| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | using System.IO; |
| | | using System.Drawing; |
| | | using HDL_ON.DAL; |
| | | using HDL_ON.DAL.Server; |
| | | |
| | | namespace HDL_ON |
| | | { |
| | | [System.Serializable] |
| | | public class UserInfo |
| | | { |
| | | public static readonly string ConfigFile = "UserInfo_File"; |
| | | /// <summary> |
| | | /// 通用方法 |
| | | /// </summary> |
| | | private static UserInfo m_Current = null; |
| | | /// <summary> |
| | | /// 通用方法 |
| | | /// </summary> |
| | | public static UserInfo Current |
| | | { |
| | | get |
| | | { |
| | | if (m_Current == null) |
| | | { |
| | | try |
| | | { |
| | | UserInfo temp = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo>(System.Text.Encoding.UTF8.GetString(FileUtils.ReadFile(ConfigFile))); |
| | | if (temp == null) |
| | | { |
| | | m_Current = new UserInfo() { }; |
| | | Utlis.WriteLine("UserInfo null"); |
| | | } |
| | | else |
| | | { |
| | | m_Current = temp; |
| | | Utlis.WriteLine("UserInfo Current"); |
| | | } |
| | | } |
| | | catch |
| | | { |
| | | m_Current = new UserInfo() { }; |
| | | Utlis.WriteLine("UserInfo null"); |
| | | } |
| | | } |
| | | return m_Current; |
| | | } |
| | | } |
| | | |
| | | #region 新增保存参数 |
| | | /// <summary> |
| | | /// 账号注册服务器信息 |
| | | /// </summary> |
| | | public string RequestHttpsHost = "https://china.hdlcontrol.com"; |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public GlobalRegionListRes GlobalRegion; |
| | | |
| | | /// <summary> |
| | | /// 是否同意协议 |
| | | /// </summary> |
| | | public bool isAgreePrivacyPolicy; |
| | | |
| | | /// <summary> |
| | | /// 忽略更新的版本号 |
| | | /// </summary> |
| | | public string IgnoreUpdateVersion = string.Empty; |
| | | |
| | | /// <summary> |
| | | /// 信息推送标记 |
| | | /// </summary> |
| | | public string PushDeviceToken; |
| | | /// <summary> |
| | | /// phoneName |
| | | /// </summary> |
| | | public string PhoneName; |
| | | /// <summary> |
| | | /// 添加推送Token成功时返回的Id |
| | | /// </summary> |
| | | public string PushId; |
| | | #endregion |
| | | |
| | | |
| | | #region 用户数据 |
| | | /// <summary> |
| | | /// 用户名称 |
| | | /// </summary> |
| | | public string UserName = ""; |
| | | public string userName = ""; |
| | | /// <summary> |
| | | /// 用户 |
| | | /// </summary> |
| | | public string AccountString=""; |
| | | /// <summary> |
| | | /// 用户密码 |
| | | /// </summary> |
| | | public string Password = ""; |
| | | public string AccountString = ""; |
| | | ///// <summary> |
| | | ///// 用户密码 |
| | | ///// </summary> |
| | | //public string password = ""; |
| | | //string aesPassword = ""; |
| | | ///// <summary> |
| | | ///// 用户密码 |
| | | ///// </summary> |
| | | //public string password |
| | | //{ |
| | | // get |
| | | // { |
| | | // return Shared.Securitys.EncryptionService.AesDecryptTopic(aesPassword, "85521566HDLONPRO"); |
| | | // } |
| | | // set |
| | | // { |
| | | // aesPassword = Shared.Securitys.EncryptionService.AesEncryptTopic(value, "85521566HDLONPRO"); |
| | | // } |
| | | //} |
| | | /// <summary> |
| | | /// 用户手机号码 |
| | | /// </summary> |
| | | public string UserMobileInfo = ""; |
| | | public string userMobileInfo = ""; |
| | | /// <summary> |
| | | /// 用户邮箱信息 |
| | | /// </summary> |
| | | public string UserEmailInfo = ""; |
| | | public string userEmailInfo = ""; |
| | | /// <summary> |
| | | /// 用户ID |
| | | /// </summary> |
| | | public int ID; |
| | | |
| | | public string ID; |
| | | /// <summary> |
| | | /// 用户选择显示的语言 |
| | | /// </summary> |
| | | public string language = "Chinese"; |
| | | /// <summary> |
| | | /// 用户区域 |
| | | /// </summary> |
| | | public string areaCode = "86"; |
| | | /// <summary> |
| | | /// 用户头像图片 |
| | | /// </summary> |
| | | public string headImagePagePath = "LoginIcon/2.png"; |
| | | ///// <summary> |
| | | ///// 用户头像byte数据 |
| | | ///// </summary> |
| | | //public byte[] headImagePageBytes = null; |
| | | /// <summary> |
| | | /// 上一次登录时间 |
| | | /// </summary> |
| | | public DateTime LastTime = DateTime.MinValue; |
| | | |
| | | /// <summary> |
| | | /// 是否是登录状态 |
| | | /// </summary> |
| | | public bool IsLogin { |
| | | get { |
| | | public bool IsLogin |
| | | { |
| | | get |
| | | { |
| | | return (DateTime.Now - LastTime).TotalDays < 7; |
| | | } |
| | | } |
| | | |
| | | public int AccountType = 0; |
| | | |
| | | public int MasterID = 0; |
| | | |
| | | public string LoginTokenString{ |
| | | get { |
| | | var result = Encoding.UTF8.GetBytes (Password); |
| | | var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider (); |
| | | var output = md5.ComputeHash (result); |
| | | var md5Password = BitConverter.ToString (output).Replace ("-", ""); |
| | | var account_md5Pssword = AccountString + ":" + md5Password; |
| | | var tokenBytes = Encoding.UTF8.GetBytes (account_md5Pssword); |
| | | return Convert.ToBase64String (tokenBytes).Replace ("=", "%3D"); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public string LoginTokenString; |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public string RefreshToken; |
| | | /// <summary> |
| | | /// UserType B端账号 C端账号 |
| | | /// </summary> |
| | | public string userType = "USER_C"; |
| | | /// <summary> |
| | | /// 用户住宅列表 |
| | | /// </summary> |
| | | public List<RegionInfoRes> HomeLists = new List<RegionInfoRes>(); |
| | | public List<RegionInfoRes> regionList = new List<RegionInfoRes>(); |
| | | |
| | | #endregion |
| | | |
| | | public void SaveUserInfo() |
| | | { |
| | | FileUtils.WriteFileByBytes(ConfigFile, Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// <!--SIP 帐号--> |
| | | /// 可视对讲使用的登录账号 |
| | | /// 退出登录重置参数 |
| | | /// </summary> |
| | | public string SIP_Account; |
| | | |
| | | public void SaveUserInfo () |
| | | public void LogoutReset() |
| | | { |
| | | MyIO.FileUtils.WriteFileByBytes ("Register_File", Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (this))); |
| | | userName = ""; |
| | | ID = ""; |
| | | LoginTokenString = ""; |
| | | RefreshToken = ""; |
| | | userType = "USER_C"; |
| | | LastTime = DateTime.MinValue; |
| | | headImagePagePath = "LoginIcon/2.png";//重置用户头像 |
| | | } |
| | | |
| | | private byte[] convertByte(Image img) |
| | | { |
| | | MemoryStream ms = new MemoryStream(); |
| | | img.Save(ms, img.RawFormat); |
| | | //byte[] bytes = new byte[ms.Length]; |
| | | //ms.Read(bytes, 0, Convert.ToInt32(ms.Length)); |
| | | //以上两句改成下面两句 |
| | | byte[] bytes = ms.ToArray(); |
| | | ms.Close(); |
| | | return bytes; |
| | | } |
| | | private Image convertImg(byte[] datas) |
| | | { |
| | | MemoryStream ms = new MemoryStream(datas); |
| | | Image img = Image.FromStream(ms, true);//在这里出错 |
| | | //流用完要及时关闭 |
| | | ms.Close(); |
| | | return img; |
| | | } |
| | | } |
| | | } |