陈嘉乐
2021-03-01 a469a96ee8c38f7d98366dcd633e3a15f92fec65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using System;
using System.IO;
using System.Net;
using HDL_ON.DAL.Server;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Shared;
 
namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
{
 
    public class PirSend
    {
        /// <summary>
        /// 住宅ID
        /// </summary>
        public static string HomeId
        {
            get
            {
                return Entity.DB_ResidenceData.Instance.CurrentRegion.RegionID;
            }
        }
        /// <summary>
        /// 是否为其他主用户分享过来的住宅
        /// </summary>
        public static bool IsOthreShare
        {
            get
            {
                return Entity.DB_ResidenceData.Instance.CurrentRegion.IsOthreShare;
            }
        }
        /// <summary>
        /// 遥控器添加
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew Add(Control control)
        {
            var jObject = new JObject { }; 
            jObject.Add("homeId", HomeId);
            jObject.Add("deviceId", control.deviceId);
            jObject.Add("name", control.name);
            jObject.Add("spk", "ir.module");
            jObject.Add("type", control.type);
            if (control.type == "library")
            {
                //jObject.Add("group_id", "123");
                var libraryjay = new JArray { };
                for (int i = 0; i < control.library.Count; i++)
                {
                    libraryjay.Add(control.library[i]);
                }
                jObject.Add("library", libraryjay);
            }
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_Add);
            return responsePackNew;
        }
        /// <summary>
        /// 红外码学习
        /// </summary>
        /// <returns></returns>
        public static void CodeStudy(ButtonObj buttonObj, Action<ResponsePackNew> action)
        {
            //var whichDayJson = jay["whichDay"].ToString();
            //var whichDayAry = Newtonsoft.Json.Linq.JArray.Parse(whichDayJson);
            //for (int b = 0; b < whichDayAry.Count; b++)
            //{
            //    var days = whichDayAry[b].ToString();
            //    timer.whichDay.Add(int.Parse(days));
            //}
            var job = new JObject { };
            job.Add("key", buttonObj.Key);
            job.Add("data_type", "string");
            var valuejArray = new JArray { };
            valuejArray.Add(buttonObj.value);
            job.Add("value", valuejArray);
            var jArray = new JArray { };
            jArray.Add(job);
            var jObject = new JObject { { "homeId", HomeId }, { "deviceId", "0" }, { "attributes", jArray } };
            ResponsePackNew responsePackNew = null;
            new System.Threading.Thread(() =>
            {
 
                try
                {
                    //发送红外码学习命令
                    responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_CodeStudy);
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        action(responsePackNew);
                    });
                }
 
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 自学按键删除
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew CodeRemove(ButtonObj buttonObj)
        {
            var job = new JObject { };
            job.Add("key", buttonObj.Key);
            job.Add("data_type", "string");
            var valuejArray = new JArray { };
            valuejArray.Add(buttonObj.value);
            job.Add("value", valuejArray);
            var jArray = new JArray { };
            jArray.Add(job);
            var jObject = new JObject { { "homeId", HomeId }, { "deviceId", "0" }, { "attributes", jArray } };
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_CodeRemove);
            return responsePackNew;
        }
 
        /// <summary>
        /// 查询红外设备类型列表/品牌列表/品牌红外码库列表
        /// </summary>
        /// <param name="frameLayout">加载log的父控件</param>
        /// <param name="action">回调函数</param>
        public static void GetDeviceTypesList(FrameLayout frameLayout, Action<ResponsePackNew> action, string id, string if_str)
        {
 
            DAL.Server.ResponsePackNew responsePackNew = null;
            Loading loading = new Loading();
            frameLayout.AddChidren(loading);
            loading.Start();
            new System.Threading.Thread(() =>
            {
                try
                {
                    string url = "";
                    var jObject = new JObject { };
                    if (if_str == "设备类型列表")
                    {
                        url = "/smart-footstone/app/ir/device-type/list";
                    }
                    else if (if_str == "品牌列表")
                    {
                        url = "/smart-footstone/app/ir/brand/list";
                        jObject.Add("deviceTypeId", id);
                    }
                    else if (if_str == "品牌红外码库列表")
                    {
                        url = "/smart-footstone/app/ir/code/list";
                        jObject.Add("brandId", id);
                    }
                    responsePackNew = RequestServerhomeId(jObject, url);
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                        action(responsePackNew);
                    });
                }
            })
            { IsBackground = true }.Start();
 
        }
 
 
 
        /// <summary>
        ///请求服务器(与住宅有关:例如;homeId) 
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew RequestServerhomeId(object o, string api_Url, int mTimeout = 20)
        {
            var requestJson = HttpUtil.GetSignRequestJson(o);
            return HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout);
 
        }
        /// <summary>
        /// 请求服务器
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew RequestServer(object o, string api_Url)
        {
            var requestJson = HttpUtil.GetSignRequestJson(o);
            return HttpUtil.RequestHttpsPost(api_Url, requestJson);
 
        }
        /// <summary>
        /// 刷新Token
        /// </summary>
        public static void RefreshToken()
        {
            IMessageCommon.Current.StartRefreshToken();
        }
 
    }
 
}