Commit e70f0f54 authored by 唐峰's avatar 唐峰

Merge branch 'feature-migration-20230628-v1' into feature-migration-20230628

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