New file |
| | |
| | | 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(); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |