| | |
| | | using ZigBee.Common; |
| | | using Shared.Common; |
| | | using System.Collections.Specialized; |
| | | using System.Net; |
| | | using System.IO; |
| | | |
| | | namespace Shared.Phone.Device.Logic |
| | | { |
| | |
| | | var Logicifon = jObjectdata["Data"]; |
| | | logic.LogicId = int.Parse(Logicifon["LogicId"]?.ToString()); |
| | | logic.IsEnable = int.Parse(Logicifon["IsEnable"]?.ToString()); |
| | | logic.LogicName = Logicifon["LogicName"]?.ToString(); |
| | | |
| | | logic.LogicName = Logicifon["LogicName"]?.ToString();
|
| | | logic.LogicCustomPushText = Logicifon["LogicCustomPushText"].ToString();
|
| | | logic.Relationship = int.Parse(Logicifon["Relationship"]?.ToString()); |
| | | logic.TimeAttribute = Newtonsoft.Json.JsonConvert.DeserializeObject<TimeAttributeObj>(Logicifon["TimeAttribute"].ToString()); |
| | | logic.Conditions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(Logicifon["Conditions"].ToString()); |
| | |
| | | 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.LogicCustomPushText = Logicifon["LogicCustomPushText"].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()); |
| | |
| | | }); |
| | | } |
| | | // <summary> |
| | | /// 通过设备找到区域(房间)名称 |
| | | /// 通过设备找到区域(房间)名称 |
| | | /// </summary> |
| | | /// <param name="btnregionname">Btnregionname.</param> |
| | | /// <param name="device">Device.</param> |
| | |
| | | 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> |
| | |
| | | public static UserCenter.MemberInfoRes UserMemberInfoRes = null; |
| | | #endregion |
| | | |
| | | #region 存取本地文件的方法 ---暂时不用合并该方法--- |
| | | #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> |
| | | /// <param name="command">识别命令判断字符串</param> |
| | | /// <param name="url">请求地址</param> |
| | | /// <param name="method">请求方式为POST/GET</param> |
| | | /// <param name="obj">存储发送数据的对象</param> |
| | | /// <returns></returns> |
| | | public static string ReadLocalFile(string FileName) |
| | | public static async System.Threading.Tasks.Task<string>Data(string command, string url, string method, object obj = null) |
| | | { |
| | | if (System.IO.File.Exists(FileName) == false) |
| | | var getUrl = CommonPage.RequestHttpsHost + url;//请求地址; |
| | | var jObject = new JObject(); |
| | | if (UserCenter.UserCenterResourse.UserInfo.AuthorityNo == 1) |
| | | { |
| | | ///判断是否有文件; |
| | | return null; |
| | | jObject.Add("IsOtherAccountCtrl", false); |
| | | } |
| | | //读出保存该路径的文件; |
| | | var varByte = Shared.IO.FileUtils.ReadFile(FileName); |
| | | //字节流转换为字符串; |
| | | return System.Text.Encoding.UTF8.GetString(varByte); |
| | | 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 |
| | | } |