コード例 #1
0
        public CaptchaHelperModel SendAuthCode(CaptchaEnum captchaEnum, int accId, CaptchaPhoneEmailEnum typeEnum,
                                               string phoneOrEmail)
        {
            var redisCacheService = new RedisCacheService();

            if (string.IsNullOrWhiteSpace(phoneOrEmail))
            {
                throw new ArgumentNullException("phoneOrEmail", "手机号码邮箱地址为空");
            }


            //获取失败次数
            var strWrongTimesKey = GetWrongTimesKey(captchaEnum, accId);



            int iWrongTimes = redisCacheService.Get <int>(strWrongTimesKey);

            //判断验证码错误次数
            if (iWrongTimes > _checkWrongTimes)
            {
                return(new CaptchaHelperModel(false, "验证码错误次数过多,请1小时后重试或联系客服", typeEnum));
            }

            //获取验证码key
            var strCaptchaKey = GetCaptchaKey(captchaEnum, accId, phoneOrEmail);

            if (string.IsNullOrEmpty(strCaptchaKey))
            {
                return(new CaptchaHelperModel(false, "错误的手机号或邮箱", typeEnum));
            }


            //判断是否之前发过验证码
            int iCaptcha = redisCacheService.Get <int>(strCaptchaKey);

            if (iCaptcha == 0)
            {
                iCaptcha = Helper.GetInt32(Helper.GetRandomNum(), 111111);
            }

            var smsStr = string.Format("【生意专家】您本次获取的验证码为:{0},此验证码{1}分钟内有效。维护您的数据安全是生意专家义不容辞的责任。", iCaptcha,
                                       _outTimeMinutes);
            var mailSend = new EmailSend();
            var smsSend  = new SmsSend();
            var result   = typeEnum == CaptchaPhoneEmailEnum.Phone
                ? smsSend.SendSys(phoneOrEmail, smsStr, 13)
                : mailSend.SendVerifiEmail(accId, "", phoneOrEmail, iCaptcha.ToString());

            if (result)
            {
                _logger.Debug("发送验证码成功:" + iCaptcha);
                redisCacheService.Set(strCaptchaKey, iCaptcha, _outTimeMinutes * 60);
                return(new CaptchaHelperModel(true, "发送验证码成功", CaptchaPhoneEmailEnum.Email));
            }
            else
            {
                return(new CaptchaHelperModel(false, "发送失败", CaptchaPhoneEmailEnum.Email));
            }
        }
コード例 #2
0
        public CaptchaHelperModel CheckCaptchaCode(CaptchaEnum captchaEnum, int accId, CaptchaPhoneEmailEnum typeEnum,
                                                   int captchaCode, string phoneOrEmail)
        {
            var redisCacheService = new RedisCacheService();
            CaptchaHelperModel model;

            //获取失败次数
            var strWrongTimesKey = GetWrongTimesKey(captchaEnum, accId);
            int iWrongTimes      = redisCacheService.Get <int>(strWrongTimesKey);

            //判断验证码错误次数
            if (iWrongTimes > 10)
            {
                return(new CaptchaHelperModel(false, "验证码错误次数过多,请1小时后重试或联系客服", typeEnum));
            }

            //获取验证码key
            string strCaptchaKey = GetCaptchaKey(captchaEnum, accId, phoneOrEmail);

            if (string.IsNullOrWhiteSpace(strCaptchaKey))
            {
                return(new CaptchaHelperModel(false, "验证码校验失败", typeEnum));
            }

            //获取发过的验证码
            int iCaptcha = redisCacheService.Get <int>(strCaptchaKey);

            if (iCaptcha == captchaCode)
            {
                _logger.Debug("验证验证码成功:" + iCaptcha);
                redisCacheService.RemoveKey(strWrongTimesKey);
                redisCacheService.RemoveKey(strCaptchaKey);
                return(new CaptchaHelperModel(true, "验证码校验成功", typeEnum));
            }
            else if (iCaptcha == 0)
            {
                _logger.Debug("验证验证码失败:" + captchaCode);
                return(new CaptchaHelperModel(false, "验证码过期,请重新申请发送验证码", typeEnum));
            }
            else
            {
                //失败添加失败次数
                redisCacheService.Set(strWrongTimesKey, iWrongTimes + 1, 60 * 60);
                return(new CaptchaHelperModel(false, "验证码校验失败", typeEnum));
            }
        }
コード例 #3
0
 public ResponseModel SendVerificationCode(UserContext userContext, int context, CaptchaPhoneEmailEnum typeEnum, string phoneOrEmail)
 {
     return(new ResponseModel());
 }
コード例 #4
0
 public CaptchaHelperModel(bool isSuccess, string errMessage, CaptchaPhoneEmailEnum typeenum)
 {
     IsSuccess  = isSuccess;
     ErrMessage = errMessage;
     Type       = typeenum.ToString();
 }
コード例 #5
0
 public CaptchaHelperModel SendAuthCode(CaptchaEnum captchaEnum, int accId, CaptchaPhoneEmailEnum typeEnum, string phoneOrEmail)
 {
     return(new CaptchaHelperModel(true, string.Empty, typeEnum));
 }
コード例 #6
0
 public CaptchaHelperModel CheckCaptchaCode(CaptchaEnum captchaEnum, int accId, CaptchaPhoneEmailEnum typeEnum,
                                            int captchaCode, string phone)
 {
     return(new CaptchaHelperModel(true, String.Empty, typeEnum));
 }
コード例 #7
0
        /// <summary>
        ///  发送验证码
        /// </summary>
        /// <returns></returns>
        public ResponseModel SendVerificationCode(UserContext userContext, int context, CaptchaPhoneEmailEnum typeEnum,
                                                  string phoneOrEmail)
        {
            var result = _authCodeService.SendAuthCode((CaptchaEnum)context, userContext.AccId, typeEnum, phoneOrEmail);

            return(new ResponseModel
            {
                Code = result.IsSuccess ? (int)ErrorCodeEnum.Success : (int)ErrorCodeEnum.Failed,
                Message = result.ErrMessage
            });
        }