public ActionResult LogOn(LogOnModel model) { if (ModelState.IsValid) { var userPassword = _adminUserTask.GetByUserName(model.UserName); if (userPassword == null) { return(AlertMsg("账号不存在", Request.UrlReferrer.PathAndQuery)); } if (userPassword.Password != CryptTools.HashPassword(model.Password)) { return(AlertMsg("账号或密码不正确", Request.UrlReferrer.PathAndQuery)); } if (userPassword.IsLock) { return(AlertMsg("对不起,您的账号被锁定", Request.UrlReferrer.PathAndQuery)); } if (model.ValidationCode != Session["code"].ToString()) { return(AlertMsg("验证码不正确", Request.UrlReferrer.PathAndQuery)); } AccountDto account = new AccountDto(); account.AdminUserId = userPassword.AdminUserId; account.UserName = userPassword.UserName; account.RoleId = userPassword.RoleId; Session["Account"] = account; SysLogTask.AddLog(new MyProject.Core.Entities.SysLogDto() { Message = "", Module = LogModuleEnum.Land, Type = LogTypeEnum.Land, Operator = userPassword.UserName, Result = "登陆成功" }); return(RedirectToAction("Index", "Home")); } return(View(model)); }
public ActionResult LogInIndex(LogOnModel model) { if (ModelState.IsValid) { var userPassword = _adminUserTask.GetByUserName(model.UserName); if (userPassword == null) { ModelState.AddModelError("UserName", "账号不存在"); return(View(model)); } if (userPassword.Password != CryptTools.HashPassword(model.Password)) { ModelState.AddModelError("UserName", "密码不正确"); return(View(model)); } if (userPassword.IsLock) { ModelState.AddModelError("Password", "对不起,您的账号被锁定"); return(View(model)); } HttpCookie cookie = new HttpCookie("Account", userPassword.UserName); cookie.Expires = DateTime.Now.AddMinutes(60); Response.Cookies.Add(cookie); SysLogTask.AddLog(new MyProject.Core.Entities.SysLogDto() { Message = "", Module = LogModuleEnum.Land, Type = LogTypeEnum.Land, Operator = userPassword.UserName, Result = "登陆成功" }); return(RedirectToAction("Index", "Home")); } return(View(model)); }
public ActionResult Post(string signature, string timestamp, string nonce, string echostr) { try { if (CheckSignature(XiaoWeiXinSdkTask.Token)) { WeixinMessage message = null; string msgBody = ""; Stream s = System.Web.HttpContext.Current.Request.InputStream; byte[] b = new byte[s.Length]; s.Read(b, 0, (int)s.Length); msgBody = Encoding.UTF8.GetString(b); if (string.IsNullOrWhiteSpace(msgBody)) { SysLogTask.AddLog(new SysLogDto() { Message = "lkpost过来的数据包:空" + msgBody.Length + DateTime.Now.ToString(), Module = LogModuleEnum.WeiXin, Operator = "zl", Result = "加密失败", Type = LogTypeEnum.WeiXinREceive }); return(null); } SysLogTask.AddLog(new SysLogDto() { Message = "msgBody:" + msgBody.Length, Module = LogModuleEnum.WeiXin, Operator = "zl", Result = "加密失败", Type = LogTypeEnum.WeiXinREceive }); message = AcceptMessageAPI.Parse(msgBody); var response = _sdk.Execute(message);//处理接收到的信息 SysLogTask.AddLog(new SysLogDto() { Message = "response:" + response, Module = LogModuleEnum.WeiXin, Operator = "zl", Result = "加密失败", Type = LogTypeEnum.WeiXinREceive }); } else { SysLogTask.AddLog(new SysLogDto() { Message = "lk消息真实性效验,不通过", Module = LogModuleEnum.WeiXin, Operator = "zl", Result = "加密失败", Type = LogTypeEnum.WeiXinREceive }); } } catch (Exception ex) { SysLogTask.AddLog(new SysLogDto() { Message = "lk出错:" + ex.Message + DateTime.Now.ToString(), Module = LogModuleEnum.WeiXin, Operator = "zl", Result = "加密失败", Type = LogTypeEnum.WeiXinREceive }); } return(Content("")); //返回空串表示有响应 }
/// <summary> /// 获取小程序账号信息(如果关注了公众号就会返回unionid,如果没关注过的不能用该方法拿unionid) /// </summary> /// <param name="code"></param> /// <returns></returns> public ActionResult GetInfo(string code) { try { XiaoWeiXinAppDecryptTask _appDecrypt = new XiaoWeiXinAppDecryptTask(XiaoWeiXinSdkTask.appID, XiaoWeiXinSdkTask.appsecret); return(Json(new RequestResultDto() { Msg = _appDecrypt.GetOpenIdAndSessionKeyString(code), Ret = 0 }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { SysLogTask.AddLog(new SysLogDto() { Message = e.Message, Module = LogModuleEnum.WeiXin, Operator = "zl", Result = "加密失败", Type = LogTypeEnum.WeiXinREceive }); } return(Json(new RequestResultDto() { Msg = "错误", Ret = -1 }, JsonRequestBehavior.AllowGet)); }
public ActionResult Post(string signature, string timestamp, string nonce, string echostr) { WeixinMessage message = null; var safeMode = Request.QueryString.Get("encrypt_type") == "aes"; using (var streamReader = new StreamReader(Request.InputStream)) { var decryptMsg = string.Empty; var msg = streamReader.ReadToEnd(); #region 解密 if (safeMode) { var msg_signature = Request.QueryString.Get("msg_signature"); var wxBizMsgCrypt = new WXBizMsgCrypt(WeiXinSdkTask.Token, WeiXinSdkTask.appsecret, WeiXinSdkTask.appID); var ret = wxBizMsgCrypt.DecryptMsg(msg_signature, timestamp, nonce, msg, ref decryptMsg); if (ret != 0)//解密失败 { SysLogTask.AddLog(new SysLogDto() { Message = "message:" + ret + "request:" + msg, Module = LogModuleEnum.WeiXin, Operator = "zl", Result = "解密失败", Type = LogTypeEnum.WeiXinREceive }); } } else { decryptMsg = msg; } #endregion message = AcceptMessageAPI.Parse(decryptMsg); } var response = _sdk.Execute(message);//处理接收到的信息 var encryptMsg = string.Empty; #region 加密 if (safeMode) { var msg_signature = Request.QueryString.Get("msg_signature"); var wxBizMsgCrypt = new WXBizMsgCrypt(WeiXinSdkTask.Token, WeiXinSdkTask.appsecret, WeiXinSdkTask.appID); var ret = wxBizMsgCrypt.EncryptMsg(response, timestamp, nonce, ref encryptMsg); if (ret != 0)//加密失败 { SysLogTask.AddLog(new SysLogDto() { Message = "message:" + ret + "response:" + response, Module = LogModuleEnum.WeiXin, Operator = "zl", Result = "加密失败", Type = LogTypeEnum.WeiXinREceive }); } } else { encryptMsg = response; } #endregion return(new ContentResult { Content = encryptMsg, ContentType = "text/xml", ContentEncoding = System.Text.UTF8Encoding.UTF8 }); }