/// <summary> /// 添加实体对象,返回插入成功后的实体对象主键ID /// </summary> public int Insert(CaptchaRecord captchaRecord) { const string sql = @"INSERT INTO CaptchaRecord(IP, CodeType, Phone, Code, SendTime) VALUES(@IP, @CodeType, @Phone, @Code, @SendTime); SELECT LAST_INSERT_ID();"; int id = 0; using (DbConnection connection = ConnectionManager.OpenConnection) { id = connection.Query<int>(sql, captchaRecord).SingleOrDefault<int>(); } return id; }
/// <summary> /// 发送找回密码短信验证码(机构管理员),并记录此次用户的IP地址 /// </summary> public ServiceInvokeDTO SendGetPasswordCaptcha(string phone, string ip) { log.Debug(Constant.DEBUG_START); ServiceInvokeDTO result = null; try { if (RegExpUtil.IsMobile(phone)) { // 1. 检测是否已注册 AgencyAdmin dbAdmin = adminDAL.GetByPhone(phone); if (dbAdmin != null) { // 2. 检测IP限制 CaptchaRecord dbCaptcha = captchaRecordDAL.GetCode(CaptchaCodeType.GetPwdCode, ip, phone, Config.CaptchaGetTimeSpan); if (dbCaptcha == null) { string code = GenerateCode(); // result = InvokeYPToSendSms(phone, code, CaptchaCodeType.GetPwdCode); result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS); if (result != null && result.Code == InvokeCode.SYS_INVOKE_SUCCESS) { CaptchaRecord captchaRecord = new CaptchaRecord(); captchaRecord.CodeType = CaptchaCodeType.GetPwdCode; captchaRecord.IP = ip; captchaRecord.Phone = phone; captchaRecord.Code = code; captchaRecord.SendTime = DateTime.Now; captchaRecordDAL.Insert(captchaRecord); } } else { result = new ServiceInvokeDTO(InvokeCode.SMS_CAPTCHA_IP_LIMIT); } } else { result = new ServiceInvokeDTO(InvokeCode.SMS_USER_NOT_EXIST_WHEN_GET_PWD); } } else { result = new ServiceInvokeDTO(InvokeCode.SYS_ARG_ERROR); } } catch (Exception ex) { log.Error(ex); throw ex; } log.Debug(Constant.DEBUG_END); return result; }