HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using 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>
        /// 服务器注册ID
        /// </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)
            {
                //解密
                config.Password = Phone.UserCenter.UserCenterLogic.DecryptPassword("hD1(La3o", config.PasswordEncrypt);
            }
        }
 
        /// <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>
        /// 短信登录返回的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;
        /// <summary>
        /// 当前登录的账号是不是之前的账号
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public bool TheSameLoginAccount = false;
 
        /// <summary>
        /// 当前帐号的Token
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        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>
        [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);
            var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
            Shared.IO.FileUtils.WriteFileByBytes(fileName, bytes);
            ReFresh();
        }
    }
}