wxr
2021-02-26 981ccd4afab6271422d7f169b30a2efa55eafde1
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
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="listIdList">逻辑ID列表</param>
        /// <returns></returns>
        public static ResponsePackNew GetLogic(List<string> listIdList)
        {
            var jArray = new JArray { };
            for (int i = 0; i < listIdList.Count; i++)
            {
                jArray.Add(listIdList[i]);
            }
            var jObject = new JObject { { "userLogicIds", jArray } };
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Info);
            //如果是token过期则刷新token
            if (responsePackNew.Code == StateCode.TOKEN_EXPIRED)
            {
                RefreshToken();
                GetLogic(listIdList);
            }
            return responsePackNew;
        }
 
       
 
        /// <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();
        }
 
    }
 
}