陈嘉乐
2021-02-24 6031a2d7faaa4f0271b0e9cecaa228e411ceca11
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
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 CodeStudy(ButtonObj buttonObj)
        {
            var jArray = new JArray { };
            var job = new JObject { };
            job.Add("key", buttonObj.Key);
            job.Add("value", buttonObj.value);
            jArray.Add(job);
            var jObject = new JObject { { "homeId", HomeId }, { "deviceId", "0" }, { "status", jArray } };
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_CodeStudy);
            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;
        }
 
 
        public static bool Error(ResponsePackNew responsePackNew)
        {
 
            if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
            {
                return true;
            }
            else if (responsePackNew != null && responsePackNew.Code == "14005")
            {
                // new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.gatewayNotOnline));
                return false;
            }
            else
            {
                // new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.saveFail));
                return false;
            }
        }
 
        /// <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();
        }
 
    }
 
}