From d7ad5a3953a8cd001659092ebde204b881f94b9d Mon Sep 17 00:00:00 2001 From: WJC <wjc@hdlchina.com.cn> Date: 星期四, 31 十月 2019 10:47:13 +0800 Subject: [PATCH] 2019-10-31-1 --- ZigbeeApp/Shared/Phone/Device/Logic/Send.cs | 275 ++++++++++++++++++++++++++++++------------------------ 1 files changed, 154 insertions(+), 121 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs b/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs index 061d345..54081cb 100644 --- a/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs +++ b/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs @@ -609,7 +609,7 @@ logic.IsEnable = int.Parse(Logicifon["IsEnable"].ToString()); logic.LogicName = Logicifon["LogicName"].ToString(); logic.LogicType = int.Parse(Logicifon["LogicType"].ToString()); - logic.Relationship = int.Parse(Logicifon["Relationship"].ToString()); + logic.Relationship = int.Parse(Logicifon["Relationship"].ToString()); logic.TimeAttribute = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.TimeAttributeObj>(Logicifon["TimeAttribute"].ToString()); logic.Conditions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(Logicifon["Conditions"].ToString()); logic.Accounts = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(Logicifon["Accounts"].ToString()); @@ -712,12 +712,12 @@ return Common.Room.Lists.FindAll((obj) => obj.FloorId == floorId); } -# endregion + #endregion #region ----鑾峰彇闂ㄩ攣 - public static List<DoorLock> ReadDoorLockIfon(string doorlockMac) + public static List<LogicLock> ReadDoorLockIfon(string doorlockMac) { - List<DoorLock> list = new List<DoorLock>(); + List<LogicLock> list = new List<LogicLock>(); string url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetHomePager";//瀛愯处鍙峰拰涓昏处鍙峰彲鑳介摼鎺ヤ笉鍚� System.Net.WebClient webClient = new System.Net.WebClient(); System.Collections.Specialized.NameValueCollection postValues = new System.Collections.Specialized.NameValueCollection(); @@ -784,9 +784,9 @@ } - public static List<DoorLock> ReadToken(Residential residential) + public static List<LogicLock> ReadToken(Residential residential) { - List<DoorLock> list = new List<DoorLock>(); + List<LogicLock> list = new List<LogicLock>(); string url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetSharedHomeApiControl"; System.Net.WebClient webClient = new System.Net.WebClient(); System.Collections.Specialized.NameValueCollection postValues = new System.Collections.Specialized.NameValueCollection(); @@ -829,9 +829,9 @@ return list; } - public static List<DoorLock> ReadDoorLock(Residential lockifon) + public static List<LogicLock> ReadDoorLock(Residential lockifon) { - List<DoorLock> list = new List<DoorLock>(); + List<LogicLock> list = new List<LogicLock>(); System.Net.WebClient webClient = new System.Net.WebClient(); System.Collections.Specialized.NameValueCollection postValues = new System.Collections.Specialized.NameValueCollection(); postValues.Add("RequestVersion", CommonPage.RequestVersion); @@ -856,7 +856,7 @@ for (int i = 0; i < datalist.Count; i++) { var data = JObject.Parse(datalist[i].ToString()); - DoorLock doorLock = new DoorLock(); + LogicLock doorLock = new LogicLock(); doorLock.DoorLockLocalUserId = data["DoorLockLocalUserId"].ToString(); doorLock.OpenLockMode = int.Parse(data["OpenLockMode"].ToString()); doorLock.CloudAccountId = data["CloudAccountId"].ToString(); @@ -864,13 +864,13 @@ } } - catch(Exception e) + catch (Exception e) { var s = e.Message; } }); - var datetime = DateTime.Now; + var datetime = DateTime.Now; while ((DateTime.Now - datetime).TotalMilliseconds < 3 * 1000) { if (list.Count != 0) @@ -881,54 +881,17 @@ return list; } - public class Residential + + + + + #region ---绗�2绉� + + public static async System.Threading.Tasks.Task<List<LogicLock>> UserListIfon(string doorlockMac) { - public string Id = string.Empty; - public bool IsOthreShare; - public string MainUserDistributedMark = string.Empty; - public string Url = string.Empty; - public string Token = string.Empty; - public bool IsOtherAccountCtrl; - public string doorlockmac; - } - - public class DoorLock - { - public string DoorLockLocalUserId = string.Empty; - public int OpenLockMode; - public string CloudAccountId = string.Empty; - /// <summary> - /// 韬唤+瑙﹀彂婧�(0鎸夐敭/3鍗�/15鎸囩汗) - /// </summary> - public string UserIdMode - { - get - { - return DoorLockLocalUserId + "_" + OpenLockMode.ToString(); - } - } - } - - public class MembershipIfon - { - public string MembershipId = string.Empty; - public List<string> UserIdMode = new List<string>(); - public string MembershipName = string.Empty; - } - - public static List<MembershipIfon> UserList = new List<MembershipIfon>(); - - - #endregion - /* - public async System.Threading.Tasks.Task<List<>> a() - { - string url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetHomePager"; - System.Collections.Specialized.NameValueCollection postValues = new System.Collections.Specialized.NameValueCollection(); - postValues.Add("RequestVersion", CommonPage.RequestVersion); - postValues.Add("ReqDto.LoginAccessToken", Config.Instance.Token); - var str = await WebClientAsync(postValues, url); - var jObject = JObject.Parse(str); + List<LogicLock> list = new List<LogicLock>(); + var s = await ReadUserList(doorlockMac); + var jObject = JObject.Parse(s); if (jObject == null || jObject["StateCode"].ToString() != "Success") { return null; @@ -938,63 +901,19 @@ for (int i = 0; i < datalist.Count; i++) { var data = JObject.Parse(datalist[i].ToString()); - if (Config.Instance.HomeId == data["Id"].ToString()) - { - Residential residential = new Residential(); - - if (Convert.ToBoolean(data["IsOthreShare"].ToString())) - { - //鍒嗕韩鑰匢D - residential.Id = data["Id"].ToString(); - //鏄惁鏄垎浜处鍙穂true(鏄垎浜�);false;(涓嶆槸鍒嗕韩)]; - residential.IsOthreShare = Convert.ToBoolean(data["IsOthreShare"].ToString()); - //鍒嗕韩鑰呬綇瀹匢D - residential.MainUserDistributedMark = data["MainUserDistributedMark"].ToString(); - residential.IsOtherAccountCtrl = true; - //residential.doorlockmac = doorlockMac; - //list = ReadToken(residential); - } - else - { - residential.Url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/DoorLock/GetDoorLockPager"; - residential.Token = Config.Instance.Token; - residential.Id = Config.Instance.HomeId; - residential.IsOtherAccountCtrl = false; - //residential.doorlockmac = doorlockMac; - //list = ReadDoorLock(residential); - - } - } - + LogicLock doorLock = new LogicLock(); + doorLock.DoorLockLocalUserId = data["DoorLockLocalUserId"].ToString(); + doorLock.OpenLockMode = int.Parse(data["OpenLockMode"].ToString()); + doorLock.CloudAccountId = data["CloudAccountId"].ToString(); + list.Add(doorLock); } + return list; } - public async System.Threading.Tasks.Task<string> aa(int value, string url, Residential residential = null) + public static async System.Threading.Tasks.Task<string> ReadUserList(string doorlockMac) { - NameValueCollection postValues = new NameValueCollection(); - if (value == 1) - { - - } - else if (value == 2) - { - postValues.Add("RequestVersion", CommonPage.RequestVersion); - postValues.Add("LoginAccessToken", Config.Instance.Token); - postValues.Add("MainAccountId", residential.MainUserDistributedMark); - postValues.Add("SharedHid", residential.Id); - } - else - { - postValues.Add("RequestVersion", CommonPage.RequestVersion); - postValues.Add("ReqDto.LoginAccessToken", Config.Instance.Token); - - } - return await WebClientAsync(postValues, url); - } - - public async System.Threading.Tasks.Task<string> aaa(NameValueCollection postValues, string url) - { - var str = await aa(0, "https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetHomePager"); + string s = null; + var str = await WebClientAsync(0, "https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetHomePager"); var jObject = JObject.Parse(str); if (jObject == null || jObject["StateCode"].ToString() != "Success") { @@ -1017,10 +936,9 @@ //鍒嗕韩鑰呬綇瀹匢D residential.MainUserDistributedMark = data["MainUserDistributedMark"].ToString(); residential.IsOtherAccountCtrl = true; - //residential.doorlockmac = doorlockMac; - //list = ReadToken(residential); - - var str = await WebClientAsync(residential, postValues, url); + residential.doorlockmac = doorlockMac; + residential.Url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetSharedHomeApiControl"; + s = await ReadUserDoorLock(residential); } else { @@ -1028,13 +946,34 @@ residential.Token = Config.Instance.Token; residential.Id = Config.Instance.HomeId; residential.IsOtherAccountCtrl = false; - //residential.doorlockmac = doorlockMac; - var str = await WebClientAsync(postValues, url); - + residential.doorlockmac = doorlockMac; + s = await WebClientAsync(2, residential.Url, residential); } - } + } } + return s; + } + + public static async System.Threading.Tasks.Task<string> ReadUserDoorLock(Residential residential) + { + + var s = await WebClientAsync(1, residential.Url, residential); + + var jObject = JObject.Parse(s); + if (jObject == null || jObject["StateCode"].ToString() != "Success") + { + return null; + } + var RequestBaseUrl = jObject["ResponseData"]["RequestBaseUrl"].ToString(); + var RequestToken = jObject["ResponseData"]["RequestToken"].ToString(); + Residential lockifon = new Residential(); + lockifon.Url = RequestBaseUrl + "/DoorLock/GetDoorLockPager"; + lockifon.Token = RequestToken; + lockifon.Id = Config.Instance.HomeId; + lockifon.IsOtherAccountCtrl = true; + lockifon.doorlockmac = residential.doorlockmac; + return await WebClientAsync(2, lockifon.Url, lockifon); } /// <summary> @@ -1043,13 +982,107 @@ /// <param name="postValues">post鍙傛暟</param> /// <param name="url"></param> /// <returns></returns> - public async System.Threading.Tasks.Task<string> WebClientAsync(NameValueCollection postValues, string url) + public static async System.Threading.Tasks.Task<string> WebClientAsync(int value, string url, Residential residential = null) { + + NameValueCollection postValues = new NameValueCollection(); + if (value == 0) + { + postValues.Add("RequestVersion", CommonPage.RequestVersion); + postValues.Add("ReqDto.LoginAccessToken", Config.Instance.Token); + } + else if (value == 1) + { + postValues.Add("RequestVersion", CommonPage.RequestVersion); + postValues.Add("LoginAccessToken", Config.Instance.Token); + postValues.Add("MainAccountId", residential.MainUserDistributedMark); + postValues.Add("SharedHid", residential.Id); + } + else if (value == 2) + { + postValues.Add("RequestVersion", CommonPage.RequestVersion); + postValues.Add("LoginAccessToken", residential.Token); + postValues.Add("HomeId", residential.Id); + postValues.Add("DoorLockId", residential.doorlockmac);//闂ㄩ攣Mac + postValues.Add("IsOtherAccountCtrl", residential.IsOtherAccountCtrl.ToString()); + } System.Net.WebClient webClient = new System.Net.WebClient(); byte[] responseArray = webClient.UploadValues(url, postValues); return System.Text.Encoding.UTF8.GetString(responseArray); } - */ + #endregion + + public class Residential + { + /// <summary> + /// 浣忓畢ID + /// </summary> + public string Id = string.Empty; + /// <summary> + /// 褰撳墠浣忓畢鏄笉鏄叾浠栦富甯愬彿鍒嗕韩杩囨潵鐨� + /// </summary> + public bool IsOthreShare; + /// <summary> + /// 褰撳墠浣忓畢鏄笉鏄叾浠栦富甯愬彿鍒嗕韩杩囨潵鐨勪富甯愬彿鐨勫垎甯冨紡Id + /// </summary> + public string MainUserDistributedMark = string.Empty; + public string Url = string.Empty; + public string Token = string.Empty; + public bool IsOtherAccountCtrl; + /// <summary> + /// 褰撳墠闂ㄩ攣mac + /// </summary> + public string doorlockmac; + } + + public class LogicLock + { + /// <summary> + /// 瑙﹀彂婧怚D + /// </summary> + public string DoorLockLocalUserId = string.Empty; + /// <summary> + /// 瑙﹀彂婧愭ā寮�(0:瀵嗙爜;3:鍗�;15:鎸囩汗;) + /// </summary> + public int OpenLockMode; + /// <summary> + /// 璇嗗埆鐢ㄦ埛韬唤 + /// </summary> + public string CloudAccountId = string.Empty; + } + + public class MembershipIfon + { + /// <summary> + /// 璇嗗埆鐢ㄦ埛韬唤 + /// </summary> + public string MembershipId = string.Empty; + /// <summary> + /// 瑙﹀彂婧怚D+妯″紡(0:瀵嗙爜;3:鍗�;15:鎸囩汗;) + /// </summary> + public List<LockMode> UserIdMode = new List<LockMode>(); + /// <summary> + /// 鐢ㄦ埛鏄电О + /// </summary> + public string MembershipName = string.Empty; + } + + public class LockMode + { + /// <summary> + /// 瑙﹀彂婧怚D + /// </summary> + public string UserId = string.Empty; + /// <summary> + /// 瑙﹀彂婧愭ā寮�(0:瀵嗙爜;3:鍗�;15:鎸囩汗;) + /// </summary> + public int OpenMode; + + } + + public static List<MembershipIfon> UserList = new List<MembershipIfon>(); + + #endregion } } -- Gitblit v1.8.0