| | |
| | | using ZigBee.Common; |
| | | using Shared.Common; |
| | | using System.Collections.Specialized; |
| | | using System.Net; |
| | | using System.IO; |
| | | |
| | | namespace Shared.Phone.Device.Logic |
| | | { |
| | |
| | | }; |
| | | 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(); |
| | |
| | | }); |
| | | } |
| | | // <summary> |
| | | /// 通过设备找到区域(房间)名称 |
| | | /// 通过设备找到区域(房间)名称 |
| | | /// </summary> |
| | | /// <param name="btnregionname">Btnregionname.</param> |
| | | /// <param name="device">Device.</param> |
| | |
| | | public static List<Common.Room> GetRoomList(string floorId) |
| | | { |
| | | return Common.Room.Lists.FindAll((obj) => obj.FloorId == floorId); |
| | | //var list1 = new List<Common.Room>(); |
| | | /////找到某楼层房间列表; |
| | | //var list = Common.Room.Lists.FindAll((obj) => obj.FloorId == floorId); |
| | | //for (int i = 0; i < list.Count; i++) |
| | | //{ |
| | | // if (str == "device") |
| | | // { |
| | | // if (list[i].DeviceUIList.Count != 0) |
| | | // { ///过滤掉没有设备的房间 |
| | | // list1.Add(list[i]); |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // if (list[i].SceneUIList.Count != 0) |
| | | // { ///过滤掉没有场景的房间 |
| | | // list1.Add(list[i]); |
| | | // } |
| | | // } |
| | | //} |
| | | /////返回房间列表; |
| | | //return list1; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取场景信息的方法 |
| | | /// </summary> |
| | | /// <param name="SceneId"></param> |
| | | /// <returns></returns> |
| | | public static async System.Threading.Tasks.Task<SceneUI> GetScene(int SceneId) |
| | | { |
| | | 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; |
| | | } |
| | | |
| | | 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) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | ZbGateway.MainGateWay.GwResDataAction -= action; |
| | | return sceneui; |
| | | }); |
| | | } |
| | | #endregion |
| | | |
| | |
| | | /// <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) |
| | | { |
| | |
| | | currUserIfon.CloudAccountId = Config.Instance.Guid; |
| | | if (string.IsNullOrEmpty(UserCenter.UserCenterResourse.UserInfo.UserName)) |
| | | { |
| | | ///如果昵称为空,此时,登陆账号为默认昵称; |
| | | currUserIfon.UserName = UserCenter.UserCenterResourse.UserInfo.Account; |
| | | } |
| | | else |
| | |
| | | } |
| | | 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) |
| | | { |
| | | |
| | | UnlockingMode unlockingMode = new UnlockingMode(); |
| | | unlockingMode.OpenMode = o.OpenMode; |
| | | unlockingMode.UserId = o.UserId; |
| | |
| | | userIfon.CloudAccountId = user.SubAccountDistributedMark; |
| | | if (string.IsNullOrEmpty(user.UserName)) |
| | | { |
| | | ///如果昵称为空,此时,登陆账号为默认昵称; |
| | | userIfon.UserName = user.Account; |
| | | |
| | | } |
| | |
| | | } |
| | | for (int j = 0; j < AllUserIfon.Count; j++) |
| | | { |
| | | if (AllUserIfon[j].IsFreezeUser || string.IsNullOrEmpty(AllUserIfon[j].UserId)) |
| | | { |
| | | ///过滤掉冻结的成员和UserId为空的数据; |
| | | continue; |
| | | } |
| | | if (string.IsNullOrEmpty(userIfon.DoorLockMacPort)) |
| | | { |
| | | userIfon.DoorLockMacPort = AllUserIfon[j].DoorLockMacPort; |
| | |
| | | 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, CommonPage.RequestHttpsHost+"/App/GetHomePager");//不同区域域名前缀不一样 |
| | | var str = await WebClientAsync(0, CommonPage.RequestHttpsHost + "/App/GetHomePager");//不同区域域名前缀不一样 |
| | | // 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 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()显示索引, 键,值 |
| | | public static void PrintKeysAndValues2(NameValueCollection myCol) |
| | | { |
| | | |
| | | NameValueCollection postValues = new NameValueCollection(); |
| | | |
| | | if (value == 0) |
| | | for (int i = 0; i < myCol.Count; i++) |
| | | { |
| | | postValues.Add("RequestVersion", CommonPage.RequestVersion); |
| | | postValues.Add("ReqDto.LoginAccessToken", Config.Instance.Token); |
| | | postValues.Add("ReqDto.PageSetting.PageSize", Int32.MaxValue.ToString());// |
| | | |
| | | //打印显示索引, 键,值 |
| | | Console.WriteLine("[{0}]{1,-10} {2}", i, myCol.GetKey(i), myCol.Get(i)); |
| | | } |
| | | 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()); |
| | | postValues.Add("PageSetting.PageSize", Int32.MaxValue.ToString()); |
| | | } |
| | | System.Net.WebClient webClient = new System.Net.WebClient(); |
| | | byte[] responseArray = webClient.UploadValues(url, postValues); |
| | | var s = System.Text.Encoding.UTF8.GetString(responseArray); |
| | | return s; |
| | | |
| | | } |
| | | |
| | | public class Residential |
| | | { |
| | | /// <summary> |
| | |
| | | /// 用户昵称 |
| | | /// </summary> |
| | | public string UserName = string.Empty; |
| | | |
| | | /// <summary> |
| | | /// 是否冻结该成员(true已冻结) |
| | | /// </summary> |
| | | public bool IsFreezeUser; |
| | | |
| | | } |
| | | |
| | |
| | | /// 门锁Mac+Port,识别门锁; |
| | | /// </summary> |
| | | public string DoorLockMacPort = string.Empty; |
| | | /// <summary> |
| | | /// 是否冻结该成员(true已冻结) |
| | | /// </summary> |
| | | public bool IsFreezeUser; |
| | | |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | public static UserCenter.MemberInfoRes UserMemberInfoRes = null; |
| | | #endregion |
| | | |
| | | #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 = CommonPage.RequestHttpsHost + url;//请求地址; |
| | | var jObject = new JObject(); |
| | | if (UserCenter.UserCenterResourse.UserInfo.AuthorityNo == 1) |
| | | { |
| | | jObject.Add("IsOtherAccountCtrl", false); |
| | | } |
| | | else |
| | | { |
| | | jObject.Add("IsOtherAccountCtrl", true); |
| | | } |
| | | 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) |
| | | { |
| | | HttpWebRequest request = WebRequest.Create(getUrl) as HttpWebRequest; //创建请求 |
| | | request.Method = method; //请求方式为POST/GET |
| | | request.ContentType = "application/json"; |
| | | request.Timeout = second * 1000;//超时时间 |
| | | 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; |
| | | } |
| | | /// <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>
|
| | | /// 文件保存
|
| | | /// </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>
|
| | | /// <returns></returns>
|
| | | public static string ReadLocalFile(string FileName)
|
| | | {
|
| | | if (System.IO.File.Exists(FileName) == false)
|
| | | {
|
| | | ///判断是否有文件;
|
| | | return null;
|
| | | }
|
| | | //读出保存该路径的文件;
|
| | | var varByte = Shared.IO.FileUtils.ReadFile(FileName);
|
| | | //字节流转换为字符串;
|
| | | return System.Text.Encoding.UTF8.GetString(varByte);
|
| | | } |
| | | #endregion |
| | | } |
| | | } |