| | |
| | | { |
| | | [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; |
| | | } |
| | | } |
| | | {
|
| | | #region ■ 需要保存的变量_____________________ |
| | |
|
| | | /// <summary> |
| | | /// 服务器注册ID |
| | | /// <summary>
|
| | | /// 当前账号:刷新Token用的token(不用记录什么有效期,如果刷新失败,就踢人即可)
|
| | | /// </summary> |
| | | public string RegistrationID = string.Empty; |
| | | |
| | | public string RefreshToken = string.Empty; |
| | | /// <summary>
|
| | | /// 将极光ID发给云端之后,云端返回的Token
|
| | | /// </summary> |
| | | public string PushId = string.Empty; |
| | | /// <summary> |
| | | /// 账户登录成功时的时间 |
| | | /// </summary> |
| | | public DateTime LoginDateTime = DateTime.MinValue;
|
| | | /// <summary> |
| | | /// |
| | | /// 当前登录的帐号 |
| | | /// </summary> |
| | | public string Account = string.Empty;
|
| | | /// <summary>
|
| | | /// 添加到Token头部的东西(不要理它,只给底层使用)
|
| | | /// </summary>
|
| | | public string HeaderPrefix = string.Empty; |
| | | /// <summary> |
| | | /// 登陆账号的Guid,也是账号的userId |
| | | /// </summary> |
| | | public string Guid = string.Empty; |
| | | /// <summary>
|
| | | /// 当前的住宅ID
|
| | | /// </summary> |
| | | public string HomeId = string.Empty;
|
| | | /// <summary>
|
| | | /// 住宅文件列表
|
| | | /// </summary>
|
| | | public List<string> HomeFilePathList = new List<string>();
|
| | |
|
| | | #endregion |
| | |
|
| | | #region ■ 缓存变量___________________________
|
| | |
|
| | | /// <summary> |
| | | /// 服务器注册ID(可以说是极光ID) |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public bool IsLogin |
| | | public string RegistrationID = string.Empty;
|
| | | /// <summary> |
| | | /// 判断当前时间点是否能够自动登录 |
| | | /// </summary> |
| | | public bool CanAutoLogin |
| | | { |
| | | 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)
|
| | | {
|
| | | //解密
|
| | | config.Password = Phone.UserCenter.UserCenterLogic.DecryptPassword("hD1(La3o", config.PasswordEncrypt);
|
| | | } |
| | | if (config.Md5pwdEncrypt != string.Empty) |
| | | { |
| | | //解密 |
| | | config.MD5PWD = Phone.UserCenter.UserCenterLogic.DecryptPassword("hD1(La3o", config.Md5pwdEncrypt); |
| | | } |
| | | }
|
| | |
|
| | | /// <summary> |
| | | /// 账户登录成功的账户类型(此变量默认为0,并且不赋值) |
| | | /// 是否同意隐私政策 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int AccountType = 0;
|
| | | public bool AcceiptPolicy = false;
|
| | | /// <summary> |
| | | /// 当前登录的帐号 |
| | | /// </summary> |
| | | public string Account = string.Empty; |
| | | /// <summary> |
| | | /// 当前帐号密码 |
| | | /// 当前帐号的Token(这个东西不用存了) |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string Password = string.Empty; |
| | | /// <summary>
|
| | | /// 加密密码
|
| | | /// </summary> |
| | | public string PasswordEncrypt = string.Empty; |
| | | public string Token = string.Empty;
|
| | | /// <summary> |
| | | /// 短信登录返回的md5后的密码 |
| | | /// 管理员获取到的主人的Token(这个东西不用存了) |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string MD5PWD = string.Empty; |
| | | /// <summary> |
| | | /// 短信登录返回的md5后的加密密码 |
| | | /// </summary> |
| | | public string Md5pwdEncrypt = string.Empty; |
| | | /// <summary> |
| | | /// 登陆账号的Guid |
| | | /// </summary> |
| | | public string Guid = string.Empty; |
| | | /// <summary>
|
| | | /// 成员请求控制主帐号此住宅时请求基地址
|
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string AdminRequestBaseUrl = string.Empty;
|
| | | /// <summary>
|
| | | /// 成员请求控制主帐号此住宅时请求基地址的LoginAccessToken的值
|
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string AdminRequestToken = string.Empty; |
| | | public string MasterToken = string.Empty; |
| | | /// <summary>
|
| | | /// 远程连接的Mqtt的客户端ID
|
| | | /// </summary> |
| | |
| | | /// </summary>
|
| | | [Newtonsoft.Json.JsonIgnore]
|
| | | public bool TheSameLoginAccount = false;
|
| | |
|
| | | /// <summary> |
| | | /// 当前帐号的Token |
| | | /// <summary>
|
| | | /// 安卓的系统返回按键能否按下(比如在备份还原时,不能按下返回键)
|
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string Token |
| | | { |
| | | get |
| | | { |
| | | if (Shared.Phone.UserCenter.HdlExperienceAccountLogic.Current.IsExperience == true)
|
| | | {
|
| | | //体验账号的Token
|
| | | 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"); |
| | | } |
| | | |
| | | }
|
| | |
|
| | | public bool BackKeyCanClick = true;
|
| | | /// <summary>
|
| | | /// 体验账号的Token
|
| | | /// </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>
|
| | | /// 登录时Token(目前这东西没用) |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string LoginToken = string.Empty; |
| | | |
| | | public string HomeId = string.Empty;
|
| | |
|
| | | /// <summary>
|
| | | /// 住宅文件列表
|
| | | /// 访问云端的语言(有些接口需要,目前是 CHINESE 或者 ENGLISH)
|
| | | /// </summary>
|
| | | public List<string> HomeFilePathList = new List<string>();
|
| | |
|
| | | [Newtonsoft.Json.JsonIgnore]
|
| | | public string HttpLanguage = "CHINESE";
|
| | | /// <summary>
|
| | | /// 当前住宅
|
| | | /// </summary>
|
| | | [Newtonsoft.Json.JsonIgnore] |
| | | private House m_Home = null; |
| | | /// <summary> |
| | |
| | | {
|
| | | return m_Home;
|
| | | } |
| | | m_Home = Phone.UserCenter.HdlResidenceLogic.Current.GetHouseByHouseId(HomeId); |
| | | m_Home = Phone.HdlResidenceLogic.Current.GetHouseByHouseId(HomeId); |
| | | if (m_Home == null) |
| | | { |
| | | m_Home = new House(); |
| | |
| | | m_Home = value;
|
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 全路径 |
| | | /// <para> 使用方法: FullPath + FileName </para> |
| | |
| | | { |
| | | return System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Instance.Guid, Instance.HomeId); |
| | | } |
| | | } |
| | | }
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化_____________________________ |
| | |
|
| | | /// <summary>
|
| | | /// Config文件名
|
| | | /// </summary> |
| | | private const string fileName = "Config.json"; |
| | | |
| | | private static Config config = null; |
| | | /// <summary>
|
| | | /// Config对象
|
| | | /// </summary> |
| | | public static Config Instance |
| | | { |
| | | get |
| | | { |
| | | if (config == null) |
| | | { |
| | | ReFresh(); |
| | | } |
| | | return config; |
| | | } |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 刷新
|
| | | /// </summary>
|
| | | private static void ReFresh() |
| | | { |
| | | var file = Shared.IO.FileUtils.ReadFile(fileName); |
| | | if (file != null && file.Length > 0)
|
| | | {
|
| | | config = Newtonsoft.Json.JsonConvert.DeserializeObject<Config>(System.Text.Encoding.UTF8.GetString(file));
|
| | | //解密
|
| | | config.RefreshToken = Phone.HdlCommonLogic.Current.DecryptPassword("hD1(La3o", config.RefreshToken);
|
| | | } |
| | | else
|
| | | {
|
| | | config = new Config();
|
| | | } |
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 保存_______________________________ |
| | |
|
| | | /// <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 oldToken1 = this.RefreshToken; |
| | | this.RefreshToken = Phone.HdlCommonLogic.Current.EncryptPassword("hD1(La3o", oldToken1); |
| | | |
| | | var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | Shared.IO.FileUtils.WriteFileByBytes(fileName, bytes); |
| | | } |
| | | |
| | | this.RefreshToken = oldToken1; |
| | | }
|
| | |
|
| | | #endregion |
| | | } |
| | | } |