/// <summary> /// 获取验证码 /// </summary> /// <param name="phone"></param> /// <returns></returns> public IActionResult GetSmsCode(string phone) { if (!Regex.IsMatch(phone, @"^1\d{10}$")) { return(JsonError("手机格式不正确")); } var model = _smsCodeInfoRepository.FindBy(e => e.IsUse == false && e.Phone == phone).FirstOrDefault(); //成本考虑,如果验证码未过期,不重新发送验证码 if (model != null && DateTime.Now < model.ExpirationTime) { return(JsonError("验证码已发送")); } var code = RandomHelper.GenerateRandomCode(6); //TODO:调用阿里接口发送短信 model = new SmsCodeInfo() { Code = code, CreateTime = DateTime.Now, ExpirationTime = DateTime.Now.AddMinutes(10), IsUse = false, Phone = phone, Type = 1 }; _smsCodeInfoRepository.Add(model); return(JsonOk("发送成功")); }
/// <summary> /// 注册 /// </summary> /// <returns></returns> private async Task <AccountUsers> Register(AccountUsers user) { //注册一个用户 string cellphone = user.CellPhone; //RegisterSuccessInfo responseRegisterSuccessInfo = new RegisterSuccessInfo { IsSuccess = false }; //发送验证码 并且验证该手机号是否存在 //发送验证码 SmsCodeInfo smsCodeInfo = await this.jymService.GetSmsCodeInfo(new SendVeriCodeRequest { Cellphone = cellphone }); //验证 if (await this.jymService.VerifyCellPhone(new VerifyRequest { Cellphone = cellphone, Code = smsCodeInfo.Code.Split('|')[0], Type = 10 })) { //成功后注册 RegisterInfo info = new RegisterInfo { Token = smsCodeInfo.Token, InviteBy = user.InviteBy, ContractId = "300020150820103000", Password = user.Pwd }; if (await this.jymService.Register(info)) { //认证 string realName = user.RealName; string credentialNo = user.CredentialNo; IdentityAuthenticationResponse registerSuccess = await this.jymService.IdentityAuthentication(new IdentityAuthenticationRequest { Credential = "10", CredentialNo = credentialNo, RealName = realName }, cellphone, user.Pwd); if (registerSuccess.IsSuccess) { user.UserIdentifier = registerSuccess.UserIdentifier; user.IsVerifed = 1; //将数据存入数据库中 bool addSuccess = SqlHelper.ExecuteNoneQuery($"insert into AccountUsers(BankCardNo,CellPhone,CgCellPhone,CredentialNo,InviteBy,InviteFor,IsActivity,IsAuthInvest,IsAuthWithdraw,IsVerifed,Pwd,RealName,RechargeAmount,RechargeNums,RigisterTime,UserIdentifier,UserMac,IsBankAuth)values('{user.BankCardNo}','{user.CellPhone}','{user.CgCellPhone}','{user.CredentialNo}','{user.InviteBy}','{user.InviteFor}',{user.IsActivity},{user.IsAuthInvest},{user.IsAuthWithdraw},{user.IsVerifed},'{user.Pwd}','{user.RealName}',{user.RechargeAmount},{user.RechargeNums},'{user.RigisterTime}','{user.UserIdentifier}','{user.UserMac}',0)") > 0; if (addSuccess) { return(user); } } return(null); } } return(null); }