Commit 72dc15b9 authored by 唐峰's avatar 唐峰

验证码校验失败异常改为VerificationCodeErrorException

parent 7ac83d46
package cn.quantgroup.xyqb.exception;
import lombok.Data;
/**
* Created by Miraculous on 15/7/11.
*/
@Data
public class VerificationCodeErrorException extends RuntimeException {
private static final long serialVersionUID = -1L;
private String msg;
private String businessCode;
public VerificationCodeErrorException() {
super("验证码错误");
......@@ -15,4 +20,14 @@ public class VerificationCodeErrorException extends RuntimeException {
super(message);
}
public VerificationCodeErrorException(BizExceptionEnum bizExceptionEnum) {
this.msg = bizExceptionEnum.getMsg();
this.businessCode = bizExceptionEnum.getBusinessCode();
}
public VerificationCodeErrorException(BizExceptionEnum bizExceptionEnum,String attach) {
this.msg = bizExceptionEnum.getMsg()+attach;
this.businessCode = bizExceptionEnum.getBusinessCode();
}
}
......@@ -7,6 +7,7 @@ import cn.quantgroup.xyqb.controller.req.v2.BehaviorReq;
import cn.quantgroup.xyqb.controller.req.v2.ValidateBehavior;
import cn.quantgroup.xyqb.exception.BizException;
import cn.quantgroup.xyqb.exception.BizExceptionEnum;
import cn.quantgroup.xyqb.exception.VerificationCodeErrorException;
import cn.quantgroup.xyqb.model.BehaviorCodeBean;
import cn.quantgroup.xyqb.service.captcha.IQuantgroupCaptchaService;
import cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService;
......@@ -18,6 +19,7 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.imageio.ImageIO;
import javax.xml.bind.ValidationException;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
......@@ -53,7 +55,7 @@ public class QuantGroupBehaviorStrategy implements BehaviorStrategy {
if (result) {
return true;
} else {
throw new BizException(BizExceptionEnum.FAIL_VERIFY_CODE);
throw new VerificationCodeErrorException(BizExceptionEnum.FAIL_VERIFY_CODE);
}
}
......@@ -63,7 +65,7 @@ public class QuantGroupBehaviorStrategy implements BehaviorStrategy {
BehaviorCodeBean behaviorCodeBean = new BehaviorCodeBean();
Map<String, String> challenge = quantgroupCaptchaService.fetchQuantgroupCaptcha(Locale.CHINA);
if (challenge == null) {
throw new BizException(BizExceptionEnum.FAIL_GENERATE_IMAGE);
throw new VerificationCodeErrorException(BizExceptionEnum.FAIL_GENERATE_IMAGE);
}
behaviorCodeBean.setQtCode(BehaviorCodeBean.QtCode.builder().imageData(challenge.get("image")).build());
behaviorCodeBean.setId(challenge.get("imageId"));
......
......@@ -7,6 +7,7 @@ import cn.quantgroup.xyqb.constant.UserConstant;
import cn.quantgroup.xyqb.controller.req.v2.SMSReq;
import cn.quantgroup.xyqb.exception.BizException;
import cn.quantgroup.xyqb.exception.BizExceptionEnum;
import cn.quantgroup.xyqb.exception.VerificationCodeErrorException;
import cn.quantgroup.xyqb.model.SMSCodeBean;
import cn.quantgroup.xyqb.model.session.SessionStruct;
import cn.quantgroup.xyqb.model.sms.SmsMerchant;
......@@ -128,15 +129,15 @@ public class SMSVerificationCodeStrategy implements VerificationCodeStrategy {
}
// 手机号上限检查
if (getPhoneVerificationCount > PHONE_MAX_PER_DAY) {
throw new BizException(BizExceptionEnum.PHONE_MAX_PER_DAY);
throw new VerificationCodeErrorException(BizExceptionEnum.PHONE_MAX_PER_DAY);
}
// 设备号上限检查
if (getDeviceVerificationCount > DEVICE_MAX_PER_DAY) {
throw new BizException(BizExceptionEnum.DEVICE_MAX_PER_DAY);
throw new VerificationCodeErrorException(BizExceptionEnum.DEVICE_MAX_PER_DAY);
}
// IP上限检查
if (!IpUtil.whiteOf(clientIp) && getIPVerificationCount > IP_MAX_PER_DAY) {
throw new BizException(BizExceptionEnum.IP_MAX_PER_DAY);
throw new VerificationCodeErrorException(BizExceptionEnum.IP_MAX_PER_DAY);
}
String key = Constants.REDIS_PREFIX_VERIFICATION_CODE + phoneNo;
......@@ -147,7 +148,7 @@ public class SMSVerificationCodeStrategy implements VerificationCodeStrategy {
long expire = redisTemplate.getExpire(key, TimeUnit.MINUTES);
if (expire >= EXPIRE_MINUTES - 1) {
throw new BizException(BizExceptionEnum.DUPLICATE_MIN);
throw new VerificationCodeErrorException(BizExceptionEnum.DUPLICATE_MIN);
}
String uniqueId = phoneNo + UUID.randomUUID().toString().replaceAll("-", "");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment