| | |
| | | using ZigBee.Device; |
| | | using ZigBee.Common; |
| | | using Shared.Common; |
| | | using System.Collections.Specialized; |
| | | |
| | | namespace Shared.Phone.Device.Logic |
| | | { |
| | | public class Send |
| | | { |
| | | |
| | | #region ----获取Logic |
| | | /// <summary> |
| | | /// 获取LogicId的方法 |
| | | /// </summary> |
| | |
| | | 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()); |
| | | List<Dictionary<string, object>> listactions = new List<Dictionary<string, object>>(); |
| | | listactions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(Logicifon["Actions"].ToString()); |
| | | |
| | |
| | | return Common.Room.Lists.FindAll((obj) => obj.FloorId == floorId); |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | #region ----获取门锁 |
| | | public static List<DoorLock> ReadDoorLockIfon(string doorlockMac) |
| | | #region ---第1种 |
| | | 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(); |
| | | postValues.Add("RequestVersion", CommonPage.RequestVersion); |
| | | postValues.Add("ReqDto.LoginAccessToken", Config.Instance.Token); |
| | | System.Threading.Tasks.Task.Run(() =>
|
| | | {
|
| | | { |
| | | try
|
| | | {
|
| | |
|
| | |
| | | |
| | | } |
| | | |
| | | 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(); |
| | |
| | | var RequestBaseUrl = jObject["ResponseData"]["RequestBaseUrl"].ToString(); |
| | | var RequestToken = jObject["ResponseData"]["RequestToken"].ToString(); |
| | | Residential lockifon = new Residential(); |
| | | lockifon.Url = RequestBaseUrl + "/App/GetDoorLockPager"; |
| | | lockifon.Url = RequestBaseUrl + "/DoorLock/GetDoorLockPager"; |
| | | lockifon.Token = RequestToken; |
| | | lockifon.Id = Config.Instance.HomeId; |
| | | lockifon.IsOtherAccountCtrl = true; |
| | |
| | | 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 |
| | | catch (Exception e) |
| | | { |
| | | |
| | | var s = e.Message; |
| | | } |
| | | |
| | | }); |
| | |
| | | return list; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ---第2种 |
| | | /// <summary> |
| | | /// 获取自己+其他成员信息 |
| | | /// </summary> |
| | | /// <param name="doorlockMac">门锁Mac</param> |
| | | /// <returns></returns> |
| | | public static async System.Threading.Tasks.Task<List<MembershipIfon>> AllMembers(string doorlockMac) |
| | | { |
| | | var userlist = new List<MembershipIfon>(); |
| | | ///判断APP登录进来用户身份(主人,管理员,成员) |
| | | var doorlockifonlist = await ReadUserListIfon(doorlockMac); |
| | | var membershipIfon = new MembershipIfon(); |
| | | membershipIfon.MembershipId = Config.Instance.Guid; |
| | | if (string.IsNullOrEmpty(Config.Instance.Name)) |
| | | { |
| | | membershipIfon.MembershipName = Config.Instance.Account; |
| | | } |
| | | else |
| | | { |
| | | membershipIfon.MembershipName = Config.Instance.Name; |
| | | } |
| | | foreach (var o in doorlockifonlist) |
| | | { |
| | | if (o.CloudAccountId == Config.Instance.Guid) |
| | | { |
| | | LockMode lockMode = new LockMode(); |
| | | lockMode.OpenMode = o.OpenLockMode; |
| | | lockMode.UserId = o.DoorLockLocalUserId; |
| | | membershipIfon.UserIdMode.Add(lockMode); |
| | | } |
| | | } |
| | | if (membershipIfon.UserIdMode.Count != 0) |
| | | { |
| | | userlist.Add(membershipIfon); |
| | | } |
| | | |
| | | if (UserCenter.UserCenterResourse.UserInfo.AuthorityNo != 3) |
| | | { |
| | | var pra = new UserCenter.MemberListInfoPra(); |
| | | string result = await UserCenter.UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountByDistributedMark", false, pra); |
| | | var listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UserCenter.MemberInfoRes>>(result); |
| | | for (int i = 0; i < listInfo.Count; i++) |
| | | { |
| | | |
| | | var membership = new MembershipIfon(); |
| | | var membershipifon = listInfo[i]; |
| | | membership.MembershipId = membershipifon.SubAccountDistributedMark; |
| | | if (string.IsNullOrEmpty(membershipifon.UserName)) |
| | | { |
| | | membership.MembershipName = membershipifon.Account; |
| | | } |
| | | else |
| | | { |
| | | membership.MembershipName = membershipifon.UserName; |
| | | |
| | | } |
| | | for (int j = 0; j < doorlockifonlist.Count; j++) |
| | | { |
| | | ///查找成员以及成员门锁触发源(1按键/3卡/15指纹) |
| | | if (doorlockifonlist[j].CloudAccountId == membershipifon.SubAccountDistributedMark) |
| | | { |
| | | LockMode lockMode = new LockMode(); |
| | | lockMode.OpenMode = doorlockifonlist[j].OpenLockMode; |
| | | lockMode.UserId = doorlockifonlist[j].DoorLockLocalUserId; |
| | | membership.UserIdMode.Add(lockMode); |
| | | } |
| | | |
| | | } |
| | | if (membership.UserIdMode.Count != 0) |
| | | { |
| | | ///过滤掉重复数据; |
| | | var str = userlist.Find((c) => { return c.MembershipId == membershipifon.SubAccountDistributedMark; }); |
| | | if (str == null) |
| | | { |
| | | userlist.Add(membership); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | return userlist; |
| | | } |
| | | /// <summary> |
| | | /// 读取门锁所有成员信息 |
| | | /// </summary> |
| | | /// <param name="doorlockMac">门锁Mac</param> |
| | | /// <returns></returns> |
| | | public static async System.Threading.Tasks.Task<List<LogicLock>> ReadUserListIfon(string doorlockMac) |
| | | { |
| | | 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; |
| | | } |
| | | var pageData = jObject["ResponseData"]["PageData"].ToString(); |
| | | var datalist = JArray.Parse(pageData); |
| | | for (int i = 0; i < datalist.Count; i++) |
| | | { |
| | | var data = JObject.Parse(datalist[i].ToString()); |
| | | 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 static async System.Threading.Tasks.Task<string> ReadUserList(string doorlockMac) |
| | | { |
| | | 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") |
| | | { |
| | | return null; |
| | | } |
| | | var pageData = jObject["ResponseData"]["PageData"].ToString(); |
| | | var datalist = JArray.Parse(pageData); |
| | | 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; |
| | | residential.Url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetSharedHomeApiControl"; |
| | | s = await ReadUserDoorLock(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; |
| | | 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> |
| | | /// 请求服务器的方法 |
| | | /// </summary> |
| | | /// <param name="postValues">post参数</param> |
| | | /// <param name="url"></param> |
| | | /// <returns></returns> |
| | | 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 DoorLock |
| | | public class LogicLock |
| | | { |
| | | public string DoorLockLocalUserId = string.Empty; |
| | | public int OpenLockMode; |
| | | public string CloudAccountId = string.Empty; |
| | | /// <summary> |
| | | /// 身份+触发源(0按键/3卡/15指纹) |
| | | /// 触发源ID |
| | | /// </summary> |
| | | public string UserIdMode |
| | | { |
| | | get |
| | | { |
| | | return DoorLockLocalUserId + "_" + OpenLockMode.ToString(); |
| | | } |
| | | } |
| | | 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; |
| | | public List<string> UserIdMode = new List<string>(); |
| | | /// <summary> |
| | | /// 触发源ID+模式(0:密码;3:卡;15:指纹;) |
| | | /// </summary> |
| | | public List<LockMode> UserIdMode = new List<LockMode>(); |
| | | /// <summary> |
| | | /// 用户昵称 |
| | | /// </summary> |
| | | public string MembershipName = string.Empty; |
| | | } |
| | | |
| | | public static List<MembershipIfon> UserList = new List<MembershipIfon>();
|
| | |
|
| | |
|
| | | public class LockMode |
| | | { |
| | | /// <summary> |
| | | /// 触发源ID |
| | | /// </summary> |
| | | public string UserId = string.Empty; |
| | | /// <summary> |
| | | /// 触发源模式(0:密码;3:卡;15:指纹;) |
| | | /// </summary> |
| | | public int OpenMode; |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 自动化门锁成员信息作为条件列表 |
| | | /// </summary> |
| | | public static List<MembershipIfon> UserList = new List<MembershipIfon>(); |
| | | /// <summary> |
| | | ///联动事件门锁成员信息作为条件的列表 |
| | | /// </summary> |
| | | public static List<MembershipIfon> LinkageventLockList = new List<MembershipIfon>(); |
| | | |
| | | /// <summary> |
| | | /// 当前门锁 |
| | | /// </summary> |
| | | public static ZigBee.Device.DoorLock CurrentDoorLock = null; |
| | | /// <summary> |
| | | /// 当前用户的信息 |
| | | /// </summary> |
| | | public static UserCenter.MemberInfoRes UserMemberInfoRes = null; |
| | | #endregion |
| | | } |
| | | } |