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)); } }