| | |
| | | using ZigBee.Common; |
| | | using Shared.Common; |
| | | using System.Collections.Specialized; |
| | | using System.Net; |
| | | using System.IO; |
| | | |
| | | namespace Shared.Phone.Device.Logic |
| | | { |
| | | public class Send |
| | | { |
| | | #region ----获取Logic |
| | | |
| | | #region ----Logic所有发送命令 |
| | | /// <summary> |
| | | /// 获取LogicId的方法 |
| | | /// </summary> |
| | |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | List<int> logicIdList = new List<int>(); |
| | | |
| | | bool if_theme = false; |
| | | int if_number = -1; |
| | | Action<string, string> action = (topic, data) => |
| | | { |
| | | var gatewayID = topic.Split('/')[0]; |
| | |
| | | { |
| | | return; |
| | | } |
| | | |
| | | |
| | | if (topic == $"{gatewayID}/Logic/GetLogicList_Respon") |
| | | { |
| | | |
| | | var list = jObjectdata["Data"]["LogicList"]; |
| | | if (list == null) |
| | | if_theme = true; |
| | | var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(jObjectdata["Data"]["LogicList"].ToString()); |
| | | if_number = list.Count; |
| | | if (list.Count == 0) |
| | | { |
| | | return; |
| | | } |
| | | foreach (var listIfon in list) |
| | | { |
| | | var logicId = int.Parse(listIfon["LogicId"].ToString()); |
| | | var logicId = int.Parse(listIfon["LogicId"]); |
| | | logicIdList.Add(logicId); |
| | | |
| | | } |
| | | |
| | | } |
| | | }; |
| | | var mainGateWay = ZbGateway.MainGateWay; |
| | |
| | | return logicIdList; |
| | | } |
| | | mainGateWay.GwResDataAction += action; |
| | | |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 2004 } }; |
| | | var jObjectdata1 = new JObject { { "LogicType", LogicType } }; |
| | | jObject.Add("Data", jObjectdata1); |
| | | mainGateWay?.Send("Logic/GetLogicList", jObject.ToString()); |
| | | try |
| | | { |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 2004 } }; |
| | | var jObjectdata1 = new JObject { { "LogicType", LogicType } }; |
| | | jObject.Add("Data", jObjectdata1); |
| | | mainGateWay?.Send("Logic/GetLogicList", jObject.ToString()); |
| | | } |
| | | catch(Exception e) { |
| | | var d = e.Message; |
| | | } |
| | | //await System.Threading.Tasks.Task.Run(async () => |
| | | //{ |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 3 * 1000) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(100); |
| | | if (logicIdList.Count != 0) |
| | | if (if_theme) |
| | | { |
| | | break; |
| | | if (if_number == 0 || if_number == logicIdList.Count) |
| | | { |
| | | break;//回复没有数据立刻返回 |
| | | } |
| | | |
| | | } |
| | | } |
| | | ZbGateway.MainGateWay.GwResDataAction -= action; |
| | |
| | | |
| | | if (topic == $"{gatewayID}/Logic/GetLogicInfo_Respon") |
| | | { |
| | | |
| | | logic = new Common.Logic(); |
| | | var Logicifon = jObjectdata["Data"]; |
| | | logic.LogicId = int.Parse(Logicifon["LogicId"]?.ToString()); |
| | |
| | | }); |
| | | } |
| | | ///<summary> |
| | | /// 删除逻辑 |
| | | /// 删除逻辑(0成功,其它值:失败) |
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task<int> DelLogic(int LogicId) |
| | | { |
| | |
| | | { |
| | | try |
| | | { |
| | | Logicifon = new Common.Logic(); |
| | | Logicifon = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.Logic>(jObjectdata["Data"].ToString()); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | |
| | | try |
| | | { |
| | | |
| | | |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 2000 } }; |
| | | var selectMonthList = new JArray { }; |
| | | foreach (var intvalue in logic.TimeAttribute.SelectMonDate) |
| | |
| | | ["RemindTime"] = int.Parse(dictionary["RemindTime"]), |
| | | ["EnDelay"] = int.Parse(dictionary["EnDelay"]), |
| | | ["DelayTime"] = int.Parse(dictionary["DelayTime"]), |
| | | ["DoorLockOpenDelayTime"] = int.Parse(dictionary["DoorLockOpenDelayTime"]), |
| | | }; |
| | | if (dictionary["DateType"].ToString() == "0") |
| | | { |
| | |
| | | }; |
| | | conditions.Add(sInfo); |
| | | break; |
| | | case 7: |
| | | var diliInfo = new JObject |
| | | { |
| | | ["Type"] = int.Parse(dictionary["Type"]), |
| | | ["IsValid"] = int.Parse(dictionary["IsValid"]), |
| | | ["AtHome"] = int.Parse(dictionary["AtHome"]), |
| | | ["WhoSiteUId"] = dictionary["WhoSiteUId"], |
| | | }; |
| | | conditions.Add(diliInfo); |
| | | break; |
| | | } |
| | | } |
| | | var actions = new JArray(); |
| | |
| | | }; |
| | | actions.Add(timeInfo); |
| | | break; |
| | | case 8: |
| | | var lockInfo = new JObject |
| | | { |
| | | ["LinkType"] = int.Parse(dictionary["LinkType"].ToString()), |
| | | ["DeviceAddr"] = dictionary["DeviceAddr"].ToString(), |
| | | ["Epoint"] = int.Parse(dictionary["Epoint"].ToString()), |
| | | ["PassData"] =dictionary["PassData"].ToString(), |
| | | }; |
| | | actions.Add(lockInfo); |
| | | break; |
| | | } |
| | | } |
| | | var accounts = new JArray(); |
| | |
| | | { |
| | | ["Type"] = int.Parse(dictionary["Type"]), |
| | | ["Account"] = dictionary["Account"], |
| | | ["UserId"] = dictionary["UserId"], |
| | | ["AccountName"] = dictionary["AccountName"], |
| | | |
| | | }; |
| | | |
| | | if (dictionary.ContainsKey("Option4")) |
| | | { |
| | | accounts1.Add("Option4",dictionary["Option4"]); |
| | | } |
| | | if (dictionary.ContainsKey("Option2")) |
| | | { |
| | | accounts1.Add("Option2", int.Parse(dictionary["Option2"])); |
| | | } |
| | | accounts.Add(accounts1); |
| | | } |
| | | } |
| | |
| | | accounts.Add(location); |
| | | } |
| | | break; |
| | | case 8: |
| | | { |
| | | var accounts1 = new JObject(); |
| | | if (dictionary.ContainsKey("Type")) |
| | | { |
| | | accounts1.Add("Type", int.Parse(dictionary["Type"])); |
| | | } |
| | | if (dictionary.ContainsKey("Option4")) |
| | | { |
| | | accounts1.Add("Option4", dictionary["Option4"]); |
| | | } |
| | | if (dictionary.ContainsKey("Option2")) |
| | | { |
| | | accounts1.Add("Option2", int.Parse(dictionary["Option2"])); |
| | | } |
| | | accounts.Add(accounts1); |
| | | } |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | var data = new JObject{ |
| | | { "LogicId",logic.LogicId}, |
| | | { "IsEnable", logic.IsEnable} , |
| | |
| | | { "Relationship",logic.Relationship} , |
| | | { "LogicType",logic.LogicType} , |
| | | { "LogicCustomPushText",logic.LogicCustomPushText} , |
| | | { "LogicIsCustomPushText",logic.LogicIsCustomPushText} , |
| | | { "TimeAttribute", timeAttribute} , |
| | | { "Conditions", conditions }, |
| | | { "Actions", actions }, |
| | |
| | | date.Add("LogicName", logic.LogicName); |
| | | date.Add("Relationship", logic.Relationship); |
| | | date.Add("LogicCustomPushText", logic.LogicCustomPushText); |
| | | date.Add("LogicIsCustomPushText", logic.LogicIsCustomPushText); |
| | | mainGateWay?.Send("Logic/ReviseAttribute", jObject.ToString()); |
| | | //await System.Threading.Tasks.Task.Run(async () => |
| | | //{ |
| | |
| | | { |
| | | |
| | | var listLogic = new List<Common.Logic>();
|
| | | // bool @bool = false;
|
| | | Action<string, string> action = (topic, data) => |
| | | { |
| | | var gatewayID = topic.Split('/')[0]; |
| | |
| | | |
| | | if (topic == $"{gatewayID}/Logic/GetAllLogicListInfo_Respon") |
| | | { |
| | | |
| | | var logic = new Common.Logic(); |
| | | var Logicifon = jObjectdata["Data"]; |
| | | logic.LogicId = int.Parse(Logicifon["LogicId"].ToString()); |
| | |
| | | logic.LogicName = Logicifon["LogicName"].ToString(); |
| | | logic.LogicType = int.Parse(Logicifon["LogicType"].ToString()); |
| | | logic.Relationship = int.Parse(Logicifon["Relationship"].ToString()); |
| | | logic.LogicCustomPushText = Logicifon["LogicCustomPushText"].ToString(); |
| | | logic.LogicIsCustomPushText = int.Parse(Logicifon["LogicIsCustomPushText"].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()); |
| | |
| | | } |
| | | |
| | | } |
| | | //if (topic == $"{gatewayID}/Logic/AllLogicNum_Respon") |
| | | //{ |
| | | // @bool = true; |
| | | //} |
| | | |
| | | }; |
| | | var mainGateWay = ZbGateway.MainGateWay; |
| | | if (mainGateWay == null) |
| | |
| | | } |
| | | catch { } |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 8 * 1000) |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 5* 1000) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(100); |
| | | if (sum == listLogic.Count) |
| | | { |
| | | break; |
| | | } |
| | | //if (@bool) |
| | | //{ |
| | | // break; |
| | | //} |
| | | } |
| | | ZbGateway.MainGateWay.GwResDataAction -= action; |
| | | return listLogic; |
| | | }); |
| | | } |
| | | // <summary> |
| | | /// 通过设备找到区域(房间)名称 |
| | | |
| | | /// <summary> |
| | | /// 获取场景信息的方法 |
| | | /// </summary> |
| | | /// <param name="btnregionname">Btnregionname.</param> |
| | | /// <param name="device">Device.</param> |
| | | public static void RoomNmae(Button btnregionname, CommonDevice device) |
| | | /// <param name="SceneId"></param> |
| | | /// <returns></returns> |
| | | public static async System.Threading.Tasks.Task<SceneUI> GetScene(int SceneId) |
| | | { |
| | | var room = new Common.Room(); |
| | | btnregionname.Text = room.GetRoomNameByDevice(device); |
| | | } |
| | | SceneUI sceneui = null; |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | Action<string, string> action = (topic, data) => |
| | | { |
| | | var gatewayID = topic.Split('/')[0]; |
| | | var jObjectdata = JObject.Parse(data); |
| | | if (jObjectdata == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | public static List<Common.Room> GetRoomList(string floorId) |
| | | { |
| | | return Common.Room.Lists.FindAll((obj) => obj.FloorId == floorId); |
| | | if (topic == $"{gatewayID}/Scene/GetDeviceList_Respon") |
| | | { |
| | | sceneui = new SceneUI(); |
| | | sceneui.Name = jObjectdata["Data"]["ScenesName"].ToString(); |
| | | sceneui.Id = int.Parse(jObjectdata["Data"]["ScenesId"].ToString()); |
| | | |
| | | } |
| | | }; |
| | | var mainGateWay = ZbGateway.MainGateWay; |
| | | if (mainGateWay == null) |
| | | { |
| | | Console.WriteLine("没有主网关"); |
| | | return sceneui; |
| | | } |
| | | mainGateWay.GwResDataAction += action; |
| | | |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 806 } }; |
| | | var jObjectdata1 = new JObject { { "ScenesId", SceneId } }; |
| | | jObject.Add("Data", jObjectdata1); |
| | | mainGateWay?.Send("Scene/GetDeviceList", jObject.ToString()); |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 3 * 1000) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(100); |
| | | if (sceneui != null && sceneui.Id > 0) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | ZbGateway.MainGateWay.GwResDataAction -= action; |
| | | return sceneui; |
| | | }); |
| | | } |
| | | #endregion |
| | | |
| | | #region ----获取门锁 |
| | | #region ---第1种 |
| | | public static List<LogicLock> ReadDoorLockIfon(string doorlockMac) |
| | | { |
| | | 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
|
| | | {
|
| | |
|
| | | byte[] responseArray = webClient.UploadValues(url, postValues);
|
| | | var str = System.Text.Encoding.UTF8.GetString(responseArray);
|
| | | var jObject = JObject.Parse(str);
|
| | | if (jObject == null || jObject["StateCode"].ToString() != "Success")
|
| | | {
|
| | | return;
|
| | | }
|
| | | 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;
|
| | | 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);
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | catch { }
|
| | | }); |
| | | var datetime = DateTime.Now; |
| | | while ((DateTime.Now - datetime).TotalMilliseconds < 3 * 1000) |
| | | { |
| | | if (list.Count != 0) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | return list; |
| | | |
| | | } |
| | | |
| | | public static List<LogicLock> ReadToken(Residential residential) |
| | | { |
| | | 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(); |
| | | postValues.Add("RequestVersion", CommonPage.RequestVersion); |
| | | postValues.Add("LoginAccessToken", Config.Instance.Token); |
| | | postValues.Add("MainAccountId", residential.MainUserDistributedMark); |
| | | postValues.Add("SharedHid", residential.Id); |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | | try |
| | | { |
| | | byte[] responseArray = webClient.UploadValues(url, postValues); |
| | | var str = System.Text.Encoding.UTF8.GetString(responseArray); |
| | | var jObject = JObject.Parse(str); |
| | | if (jObject == null || jObject["StateCode"].ToString() != "Success") |
| | | { |
| | | return; |
| | | } |
| | | 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; |
| | | list = ReadDoorLock(lockifon); |
| | | |
| | | } |
| | | catch { } |
| | | }); |
| | | var datetime = DateTime.Now; |
| | | while ((DateTime.Now - datetime).TotalMilliseconds < 3 * 1000) |
| | | { |
| | | if (list.Count != 0) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | public static List<LogicLock> ReadDoorLock(Residential lockifon) |
| | | { |
| | | 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); |
| | | postValues.Add("LoginAccessToken", lockifon.Token); |
| | | postValues.Add("HomeId", lockifon.Id); |
| | | postValues.Add("DoorLockId", lockifon.doorlockmac);//门锁Mac19091 |
| | | postValues.Add("IsOtherAccountCtrl", lockifon.IsOtherAccountCtrl.ToString()); |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | | try |
| | | { |
| | | |
| | | byte[] responseArray = webClient.UploadValues(lockifon.Url, postValues); |
| | | var str = System.Text.Encoding.UTF8.GetString(responseArray); |
| | | var jObject = JObject.Parse(str); |
| | | if (jObject == null || jObject["StateCode"].ToString() != "Success") |
| | | { |
| | | return; |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | var s = e.Message; |
| | | } |
| | | |
| | | }); |
| | | var datetime = DateTime.Now; |
| | | while ((DateTime.Now - datetime).TotalMilliseconds < 3 * 1000) |
| | | { |
| | | if (list.Count != 0) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ---第2种 |
| | | /// <summary> |
| | | /// 获取自己+其他成员信息 |
| | | /// </summary> |
| | | /// <param name="doorlockMac">门锁Mac</param> |
| | | /// <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)) |
| | | var AllUserIfon = await ReadUserListIfon(doorlockMac); |
| | | var currUserIfon = new MembershipIfon(); |
| | | currUserIfon.CloudAccountId = Config.Instance.Guid; |
| | | if (string.IsNullOrEmpty(UserCenter.UserCenterResourse.UserInfo.UserName)) |
| | | { |
| | | membershipIfon.MembershipName = Config.Instance.Account; |
| | | ///如果昵称为空,此时,登陆账号为默认昵称; |
| | | currUserIfon.UserName = UserCenter.UserCenterResourse.UserInfo.Account; |
| | | } |
| | | else |
| | | { |
| | | membershipIfon.MembershipName = Config.Instance.Name; |
| | | currUserIfon.UserName = UserCenter.UserCenterResourse.UserInfo.UserName; |
| | | } |
| | | foreach (var o in doorlockifonlist) |
| | | foreach (var o in AllUserIfon) |
| | | { |
| | | if (o.IsFreezeUser || string.IsNullOrEmpty(o.UserId)) |
| | | { |
| | | ///过滤掉冻结的成员和UserId为空的数据; |
| | | continue; |
| | | } |
| | | if (string.IsNullOrEmpty(currUserIfon.DoorLockMacPort)) |
| | | { |
| | | currUserIfon.DoorLockMacPort = o.DoorLockMacPort; |
| | | } |
| | | if (o.CloudAccountId == Config.Instance.Guid) |
| | | { |
| | | LockMode lockMode = new LockMode(); |
| | | lockMode.OpenMode = o.OpenLockMode; |
| | | lockMode.UserId = o.DoorLockLocalUserId; |
| | | membershipIfon.UserIdMode.Add(lockMode); |
| | | |
| | | UnlockingMode unlockingMode = new UnlockingMode(); |
| | | unlockingMode.OpenMode = o.OpenMode; |
| | | unlockingMode.UserId = o.UserId; |
| | | unlockingMode.ModeName = o.ModeName; |
| | | currUserIfon.UserIdMode.Add(unlockingMode); |
| | | } |
| | | } |
| | | if (membershipIfon.UserIdMode.Count != 0) |
| | | if (currUserIfon.UserIdMode.Count != 0) |
| | | { |
| | | userlist.Add(membershipIfon); |
| | | userlist.Add(currUserIfon); |
| | | } |
| | | |
| | | 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); |
| | | string result = ""; |
| | | if (AllUserIfon.Count != 0) |
| | | { |
| | | //服务返回来没有门锁成员信息,没有必要再去请求成员列表, |
| | | //原因:节约时间,体验效果好; |
| | | result = UserCenter.UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountByDistributedMark", false, pra); |
| | | }
|
| | | if (string.IsNullOrEmpty(result))
|
| | | {
|
| | | //防止为空抛异常;
|
| | | return userlist; |
| | | } |
| | | var listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UserCenter.MemberInfoRes>>(result);
|
| | | if (listInfo == null)
|
| | | {
|
| | | //防止为空抛异常;
|
| | | return userlist; |
| | | } |
| | | 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)) |
| | | var userIfon = new MembershipIfon(); |
| | | var user = listInfo[i]; |
| | | userIfon.CloudAccountId = user.SubAccountDistributedMark; |
| | | if (string.IsNullOrEmpty(user.UserName)) |
| | | { |
| | | membership.MembershipName = membershipifon.Account; |
| | | ///如果昵称为空,此时,登陆账号为默认昵称; |
| | | userIfon.UserName = user.Account; |
| | | |
| | | } |
| | | else |
| | | { |
| | | membership.MembershipName = membershipifon.UserName; |
| | | userIfon.UserName = user.UserName; |
| | | |
| | | } |
| | | for (int j = 0; j < doorlockifonlist.Count; j++) |
| | | for (int j = 0; j < AllUserIfon.Count; j++) |
| | | { |
| | | ///查找成员以及成员门锁触发源(1按键/3卡/15指纹) |
| | | if (membershipifon.SubAccountDistributedMark == doorlockifonlist[j].CloudAccountId) |
| | | if (AllUserIfon[j].IsFreezeUser || string.IsNullOrEmpty(AllUserIfon[j].UserId)) |
| | | { |
| | | LockMode lockMode = new LockMode(); |
| | | lockMode.OpenMode = doorlockifonlist[j].OpenLockMode; |
| | | lockMode.UserId = doorlockifonlist[j].DoorLockLocalUserId; |
| | | membership.UserIdMode.Add(lockMode); |
| | | ///过滤掉冻结的成员和UserId为空的数据; |
| | | continue; |
| | | } |
| | | if (string.IsNullOrEmpty(userIfon.DoorLockMacPort)) |
| | | { |
| | | userIfon.DoorLockMacPort = AllUserIfon[j].DoorLockMacPort; |
| | | } |
| | | ///查找成员以及成员门锁触发源(1按键/3卡/15指纹) |
| | | if (user.SubAccountDistributedMark == AllUserIfon[j].CloudAccountId) |
| | | { |
| | | UnlockingMode unlockingMode = new UnlockingMode(); |
| | | unlockingMode.OpenMode = AllUserIfon[j].OpenMode; |
| | | unlockingMode.UserId = AllUserIfon[j].UserId; |
| | | unlockingMode.ModeName = AllUserIfon[j].ModeName; |
| | | userIfon.UserIdMode.Add(unlockingMode); |
| | | } |
| | | |
| | | } |
| | | if (membership.UserIdMode.Count != 0) |
| | | if (userIfon.UserIdMode.Count != 0) |
| | | { |
| | | ///过滤掉重复数据; |
| | | var str = userlist.Find((c) => { return c.MembershipId == membershipifon.SubAccountDistributedMark; }); |
| | | var str = userlist.Find((c) => { return c.CloudAccountId == user.SubAccountDistributedMark; }); |
| | | if (str == null) |
| | | { |
| | | userlist.Add(membership); |
| | | userlist.Add(userIfon); |
| | | } |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | /// <param name="doorlockMac">门锁Mac</param> |
| | | /// <returns></returns> |
| | | public static async System.Threading.Tasks.Task<List<LogicLock>> ReadUserListIfon(string doorlockMac) |
| | | public static async System.Threading.Tasks.Task<List<User>> ReadUserListIfon(string doorlockMac) |
| | | { |
| | | List<LogicLock> list = new List<LogicLock>(); |
| | | var list = new List<User>(); |
| | | var s = await ReadUserList(doorlockMac); |
| | | var jObject = JObject.Parse(s); |
| | | if (jObject == null || jObject["StateCode"].ToString() != "Success") |
| | |
| | | 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); |
| | | var user = new User(); |
| | | user.UserId = data["DoorLockLocalUserId"].ToString(); |
| | | user.OpenMode = int.Parse(data["OpenLockMode"].ToString()); |
| | | user.CloudAccountId = data["CloudAccountId"].ToString(); |
| | | user.DoorLockMacPort = data["DoorLockId"].ToString(); |
| | | user.ModeName = data["UserIdRemarks"].ToString(); |
| | | user.IsFreezeUser = Convert.ToBoolean(data["IsFreezeUser"].ToString()); |
| | | list.Add(user); |
| | | } |
| | | 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 str = await WebClientAsync(0, CommonPage.RequestHttpsHost + "/App/GetHomePager");//不同区域域名前缀不一样 |
| | | |
| | | var jObject = JObject.Parse(str); |
| | | if (jObject == null || jObject["StateCode"].ToString() != "Success") |
| | | { |
| | |
| | | residential.MainUserDistributedMark = data["MainUserDistributedMark"].ToString(); |
| | | residential.IsOtherAccountCtrl = true; |
| | | residential.doorlockmac = doorlockMac; |
| | | residential.Url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetSharedHomeApiControl"; |
| | | residential.Url = CommonPage.RequestHttpsHost + "/App/GetSharedHomeApiControl"; |
| | | s = await ReadUserDoorLock(residential); |
| | | } |
| | | else |
| | | { |
| | | residential.Url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/DoorLock/GetDoorLockPager"; |
| | | residential.Url = CommonPage.RequestHttpsHost + "/DoorLock/GetDoorLockPager"; |
| | | residential.Token = Config.Instance.Token; |
| | | residential.Id = Config.Instance.HomeId; |
| | | residential.IsOtherAccountCtrl = false; |
| | |
| | | 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> |
| | |
| | | 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; |
| | | public string CloudAccountId = string.Empty; |
| | | /// <summary> |
| | | /// 触发源ID+模式(0:密码;3:卡;15:指纹;) |
| | | /// 门锁Mac+Port,识别门锁; |
| | | /// </summary> |
| | | public List<LockMode> UserIdMode = new List<LockMode>(); |
| | | public string DoorLockMacPort = string.Empty; |
| | | /// <summary> |
| | | /// 触发源列表 |
| | | /// </summary> |
| | | public List<UnlockingMode> UserIdMode = new List<UnlockingMode>(); |
| | | /// <summary> |
| | | /// 用户昵称 |
| | | /// </summary> |
| | | public string MembershipName = string.Empty; |
| | | public string UserName = string.Empty; |
| | | /// <summary> |
| | | /// 是否冻结该成员(true已冻结) |
| | | /// </summary> |
| | | public bool IsFreezeUser; |
| | | |
| | | } |
| | | |
| | | public class LockMode |
| | | public class UnlockingMode |
| | | { |
| | | /// <summary> |
| | | /// 触发源ID |
| | |
| | | /// 触发源模式(0:密码;3:卡;15:指纹;) |
| | | /// </summary> |
| | | public int OpenMode; |
| | | /// <summary> |
| | | /// 自定义触发源名称 |
| | | /// </summary> |
| | | public string ModeName = string.Empty; |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 自动化门锁成员信息作为条件列表 |
| | | /// </summary> |
| | | public static List<MembershipIfon> UserList = new List<MembershipIfon>(); |
| | | /// <summary> |
| | | ///联动事件门锁成员信息作为条件的列表 |
| | | /// </summary> |
| | | public static List<MembershipIfon> LinkageventLockList = new List<MembershipIfon>(); |
| | | |
| | | public class User |
| | | { |
| | | /// <summary> |
| | | /// 识别用户身份 |
| | | /// </summary> |
| | | public string CloudAccountId = string.Empty; |
| | | /// <summary> |
| | | /// 触发源ID |
| | | /// </summary> |
| | | public string UserId = string.Empty; |
| | | /// <summary> |
| | | /// 触发源模式(0:密码;3:卡;15:指纹;) |
| | | /// </summary> |
| | | public int OpenMode; |
| | | /// <summary> |
| | | /// 自定义触发源名称 |
| | | /// </summary> |
| | | public string ModeName = string.Empty; |
| | | /// <summary> |
| | | /// 门锁Mac+Port,识别门锁; |
| | | /// </summary> |
| | | public string DoorLockMacPort = string.Empty; |
| | | /// <summary> |
| | | /// 是否冻结该成员(true已冻结) |
| | | /// </summary> |
| | | public bool IsFreezeUser; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 门锁列表 |
| | | /// </summary> |
| | | public static List<MembershipIfon> LockList = new List<MembershipIfon>(); |
| | | /// <summary> |
| | | /// 当前门锁 |
| | | /// </summary> |
| | |
| | | /// </summary> |
| | | public static UserCenter.MemberInfoRes UserMemberInfoRes = null; |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 自己用的发送的方法 |
| | | /// </summary> |
| | | /// <param name="tag">标记是那条命令</param> |
| | | /// <param name="logic">逻辑对象</param> |
| | | public static void Zj(bool tag, Common.Logic logic) |
| | | { |
| | | |
| | | if (string.IsNullOrEmpty(logic.LogicCustomPushText)) |
| | | { |
| | | ///默认推送自定义内容 |
| | | string str = logic.LogicName + Language.StringByID(R.MyInternationalizationString.defaulttext); |
| | | logic.LogicCustomPushText = str; |
| | | } |
| | | |
| | | new System.Threading.Thread(() => |
| | | { |
| | | if (logic.LogicId != 0) |
| | | { |
| | | if (tag) |
| | | { |
| | | Data("添加/更新", "/App/HomeLogicConfig", "POST"); |
| | | } |
| | | else |
| | | { |
| | | Data("删除", "/App/DelHomeLogicConfig", "POST"); |
| | | } |
| | | ///只改推送内容; |
| | | LogicControlSwitch(logic); |
| | | } |
| | | |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | #region 请求服务器方法--- |
| | | /// <summary> |
| | | /// 请求数据的封装方法 |
| | | /// </summary> |
| | | /// <param name="command">识别命令判断字符串</param> |
| | | /// <param name="url">请求地址</param> |
| | | /// <param name="method">请求方式为POST/GET</param> |
| | | /// <param name="obj">存储发送数据的对象</param> |
| | | /// <returns></returns> |
| | | public static async System.Threading.Tasks.Task<string> Data(string command, string url, string method, object obj = null) |
| | | { |
| | | var getUrl = ""; |
| | | var jObject = new JObject(); |
| | | if (UserCenter.UserCenterResourse.UserInfo.AuthorityNo == 1) |
| | | { |
| | | getUrl = CommonPage.RequestHttpsHost + url;//请求地址; |
| | | jObject.Add("IsOtherAccountCtrl", false); |
| | | jObject.Add("LoginAccessToken", Config.Instance.Token); |
| | | } |
| | | else |
| | | { |
| | | getUrl = Config.Instance.AdminRequestBaseUrl + url;//请求地址; |
| | | jObject.Add("IsOtherAccountCtrl", true); |
| | | jObject.Add("LoginAccessToken", Config.Instance.AdminRequestToken); |
| | | } |
| | | switch (command) |
| | | { |
| | | case "添加/更新": |
| | | { |
| | | jObject.Add("RequestVersion", CommonPage.RequestVersion); |
| | | //jObject.Add("LoginAccessToken", Config.Instance.Token); |
| | | jObject.Add("HomeId", Config.Instance.HomeId); |
| | | jObject.Add("LogicID", Common.Logic.CurrentLogic.LogicId); |
| | | jObject.Add("PushUserIds", new JArray { Config.Instance.Guid }); |
| | | jObject.Add("PushContent", Common.Logic.CurrentLogic.LogicCustomPushText); |
| | | } |
| | | break; |
| | | case "删除": |
| | | { |
| | | jObject.Add("RequestVersion", CommonPage.RequestVersion); |
| | | //jObject.Add("LoginAccessToken", Config.Instance.Token); |
| | | jObject.Add("HomeId", Config.Instance.HomeId); |
| | | jObject.Add("LogicID", Common.Logic.CurrentLogic.LogicId); |
| | | } |
| | | break; |
| | | } |
| | | return await HttpWebRequest(getUrl, jObject.ToString(), method); |
| | | } |
| | | /// <summary> |
| | | /// 请求服务器的方法(支持请求方式为POST/GET) |
| | | /// </summary> |
| | | /// <param name="getUrl">请求的地址</param> |
| | | /// <param name="str">请求数据</param> |
| | | /// <param name="method">请求方式为POST/GET</param> |
| | | /// <param name="second">超时时间</param> |
| | | /// <returns></returns> |
| | | public static async System.Threading.Tasks.Task<string> HttpWebRequest(string getUrl, string str, string method, int second = 3, bool _bool = false) |
| | | { |
| | | try
|
| | | {
|
| | | HttpWebRequest request = WebRequest.Create(getUrl) as HttpWebRequest; //创建请求
|
| | | request.Method = method; //请求方式为POST/GET
|
| | | request.ContentType = "application/json";
|
| | | request.Timeout = second * 1000;//超时时间
|
| | | if (_bool)
|
| | | {
|
| | | //用于高胜可视对讲接口
|
| | | request.Headers.Add("Authorization", Config.Instance.Token);
|
| | | }
|
| | | if (method == "POST")
|
| | | {
|
| | | byte[] jsonbyte = System.Text.Encoding.UTF8.GetBytes(str);
|
| | | request.ContentLength = jsonbyte.Length;
|
| | | Stream postStream = request.GetRequestStream();
|
| | | postStream.Write(jsonbyte, 0, jsonbyte.Length);
|
| | | postStream.Close();
|
| | | }
|
| | | //发送请求并获取相应回应数据 |
| | | HttpWebResponse res;
|
| | | try
|
| | | {
|
| | | res = (HttpWebResponse)request.GetResponse();
|
| | | }
|
| | | catch (WebException ex)
|
| | | {
|
| | | res = (HttpWebResponse)ex.Response;
|
| | | }
|
| | | StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8);
|
| | | string content = sr.ReadToEnd(); //获得响应字符串
|
| | | return content;
|
| | | } |
| | | catch |
| | | {
|
| | | return null;
|
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 请求服务器的方法 |
| | | /// </summary> |
| | | /// <param name="value">区分发送命令的数据判断值</param> |
| | | /// <param name="url">请求的地址</param> |
| | | /// <param name="residential">装数据的对象</param> |
| | | /// <returns></returns> |
| | | public static async System.Threading.Tasks.Task<string> WebClientAsync(int value, string url, Residential residential = null) |
| | | { |
| | | NameValueCollection postValues = new NameValueCollection(); |
| | | switch (value) |
| | | { |
| | | case 0: |
| | | { |
| | | postValues.Add("RequestVersion", CommonPage.RequestVersion); |
| | | postValues.Add("ReqDto.LoginAccessToken", Config.Instance.Token); |
| | | postValues.Add("ReqDto.PageSetting.PageSize", Int32.MaxValue.ToString());// |
| | | } |
| | | break; |
| | | case 1: |
| | | { |
| | | postValues.Add("RequestVersion", CommonPage.RequestVersion); |
| | | postValues.Add("LoginAccessToken", Config.Instance.Token); |
| | | postValues.Add("MainAccountId", residential.MainUserDistributedMark); |
| | | postValues.Add("SharedHid", residential.Id); |
| | | } |
| | | break; |
| | | case 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()); |
| | | postValues.Add("PageSetting.PageSize", Int32.MaxValue.ToString()); |
| | | } |
| | | break; |
| | | } |
| | | //PrintKeysAndValues2(postValues); |
| | | System.Net.WebClient webClient = new System.Net.WebClient(); |
| | | byte[] responseArray = webClient.UploadValues(url, postValues); |
| | | var s = System.Text.Encoding.UTF8.GetString(responseArray); |
| | | return s; |
| | | } |
| | | #endregion |
| | | |
| | | #region 存取本地文件的方法 ---暂时不用合并该方法--- |
| | | /// <summary>
|
| | | /// 判断是否开启GPS服务 |
| | | /// </summary> |
| | | public static string If_Exist |
| | | { |
| | | get |
| | | { |
| | | string value = ReadLocalFile(Config.Instance.HomeId+"_GPS_File"); |
| | | //读取本地GPS服务状态 |
| | | if (value == "0"||string.IsNullOrEmpty(value)) |
| | | { |
| | | return "0"; |
| | | } |
| | | return "1"; |
| | | } |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 文件保存
|
| | | /// </summary>
|
| | | /// <param name="FileName">文件路径</param>
|
| | | /// <param name="obj">需要序列化数据</param>
|
| | | public static void SaveLocalFile(string FileName, object obj)
|
| | | {
|
| | | //先序列化数据;
|
| | | var data = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
|
| | | //数据转换为字节流;
|
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(data);
|
| | | //写入数据;
|
| | | Shared.IO.FileUtils.WriteFileByBytes(FileName, byteData);
|
| | | }
|
| | | /// <summary> |
| | | /// 文件保存 |
| | | /// </summary> |
| | | /// <param name="FileName">文件路径</param> |
| | | /// <param name="data">字符串</param> |
| | | public static void SaveLocalFile(string FileName, string data) |
| | | {
|
| | | //先序列化数据; |
| | | //数据转换为字节流; |
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(data); |
| | | //写入数据; |
| | | Shared.IO.FileUtils.WriteFileByBytes(FileName, byteData); |
| | | } |
| | | /// <summary>
|
| | | /// 文件读取
|
| | | /// </summary>
|
| | | /// <param name="FileName">文件路径</param>
|
| | | /// <returns></returns>
|
| | | public static string ReadLocalFile(string FileName)
|
| | | {
|
| | | //读出保存该路径的文件;
|
| | | var varByte = Shared.IO.FileUtils.ReadFile(FileName);
|
| | | //字节流转换为字符串;
|
| | | return System.Text.Encoding.UTF8.GetString(varByte);
|
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 判断字典是否存在的方法 |
| | | /// </summary> |
| | | /// <param name="deviceConditionsInfo"></param> |
| | | /// <param name="Key">键</param> |
| | | /// <param name="Value">键值</param> |
| | | public static void dictionary(Dictionary<string, string> deviceConditionsInfo, string Key, string Value) |
| | | { |
| | | if (deviceConditionsInfo.ContainsKey(Key)) |
| | | { |
| | | deviceConditionsInfo.Remove(Key); |
| | | } |
| | | deviceConditionsInfo.Add(Key, Value); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |