From 84fa7c9665d9bed9aef79237be9c5eb57c49f13d Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期五, 05 三月 2021 10:54:37 +0800 Subject: [PATCH] Merge branch 'CJL' into ez-test --- HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirSend.cs | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 175 insertions(+), 0 deletions(-) diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirSend.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirSend.cs new file mode 100644 index 0000000..abb0874 --- /dev/null +++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirSend.cs @@ -0,0 +1,175 @@ +锘縰sing 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); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + GetLogic(listIdList); + } + return responsePackNew; + } + + + + /// <summary> + ///璇锋眰鏈嶅姟鍣紙涓庝綇瀹呮湁鍏�:渚嬪锛沨omeId锛� + /// </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(); + } + + } + +} -- Gitblit v1.8.0