From c1de48884fa145a16a0f8bcee93274dcfaa0ff82 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期四, 07 五月 2020 10:40:28 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev-tzy' into dev-2020xm --- ZigbeeApp/Shared/Phone/ZigBee/Common/Config.cs | 196 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 196 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..7c83759 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/ZigBee/Common/Config.cs @@ -0,0 +1,196 @@ +锘縰sing System; +using System.Collections.Generic; + +namespace Shared.Common +{ + [System.Serializable] + public class Config + { + static readonly string fileName = "Config.json"; + static Config config; + 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> + /// Gets a value indicating whether this <see cref="T:Shared.Common.Config"/> is login. + /// </summary> + /// <value><c>true</c> if is login; otherwise, <c>false</c>.</value> + public bool IsLogin + { + get + { + return (DateTime.Now - LoginDateTime).Days < 7; + } + } + + /// <summary> + /// 璐︽埛鐧诲綍鎴愬姛鐨勮处鎴风被鍨� + /// </summary> + public int AccountType = 0; + /// <summary> + /// 璐︽埛鐧诲綍鎴愬姛鐨勪富ID + /// </summary> + public int MasterID = 0; + + + 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); + } + } + + /// <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> + public string MD5PWD = string.Empty; + /// <summary> + /// 鐧婚檰璐﹀彿鐨凣uid + /// </summary> + public string Guid = string.Empty; + /// <summary> + /// 鎴愬憳璇锋眰鎺у埗涓诲笎鍙锋浣忓畢鏃惰姹傚熀鍦板潃 + /// </summary> + public string AdminRequestBaseUrl = string.Empty; + /// <summary> + /// 鎴愬憳璇锋眰鎺у埗涓诲笎鍙锋浣忓畢鏃惰姹傚熀鍦板潃鐨凩oginAccessToken鐨勫�� + /// </summary> + public string AdminRequestToken = string.Empty; + /// <summary> + /// 杩滅▼杩炴帴鐨凪qtt鐨勫鎴风ID + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string ConnEmqClientId = string.Empty; + + [Newtonsoft.Json.JsonIgnore] + /// <summary> + /// 褰撳墠甯愬彿鐨凾oken + /// </summary> + public string Token + { + get + { + 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> + public string LoginToken = string.Empty; + + public List<string> HomeFilePathList = new List<string> { }; + + public string HomeId = string.Empty; + + [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 = House.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); + var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); + Shared.IO.FileUtils.WriteFileByBytes(fileName, bytes); + ReFresh(); + } + } +} -- Gitblit v1.8.0