/// <summary> /// 将验证码保存到数据库 /// </summary> /// <param name="smsRecord"></param> /// <returns></returns> public bool SaveSmsCode(SmsRecord smsRecord) { var result = helper.Execute($@"insert into SmsRecord values ({smsRecord.UserId},'{smsRecord.Phone}','{smsRecord.Code}','{DateTime.Now}',{1})"); return(result > 0 ? true : false); }
public virtual void Log(SmsRecord record) { if (null == record) { throw new ArgumentNullException(nameof(record)); } _repository.Insert(record); }
public ResponseResultDto <string> GetRegisterSmsCode(string phone) { bool isSussess = false; string errorMessage = string.Empty; string smsCode = string.Empty; if (Util.ValidateMobilePhone(phone))//手机号格式是否正确 { if (userRepository.PhoneIsExist(phone)) { isSussess = false; errorMessage = "手机号已经存在,无法注册"; } else { //是正确的手机号格式,获取验证码,同时将手机号等注册信息存储到数据库 var temp = SmsSingleSenderHelper.SendSms(phone); if (temp.Item3 != 0) { return(new ResponseResultDto <string> { IsSuccess = false, ErrorMessage = temp.Item2, Result = string.Empty }); } smsCode = temp.Item1; //errorMessage = temp.Item2; isSussess = true; SmsRecord sms = new SmsRecord { UserId = -1, Phone = phone, Code = smsCode, }; userRepository.SaveSmsCode(sms); } } else { errorMessage = "手机号格式不正确"; } return(new ResponseResultDto <string> { IsSuccess = isSussess, ErrorMessage = errorMessage, Result = smsCode }); }
/// <summary> /// 新增短信发送记录 /// </summary> /// <param name="phone"></param> /// <param name="code"></param> /// <param name="ipAddress"></param> /// <param name="state"></param> /// <param name="createManageId"></param> /// <param name="userId"></param> /// <returns></returns> public bool CreateSmsRecord(string phone, string code, int state, int createManageId = 0, int userId = 0, string ipAddress = "") { phone = phone.UrlDecode(); code = code.UrlDecode(); ipAddress = string.IsNullOrWhiteSpace(ipAddress) ? "" : ipAddress.UrlDecode(); CheckPhoneNotNull(phone); CheckCodeNotNull(code); var smsRecord = new SmsRecord { UserId = userId, Mobile = phone, Content = code, SendTime = DateTime.Now, State = state, IpAddress = ipAddress, CreateManageId = createManageId, CreateTime = DateTime.Now }; return(_smsRecordRepository.CreateEntity(smsRecord)); }
public void setRecord(string uid, string number) { this.Record = new SmsRecord(); switch (this.TemplateId) { case 30742: this.Record.Cate = SmsCate.购买课程; break; case 30741: this.Record.Cate = SmsCate.注册账户; break; case 30582: this.Record.Cate = SmsCate.修改密码; break; case 30771: this.Record.Cate = SmsCate.监督学习; break; case 30772: this.Record.Cate = SmsCate.忘记密码; break; case 30773: this.Record.Cate = SmsCate.绑定手机; break; case 30774: this.Record.Cate = SmsCate.充值学币; break; } this.Record.SendTime = DateTime.UtcNow; this.Record.UserID = uid; this.Record.Number = number; }
/// <summary> /// 添加短信记录 /// </summary> private HttpResponseMessage AddSmsRecord(HttpRequestMessage request) { log.Debug(Constant.DEBUG_START); string sign = ApiQueryUtil.QueryHeader(Constant.HTTP_HEADER_SIGN); string cmd = ApiQueryUtil.QueryHeader(Constant.HTTP_HEADER_CMD); string random = ApiQueryUtil.QueryHeader(Constant.HTTP_HEADER_RANDOM); string userIDString = ApiQueryUtil.QueryArgByPost("user_id"); string receiverPhone = ApiQueryUtil.QueryArgByPost("receiver_phone"); string receiverName = ApiQueryUtil.QueryArgByPost("receiver_name"); string content = ApiQueryUtil.QueryArgByPost("content"); string sendByTypeString = ApiQueryUtil.QueryArgByPost("sendby_type"); string sendTimeString = ApiQueryUtil.QueryArgByPost("send_time"); Dictionary<string, string> args = new Dictionary<string, string>() { { Constant.HTTP_HEADER_CMD, cmd }, { Constant.HTTP_HEADER_RANDOM, random }, { "user_id", userIDString }, { "receiver_phone", receiverPhone }, { "receiver_name", receiverName }, { "content", content }, { "sendby_type", sendByTypeString }, { "send_time", sendTimeString } }.OrderBy(element => element.Key).ToDictionary(o => o.Key, p => p.Value); ServiceInvokeDTO<SmsRecord> result = null; try { // Check sign if (securityService.CheckSign(args, Config.ApiSignSecretKey, sign)) { SmsRecord smsRecord = new SmsRecord(); smsRecord.UserID = Convert.ToInt32(userIDString); smsRecord.ReceiverPhone = receiverPhone; smsRecord.ReceiverName = receiverName; smsRecord.Content = content; smsRecord.SendByType = Convert.ToInt32(sendByTypeString); smsRecord.SendTime = Convert.ToDateTime(sendTimeString); result = userDataService.AddSmsRecord(smsRecord); } else { result = new ServiceInvokeDTO<SmsRecord>(InvokeCode.SYS_SIGN_ERROR); } } catch (Exception ex) { log.Error(ex); result = new ServiceInvokeDTO<SmsRecord>(InvokeCode.SYS_INNER_ERROR); } log.Debug(Constant.DEBUG_END); return request.CreateResponse(HttpStatusCode.OK, result); }
public bool DeleteEntity(SmsRecord entity) { return(base.DeleteEntity <SmsRecord>(entity)); }
public bool UpdateEntity(SmsRecord entity) { return(base.UpdateEntity <SmsRecord>(entity)); }
public bool CreateEntity(SmsRecord entity) { return(base.CreateEntity <SmsRecord>(entity)); }