| | |
| | | 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()); |
| | |
| | | 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(); |
| | |
| | | |
| | | } |
| | | |
| | | 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(); |
| | |
| | | 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); |
| | |
| | | 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(); |
| | |
| | | } |
| | | |
| | | } |
| | | 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) |
| | |
| | | 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; |
| | |
| | | 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())) |
| | | { |
| | | //分享者ID |
| | | residential.Id = data["Id"].ToString(); |
| | | //是否是分享账号[true(是分享);false;(不是分享)]; |
| | | residential.IsOthreShare = Convert.ToBoolean(data["IsOthreShare"].ToString()); |
| | | //分享者住宅ID |
| | | 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") |
| | | { |
| | |
| | | //分享者住宅ID |
| | | 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 |
| | | { |
| | |
| | | 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> |
| | |
| | | /// <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> |
| | | /// 触发源ID |
| | | /// </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> |
| | | /// 触发源ID+模式(0:密码;3:卡;15:指纹;) |
| | | /// </summary> |
| | | public List<LockMode> UserIdMode = new List<LockMode>(); |
| | | /// <summary> |
| | | /// 用户昵称 |
| | | /// </summary> |
| | | public string MembershipName = string.Empty; |
| | | } |
| | | |
| | | public class LockMode |
| | | { |
| | | /// <summary> |
| | | /// 触发源ID |
| | | /// </summary> |
| | | public string UserId = string.Empty; |
| | | /// <summary> |
| | | /// 触发源模式(0:密码;3:卡;15:指纹;) |
| | | /// </summary> |
| | | public int OpenMode; |
| | | |
| | | } |
| | | |
| | | public static List<MembershipIfon> UserList = new List<MembershipIfon>(); |
| | | |
| | | #endregion |
| | | } |
| | | } |