public void Sure() { try { if (!PhoneHelper.ValidateMobile(UserName)) { SendMsg("resetPassWord", "userNameError"); return; } if (CheckCode == "") { SendMsg("resetPassWord", "checkCodeError"); return; } if (Password == "") { SendMsg("resetPassWord", "passWordError"); return; } var result = new LoginLogic().ResetPassWord(InterfacePath.Default.ResetPassWord, CheckCode, UserName, Password); SendMsg("resetPassWord", result.code.ToString()); Log4Helper.Info(this.GetType(), $"手机号:{UserName},找回密码:{result.msg}"); } catch (Exception ex) { SendMsg("resetPassWord", "Error"); Log4Helper.Error(this.GetType(), ex); } }
/// <summary> /// 确定 /// </summary> public void Sure() { try { if (!PhoneHelper.ValidateMobile(UserName)) { SendMsg("register", "userNameError"); return; } if (CheckCode == "") { SendMsg("register", "checkCodeError"); return; } if (Password == "") { SendMsg("register", "passWordError"); return; } LoginLogic loginLogic = new LoginLogic(); ResultModel <Token> result = loginLogic.Register(InterfacePath.Default.Register, CheckCode, UserName, NickName, Password, "", ""); SendMsg("register", result.code.ToString()); Log4Helper.Info(this.GetType(), $"手机号:{UserName},注册:{result.msg}"); } catch (Exception ex) { SendMsg("register", "Error"); Log4Helper.Error(this.GetType(), ex); } }
public SqlSugarClient GetInstance(string connectionString) { SqlSugarClient db = new SqlSugarClient( new ConnectionConfig() { ConnectionString = connectionString, DbType = DbType.MySql, IsAutoCloseConnection = true, // 设为true相同线程是同一个SqlConnection IsShardSameThread = true, //从实体特性中读取主键自增列信息 InitKeyType = InitKeyType.Attribute, MoreSettings = new ConnMoreSettings() { IsWithNoLockQuery = true }, //开启二级数据缓存后,用户规模的增长和系统响应速度成正相关,直接采用分布式redis缓存避免数据库击穿 //ConfigureExternalServices = new ConfigureExternalServices() //{ // DataInfoCacheService = new RedisCache(ConfigSettings.PlatformDefaultCache.Split(':')[0], 6379, null, 300, 0), //} }); #if DEBUG //调式代码 用来打印SQL db.Aop.OnLogExecuting = (sql, pars) => { Log4Helper.Info(sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); }; #endif return(db); }
/// <summary> /// 发送短信验证码 /// </summary> /// <param name="mobile">手机号</param> /// <param name="checkCodeType"></param> public ResultModel SendMessage(string strUrl, string mobile, string checkCodeType) { Log4Helper.Info(this.GetType(), $"手机号;{mobile}发送短信一次!"); //string strUrl = "http://front.future.alibaba.com/user/auth/checkCode/send"; Dictionary <string, string> param = new Dictionary <string, string>(); param.Add("checkCodeType", checkCodeType); param.Add("mobile", mobile); Dictionary <string, string> header = new Dictionary <string, string>(); header.Add("GeneralParam", JsonHelper.ToJson(SoftwareInformation.Instance())); return(JsonHelper.JsonToObj <ResultModel>(ApiHelper.SendPost(strUrl, param, header, "post"))); }
public void Login() { try { if (!string.IsNullOrWhiteSpace(UserName) && !string.IsNullOrWhiteSpace(Password)) { this.IsCancel = false; var result = new LoginLogic().Login(InterfacePath.Default.Login, UserName, Password); if (result.code == 200)//登录成功 { //保存登录信息 SaveLoginInfo(); #region 加载用户资料 UserLogic logic = new UserLogic(); ResultModel <UserInfoModel> userModel = logic.GetUserInfo(InterfacePath.Default.GetUserInfo, result.data.token); Loginer.LoginerUser.UserId = userModel.data.userId; Loginer.LoginerUser.PhoneNo = UserName; Loginer.LoginerUser.NickName = userModel.data.nickname; Loginer.LoginerUser.ProFilePhoto = userModel.data.profilePhoto; Loginer.LoginerUser.CreateTime = userModel.data.createTime; Loginer.LoginerUser.Token = result.data.token; #endregion } //发送登录消息 SendMsg("Login", result.code.ToString()); Log4Helper.Info(this.GetType(), $"手机号:{UserName},登录:{result.msg}"); } } catch (Exception ex) { SendMsg("Login", "Error"); Log4Helper.Error(this.GetType(), ex); } }
public static Pager <Product> GetListByPage(ProductParameter parameter) { Pager <Product> result = new Pager <Product>(); using (SaleContext db = new SaleContext()) { var query = db.Product.AsQueryable(); if (!string.IsNullOrEmpty(parameter.ProductName)) { query = query.Where(t => t.ProductName.Contains(parameter.ProductName)); } Log4Helper.Info("DAO层中写入日志信息:" + parameter.ProductName); result.Total = query.Count(); result.Rows = query.OrderBy(t => t.ProductId) .Skip(parameter.Skip) .Take(parameter.PageSize) .ToList(); return(result); } }
public MainWindow() { Log4Helper.Info(this.GetType(), "第一个日志记录"); InitializeComponent(); }
/// <summary> /// 根据用户名获取token /// </summary> /// <param name="appkey"></param> /// <returns></returns> public HttpResponseMessage GetToken(string appkey, string appsecrect) { lock (this) { //增加对appkey+secrect的解密 Log4Helper.Info(this.GetType(), String.Format("进入ServiceController.GetToken。appkey:{0},appsecrect:{1}", appkey, appsecrect)); //根据用户名获取token ResultMsg resultMsg = null; //判断参数是否合法 if (String.IsNullOrEmpty(appkey) || String.IsNullOrEmpty(appsecrect)) { resultMsg = new ResultMsg(); resultMsg.StatusCode = (int)StatusCodeEnum.ParameterError; resultMsg.Info = StatusCodeEnum.ParameterError.GetEnumText(); resultMsg.Data = ""; Log4Helper.Error(this.GetType(), "ServiceController.GetToken失败。请检查参数appkey或appsecrect为空!"); return(HttpResponseExtension.toJson(JsonConvert.SerializeObject(resultMsg))); } //1.检查缓存中是否有,有就结束 Token token = (Token)HttpRuntime.Cache.Get(appkey); if (token == null) { //1.1 从数据库取 UserPlatform userPlatform = UserPlatformService.Instance.GetByAppKey(appkey, appsecrect); if (userPlatform == null) { resultMsg = new ResultMsg(); resultMsg.StatusCode = (int)StatusCodeEnum.TokenInvalid; resultMsg.Info = StatusCodeEnum.TokenInvalid.GetEnumText(); resultMsg.Data = ""; Log4Helper.Error(this.GetType(), String.Format("ServiceController.GetToken失败。请检查AppKey:{0}是否注册过!", appkey)); return(HttpResponseExtension.toJson(JsonConvert.SerializeObject(resultMsg))); } if (userPlatform != null && String.IsNullOrEmpty(userPlatform.Token)) { FeedBackResult result = RefreshToken(appkey); if (!result.Result) { resultMsg = new ResultMsg(); resultMsg.StatusCode = (int)StatusCodeEnum.TokenInvalid; resultMsg.Info = StatusCodeEnum.TokenInvalid.GetEnumText(); resultMsg.Data = ""; Log4Helper.Error(this.GetType(), String.Format("ServiceController.GetToken失败。刷新token:{0}失败!", token)); return(HttpResponseExtension.toJson(JsonConvert.SerializeObject(resultMsg))); } //重新获取一次 userPlatform = UserPlatformService.Instance.GetByAppKey(appkey, appsecrect); } //是否过期 if (DateTime.Now > userPlatform.TokenExpireTime) { //过期 刷新 FeedBackResult result = RefreshToken(appkey); if (!result.Result) { resultMsg = new ResultMsg(); resultMsg.StatusCode = (int)StatusCodeEnum.TokenInvalid; resultMsg.Info = StatusCodeEnum.TokenInvalid.GetEnumText(); resultMsg.Data = ""; Log4Helper.Error(this.GetType(), String.Format("ServiceController.GetToken失败。刷新token:{0}失败!", token)); return(HttpResponseExtension.toJson(JsonConvert.SerializeObject(resultMsg))); } //获取 userPlatform = UserPlatformService.Instance.GetByAppKey(appkey, appsecrect); } token = new Token { AppKey = userPlatform.AppKey, SignToken = userPlatform.Token, ExpireTime = userPlatform.TokenExpireTime }; //插入缓存 HttpRuntime.Cache.Insert(token.AppKey, token, null, token.ExpireTime, TimeSpan.Zero); } else if (token.ExpireTime < DateTime.Now) { //过期 刷新 FeedBackResult result = RefreshToken(appkey); if (!result.Result) { resultMsg = new ResultMsg(); resultMsg.StatusCode = (int)StatusCodeEnum.TokenInvalid; resultMsg.Info = StatusCodeEnum.TokenInvalid.GetEnumText(); resultMsg.Data = ""; Log4Helper.Error(this.GetType(), String.Format("ServiceController.GetToken失败。刷新token:{0}失败!", token)); return(HttpResponseExtension.toJson(JsonConvert.SerializeObject(resultMsg))); } //获取 UserPlatform userPlatform = UserPlatformService.Instance.GetByAppKey(appkey, appsecrect); token = new Token { AppKey = userPlatform.AppKey, SignToken = userPlatform.Token, ExpireTime = userPlatform.TokenExpireTime }; //移除缓存 HttpRuntime.Cache.Remove(token.AppKey); //插入缓存 HttpRuntime.Cache.Insert(token.AppKey, token, null, token.ExpireTime, TimeSpan.Zero); } //返回token信息 resultMsg = new ResultMsg(); resultMsg.StatusCode = (int)StatusCodeEnum.Success; resultMsg.Info = ""; resultMsg.Data = token; return(HttpResponseExtension.toJson(JsonConvert.SerializeObject(resultMsg))); } }