public void SetMobileCode() { var codes = MobileCode.GetCodes(); var key = country.options[country.value].text; mobileCode.text = codes[key]; }
public async Task OnGetAsync(string phone, bool forgot = false) { var _user = await _signInManager.UserManager.FindByNameAsync(phone); if (_user != null) { var token = await _signInManager.UserManager.GenerateChangePhoneNumberTokenAsync(_user, phone); MobileCode mobileCode = new MobileCode() { Phone = phone, Code = token }; TempData["CodeConfirm"] = token; TempData["PhoneNumber"] = phone; TempData["Forgot"] = forgot; var client = new RestClient($"https://api.kavenegar.com/v1/50686738705469657761504154597A576F6F377A424E33373056424F4A41694E6678653432534443474A6B3D/verify/lookup.json?receptor={phone}&token={token}&template=ConfirmUser") { Timeout = -1 }; var request = new RestRequest(Method.GET); _ = client.Execute(request); } }
private void InitCountry() { var options = new List <Dropdown.OptionData>(); var codes = MobileCode.GetCodes(); foreach (string key in codes.Keys) { options.Add(new Dropdown.OptionData(key)); } country.AddOptions(options); }
public ActionResult GetMobileCodeSeconds(int operateType) { int second = disSecond; string mobile = UserLogin.Instance.GetCookie("mobilecode" + operateType.ToString()); if (!string.IsNullOrEmpty(mobile) && mobile.Split(',').Length > 1) { string[] mobileArr = mobile.Split(','); MobileCode code = _mobileCodeService.GetMobileCode(this.MpUserID, TypeConverter.StrToInt(mobileArr[1])); if (code != null) { TimeSpan tspan = System.DateTime.Now.Subtract(code.CreateDate); if (tspan.TotalSeconds < disSecond && tspan.TotalSeconds > 0) { second = disSecond - int.Parse(tspan.TotalSeconds.ToString("#")); } } } return(Json(new { count = second })); }
public ActionResult MyPos(Pos pos) { //当前登录用户 MpUser mpUser = _mpUserService.GetById(MpUserID); PosAuth posAuth = _posAuthService.GetUnique(p => p.MpUserId == mpUser.Id); //if (posAuth == null) //{ // return JsonMessage(false, "对不起,您还未申请POS,请先申请!"); //} if (posAuth != null) { ViewBag.Name = posAuth.Name; } else { ViewBag.Name = mpUser.NickName; } if (mpUser.Sex == 1) { ViewBag.Sex = "先生"; } else if (mpUser.Sex == 2) { ViewBag.Sex = "女士"; } else { ViewBag.Sex = ""; } int useCount = _mobileCodeService.GetMobileCodeCount(this.MpUserID, 4);//当天使用次数 if (useCount <= 5) { MobileCode lastCode = _mobileCodeService.GetMobileCode(this.MpUserID, 4);//是否存在未使用的证码 if (lastCode != null) { //验证 MobileCode mobileCode = _mobileCodeService.GetMobileCode(RQuery["MobilePhone"], RQuery["Code"], MpUserID, 4); if (mobileCode != null) { TimeSpan ts = DateTime.Now.Subtract(mobileCode.CreateDate).Duration(); mobileCode.Status = 1; if (ts.Minutes > 10) { return(JsonMessage(false, "验证码已经失效,请重新获取")); } _mobileCodeService.Update(mobileCode); if (_posService.PosBind(pos) == 1) { if (!string.IsNullOrEmpty(pos.MobilePhones) && pos.MobilePhones.Contains(RQuery["MobilePhone"])) { return(JsonMessage(false, "您已查询过当前POS信息,您可以点击我的POS查看详细!")); } else { _posService.ExcuteSql("update Pos set MobilePhones=isnull(MobilePhones,'')+'," + RQuery["MobilePhone"] + "',MpUserIds=isnull(MpUserIds,'')+'," + MpUserID.ToString() + "' where Id='" + pos.Id.ToString() + "'"); return(JsonMessage(true, pos.Id.ToString())); } } else { return(JsonMessage(false, "-1")); } } else { lastCode.Time += 1; _mobileCodeService.Update(lastCode); return(JsonMessage(false, "对不起,验证码有误,请检查!")); } } else { return(JsonMessage(false, "对不起,您还未点击发送验证码!")); } } else { return(JsonMessage(false, "对不起,您今天最多只能发起5次验证码")); } }
public ActionResult PosApplyProvide(string isEdit) { string message = string.Empty; bool isSuccess = true; if (!ValidatorPos(ref message)) { return(JsonMessage(false, message)); } //用户最近的一笔申请[未撤销] PosApply apply2 = _posApplyService.GetUnique(pos => pos.MpUserId == MpUserID && pos.Status == 0, "CreateDate", false); //有未过期的贷款申请 if (apply2 != null && !(isEdit == "1" && (DateTime.Now - apply2.CreateDate).Hours <= 24)) { return(RedirectToAction("PosMessage", new { })); } try { _posApplyService.BeginTransaction(); //当前登录用户 MpUser mpUser = _mpUserService.GetById(MpUserID); PosAuth posAuth = _posAuthService.GetUnique(pos => pos.MpUserId == mpUser.Id); ViewBag.IsAuth = false; if (posAuth != null) { ViewBag.IsAuth = posAuth.IsAuth > 0; } //进行手机验证 if (!ViewBag.IsAuth) { int useCount = _mobileCodeService.GetMobileCodeCount(this.MpUserID, 3);//当天使用次数 if (useCount <= 5) { MobileCode lastCode = _mobileCodeService.GetMobileCode(this.MpUserID, 3);//是否存在未使用的证码 if (lastCode != null) { //验证 MobileCode mobileCode = _mobileCodeService.GetMobileCode(RQuery["MobilePhone"], RQuery["Code"], MpUserID, 3); if (mobileCode != null) { TimeSpan ts = DateTime.Now.Subtract(mobileCode.CreateDate).Duration(); if (ts.Minutes > 10) { ViewBag.CodeError = "验证码已经失效,请重新获取"; isSuccess = false; } PosAuth auth = new PosAuth(); auth.MpUserId = MpUserID; auth.Name = RQuery["Name"]; auth.MobilePhone = RQuery["MobilePhone"]; auth.IsAuth = 1; _posAuthService.Insert(auth); } else { lastCode.Time += 1; _mobileCodeService.Update(lastCode); ViewBag.CodeError = "对不起,验证码有误,请检查!"; isSuccess = false; } } else { ViewBag.CodeError = "对不起,您还未点击发送验证码!"; isSuccess = false; } } else { ViewBag.CodeError = "对不起,您今天最多只能发起5次验证码!"; isSuccess = false; } } //处理贷款业务 if (isEdit == "1") { if (apply2 != null) { TryUpdateModel <PosApply>(apply2); if (isSuccess) { _posApplyService.Update(apply2); } } else { throw new OceanException("对不起,您的参数有误,请联系客服!"); } } else { apply2 = new PosApply(); TryUpdateModel <PosApply>(apply2); apply2.MpUserId = MpUserID; apply2.Status = apply2.AssignStatus = apply2.ProcessStatus = 0; if (isSuccess) { _posApplyService.Insert(apply2); } } } catch (Exception ex) { _posApplyService.Rollback(); throw new OceanException(string.Format("对不起,{0}!", ex.Message)); } finally { _posApplyService.Commit(); } if (isSuccess) { return(RedirectToAction("PosApply")); } else { return(View("PosApply", apply2)); } }
public ActionResult LoanApplyProvide(Loan loan) { string message = string.Empty; if (!ValidatorLoan(ref message)) { return(JsonMessage(false, message)); } //用户最近的一笔贷款申请[未撤销] Loan loan2 = _loanService.GetNewestLoanApplyByMpUserId(MpUserID); //有未过期的贷款申请 if (loan2 != null && DateTime.Now < loan2.CreateDate.AddMonths(1)) { return(JsonMessage(false, "您当前已经申请过贷款")); } try { _loanService.BeginTransaction(); //当前登录用户 MpUser mpUser = _mpUserService.GetById(MpUserID); //进行手机验证 if (mpUser.IsAuth == 0) { int useCount = _mobileCodeService.GetMobileCodeCount(this.MpUserID, 2);//当天使用次数 if (useCount <= 5) { MobileCode lastCode = _mobileCodeService.GetMobileCode(this.MpUserID, 2);//是否存在未使用的证码 if (lastCode != null) { //验证 MobileCode mobileCode = _mobileCodeService.GetMobileCode(loan.Phone, RQuery["Code"], MpUserID, 2); if (mobileCode != null) { TimeSpan ts = DateTime.Now.Subtract(mobileCode.CreateDate).Duration(); if (ts.Minutes > 10) { return(JsonMessage(false, "验证码已经失效,请重新获取")); } mpUser.Name = loan.LoanName; mpUser.MobilePhone = loan.Phone; mpUser.IsAuth = 1; _mpUserService.Update(mpUser); } else { lastCode.Time += 1; _mobileCodeService.Update(lastCode); return(JsonMessage(false, "对不起,验证码有误,请检查!")); } } else { return(JsonMessage(false, "对不起,您还未点击发送验证码!")); } } else { return(JsonMessage(false, "对不起,您今天最多只能发起5次验证码")); } } //处理贷款业务 loan.MpUserId = MpUserID; loan.Status = loan.AssignStatus = loan.ProcessStatus = 0; _loanService.Insert(loan); } catch (Exception ex) { _loanService.Rollback(); throw new OceanException(string.Format("对不起,{0}!", ex.Message)); } finally { _loanService.Commit(); } return(JsonMessage(true, "提交成功,等待管理员审核")); }
public ActionResult GetMobileCode(string mobile, int operateType) { if (_mobileCodeService.GetMobileCodeCount(this.MpUserID, operateType) > 5) { return(JsonMessage(false, "短信获取失败[您当天获取验证码的次数不能超过5次]")); } else { UserLogin.Instance.WriteCookie("mobilecode" + operateType, mobile + "," + operateType.ToString(), 10, "/", ""); //验证参数格式 long lSMID = 0; string smID = GlobalConfig.GetConfig()["SMID"]; if (!long.TryParse(smID, out lSMID)) { _log.Debug("SMID格式错误"); return(JsonMessage(false, "验证码获取失败,请稍后重试")); } #if DEBUG //创建验证码 MobileCode mobileCode = new MobileCode { MpUserId = MpUserID, Mobile = mobile, Code = StringHelper.GetRandomInt(6), Time = 0, OperationType = operateType, Status = 0 }; _mobileCodeService.Insert(mobileCode); return(JsonMessage(true, string.Format("{0}", mobileCode.Code))); #else string message = string.Empty; try { //短信猫发送短信 IList <string> mobiles = new List <string>(); mobiles.Add(mobile); string code = StringHelper.GetRandomInt(6); string yzMsg = string.Empty; if (operateType == 1) { yzMsg = string.Format("您本次申请福农宝额度调整的验证码为{0},验证码10分钟内有效,详询4000896336。", code); } else if (operateType == 2) { yzMsg = string.Format("您本次申请贷款的验证码为{0},验证码10分钟内有效,详询4000896336。", code); } else if (operateType == 3) { yzMsg = string.Format("您本次申请POS的验证码为{0},验证码10分钟内有效,详询4000896336。", code); } else if (operateType == 4) { yzMsg = string.Format("您本次申请摇奖的验证码为{0},验证码10分钟内有效,详询4000896336。", code); } else { yzMsg = string.Format("您本次查询POS的验证码为{0},验证码10分钟内有效,详询4000896336。", code); } SendSmsRequest sendSmsRequest = new SendSmsRequest(mobiles, yzMsg, lSMID); //if(true) if (new SmsClient().Execute(sendSmsRequest, ref message)) { //创建验证码 MobileCode mobileCode = new MobileCode { MpUserId = MpUserID, Mobile = mobile, Code = code, Time = 0, OperationType = operateType, Status = 0 }; _mobileCodeService.Insert(mobileCode); //return JsonMessage(true, "验证码获取成功"); return(JsonMessage(true, string.Format("{0}", string.Empty))); } else { Log4NetImpl.Write("验证码获取失败:" + message); SmsClient.ReleaseAPIClient();//释放资源 return(JsonMessage(false, "验证码获取失败")); } } catch (Exception ex) { string errMsg = ""; if (string.IsNullOrWhiteSpace(message)) { errMsg = string.Format("验证码获取失败[{0}]", ex.Message); } else { errMsg = string.Format("验证码获取失败[{0}]{1}", message, ex.Message); } Log4NetImpl.Write(errMsg); SmsClient.ReleaseAPIClient();//释放资源 return(JsonMessage(false, "验证码获取失败")); } #endif } }
public ActionResult Index() { if (!string.IsNullOrEmpty(this.OpenID)) { Funongbao fnb = _funongbaoService.GetFunongbaoByOpenid(this.OpenID); if (fnb != null) { return(new RedirectResult("/funongbao/apply")); } } Funongbao funongbao = new Funongbao(); if (WebHelper.IsPost()) { ViewBag.AuthStatus = 0; TryUpdateModel <Funongbao>(funongbao); int useCount = _mobileCodeService.GetMobileCodeCount(this.MpUserID, 1);//当天使用次数 if (useCount <= 5) { MobileCode lastCode = _mobileCodeService.GetMobileCode(this.MpUserID, 1);//是否存在未使用的证码 if (lastCode != null) { MobileCode checkCode = _mobileCodeService.GetMobileCode(funongbao.MobilePhone, WebHelper.GetString("Code"), this.MpUserID, 1);//检查验证码 if (checkCode != null) { TimeSpan ts = DateTime.Now.Subtract(checkCode.CreateDate).Duration(); if (ts.Minutes > 10) { checkCode.Time += 1; checkCode.Status = 1; _mobileCodeService.Update(lastCode); ViewBag.CodeError = "验证码已经失效,请重新获取!"; } else { Funongbao authFnb = null; int authStatus = _funongbaoService.IdentAuth2(funongbao, out authFnb); if (authStatus == -1) { ViewBag.CodeError = "对不起,该客户已经被绑定了,您无法再次绑定!"; } else { if (authStatus == 1) { //更新用户认证并更新cookie MpUser user = _mpUserservice.GetById(this.MpUserID); user.Name = funongbao.Name; user.PassportNO = funongbao.PassportNO; user.MobilePhone = funongbao.MobilePhone; user.IsAuth = 1; //更新当前验证码失败 checkCode.Status = 1;//已用 //更新福农保信息 authFnb.IsAuth = 1; authFnb.IsSignAgreement = WebHelper.GetInt("IsSignAgreement", 1); authFnb.MpUserId = this.MpUserID; authFnb.OpenId = this.OpenID; try { Log4NetImpl.Write("测试事务写入"); _funongbaoService.BeginTransaction(); _mpUserservice.Update(user); _mobileCodeService.Update(checkCode); _funongbaoService.Update(authFnb); _funongbaoService.Commit(); WriteMpUserCookie(user); Log4NetImpl.Write("测试获取cookie"); var a = MpUserArr; if (!string.IsNullOrEmpty(WebHelper.GetString("refUrl"))) { return(Redirect(WebHelper.GetString("refUrl"))); } else { return(RedirectToAction("index", "funongbao")); } } catch (Exception ex) { _funongbaoService.Rollback(); Log4NetImpl.Write(ex.ToString()); throw new OceanException("对不起,系统异常,身份认证失败!", ex); } } else { ViewBag.AuthStatus = authStatus; } } } } else { lastCode.Time += 1; _mobileCodeService.Update(lastCode); ViewBag.CodeError = "对不起,验证码有误,请检查!"; } } else { ViewBag.CodeError = "对不起,您还未点击发送验证码!"; } } else { ViewBag.CodeError = "对不起,您今天最多只能发起5次验证码"; } } return(View(funongbao)); }