From f71e74b5f0d2716fbf05da016cdaa18d64e09f80 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期四, 31 十二月 2020 17:01:18 +0800 Subject: [PATCH] 又换完成最新门锁。空气质量传感器完成数据和基本配置功能。开发图表和自动化的同事可下载此代码 --- ZigbeeApp/Shared/Phone/ZigBee/Common/Config.cs | 242 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 242 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Common/Config.cs b/ZigbeeApp/Shared/Phone/ZigBee/Common/Config.cs new file mode 100755 index 0000000..d068161 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/ZigBee/Common/Config.cs @@ -0,0 +1,242 @@ +锘縰sing System; +using System.Collections.Generic; + +namespace Shared.Common +{ + [System.Serializable] + public class Config + { + private const string fileName = "Config.json"; + + private static Config config = null; + public static Config Instance + { + get + { + if (config == null) + { + ReFresh(); + } + return config; + } + } + + /// <summary> + /// 鏈嶅姟鍣ㄦ敞鍐孖D + /// </summary> + public string RegistrationID = string.Empty; + + /// <summary> + /// 璐︽埛鐧诲綍鎴愬姛鏃剁殑鏃堕棿 + /// </summary> + public DateTime LoginDateTime = DateTime.MinValue; + /// <summary> + /// + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public bool IsLogin + { + get + { + return (DateTime.Now - LoginDateTime).Days < 7; + } + } + + public static void ReFresh() + { + var file = Shared.IO.FileUtils.ReadFile(fileName); + config = Newtonsoft.Json.JsonConvert.DeserializeObject<Config>(System.Text.Encoding.UTF8.GetString(file)); + + if (config == null) + { + config = new Config { }; + } + if (config.PasswordEncrypt != string.Empty) + { + //瑙e瘑 + config.Password = Phone.UserCenter.UserCenterLogic.DecryptPassword("hD1(La3o", config.PasswordEncrypt); + } + if (config.Md5pwdEncrypt != string.Empty) + { + //瑙e瘑 + config.MD5PWD = Phone.UserCenter.UserCenterLogic.DecryptPassword("hD1(La3o", config.Md5pwdEncrypt); + } + } + + /// <summary> + /// 璐︽埛鐧诲綍鎴愬姛鐨勮处鎴风被鍨�(姝ゅ彉閲忛粯璁や负0,骞朵笖涓嶈祴鍊�) + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public int AccountType = 0; + /// <summary> + /// 褰撳墠鐧诲綍鐨勫笎鍙� + /// </summary> + public string Account = string.Empty; + /// <summary> + /// 褰撳墠甯愬彿瀵嗙爜 + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string Password = string.Empty; + /// <summary> + /// 鍔犲瘑瀵嗙爜 + /// </summary> + public string PasswordEncrypt = string.Empty; + /// <summary> + /// 鐭俊鐧诲綍杩斿洖鐨刴d5鍚庣殑瀵嗙爜 + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string MD5PWD = string.Empty; + /// <summary> + /// 鐭俊鐧诲綍杩斿洖鐨刴d5鍚庣殑鍔犲瘑瀵嗙爜 + /// </summary> + public string Md5pwdEncrypt = string.Empty; + /// <summary> + /// 鐧婚檰璐﹀彿鐨凣uid + /// </summary> + public string Guid = string.Empty; + /// <summary> + /// 鎴愬憳璇锋眰鎺у埗涓诲笎鍙锋浣忓畢鏃惰姹傚熀鍦板潃 + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string AdminRequestBaseUrl = string.Empty; + /// <summary> + /// 鎴愬憳璇锋眰鎺у埗涓诲笎鍙锋浣忓畢鏃惰姹傚熀鍦板潃鐨凩oginAccessToken鐨勫�� + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string AdminRequestToken = string.Empty; + /// <summary> + /// 杩滅▼杩炴帴鐨凪qtt鐨勫鎴风ID + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string ConnEmqClientId = string.Empty; + /// <summary> + /// 褰撳墠鐧诲綍鐨勮处鍙锋槸涓嶆槸涔嬪墠鐨勮处鍙� + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public bool TheSameLoginAccount = false; + + /// <summary> + /// 褰撳墠甯愬彿鐨凾oken + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string Token + { + get + { + if (Shared.Phone.UserCenter.HdlExperienceAccountLogic.Current.IsExperience == true) + { + //浣撻獙璐﹀彿鐨凾oken + return this.TokenExperience; + } + string md5Password; + if (string.IsNullOrEmpty(Password)) + { + //鐢ㄤ簬鐭俊鐧诲綍瀵嗙爜涓� + md5Password = MD5PWD; + } + else + { + var result = System.Text.Encoding.UTF8.GetBytes(Password); + var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); + var output = md5.ComputeHash(result); + md5Password = BitConverter.ToString(output).Replace("-", ""); + } + var account_md5Pssword = Account + ":" + md5Password; + var tokenBytes = System.Text.Encoding.UTF8.GetBytes(account_md5Pssword); + return Convert.ToBase64String(tokenBytes).Replace("=", "%3D"); + } + + } + + /// <summary> + /// 浣撻獙璐﹀彿鐨凾oken + /// </summary> + [Newtonsoft.Json.JsonIgnore] + private string m_TokenExperience = null; + [Newtonsoft.Json.JsonIgnore] + public string TokenExperience + { + get + { + if (m_TokenExperience != null) { return m_TokenExperience; } + + var result = System.Text.Encoding.UTF8.GetBytes("123456"); + var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); + var output = md5.ComputeHash(result); + var md5Password = BitConverter.ToString(output).Replace("-", ""); + var account_md5Pssword = "ceyir277@163.com:" + md5Password; + var tokenBytes = System.Text.Encoding.UTF8.GetBytes(account_md5Pssword); + m_TokenExperience = Convert.ToBase64String(tokenBytes).Replace("=", "%3D"); + return m_TokenExperience; + } + } + + /// <summary> + /// 鐧诲綍鏃禩oken(鐩墠杩欎笢瑗挎病鐢�) + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string LoginToken = string.Empty; + + public string HomeId = string.Empty; + + /// <summary> + /// 浣忓畢鏂囦欢鍒楄〃 + /// </summary> + public List<string> HomeFilePathList = new List<string>(); + + [Newtonsoft.Json.JsonIgnore] + private House m_Home = null; + /// <summary> + /// 褰撳墠浣忓畢 + /// </summary> + /// <value>The home.</value> + [Newtonsoft.Json.JsonIgnore] + public House Home + { + get + { + if (m_Home != null) + { + return m_Home; + } + m_Home = Phone.UserCenter.HdlResidenceLogic.Current.GetHouseByHouseId(HomeId); + if (m_Home == null) + { + m_Home = new House(); + } + return m_Home; + } + set + { + m_Home = value; + } + } + + /// <summary> + /// 鍏ㄨ矾寰� + /// <para> 浣跨敤鏂规硶锛� FullPath + FileName </para> + /// </summary> + /// <value>The full path.</value> + [Newtonsoft.Json.JsonIgnore] + public string FullPath + { + get + { + return System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Instance.Guid, Instance.HomeId); + } + } + + /// <summary> + /// 淇濆瓨褰撳墠瀵硅薄 + /// </summary> + public void Save() + { + //鍔犲瘑,涓嶈兘淇濆瓨鏄庣爜 + this.PasswordEncrypt = Phone.UserCenter.UserCenterLogic.EncryptPassword("hD1(La3o", this.Password); + this.Md5pwdEncrypt = Phone.UserCenter.UserCenterLogic.EncryptPassword("hD1(La3o", this.MD5PWD); + + var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); + Shared.IO.FileUtils.WriteFileByBytes(fileName, bytes); + } + } +} -- Gitblit v1.8.0