New file |
| | |
| | | using 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> |
| | | /// 服务器注册ID |
| | | /// </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)
|
| | | {
|
| | | //解密
|
| | | 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> |
| | | /// 短信登录返回的md5后的密码 |
| | | /// </summary> |
| | | public string MD5PWD = string.Empty; |
| | | /// <summary> |
| | | /// 登陆账号的Guid |
| | | /// </summary> |
| | | public string Guid = string.Empty; |
| | | /// <summary>
|
| | | /// 成员请求控制主帐号此住宅时请求基地址
|
| | | /// </summary> |
| | | public string AdminRequestBaseUrl = string.Empty;
|
| | | /// <summary>
|
| | | /// 成员请求控制主帐号此住宅时请求基地址的LoginAccessToken的值
|
| | | /// </summary> |
| | | public string AdminRequestToken = string.Empty; |
| | | /// <summary>
|
| | | /// 远程连接的Mqtt的客户端ID
|
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string ConnEmqClientId = string.Empty; |
| | | |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | /// <summary> |
| | | /// 当前帐号的Token |
| | | /// </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>
|
| | | /// 登录时Token |
| | | /// </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(); |
| | | } |
| | | } |
| | | } |