[feat] 根据验证码类型生成验证码(新增数字)

This commit is contained in:
hsdllcw
2024-08-06 16:19:32 +08:00
parent 3c804db4f0
commit e700a7dca0

View File

@@ -34,6 +34,9 @@ public class ValidateCodeServiceImpl implements ValidateCodeService
@Resource(name = "captchaProducerMath") @Resource(name = "captchaProducerMath")
private Producer captchaProducerMath; private Producer captchaProducerMath;
@Resource(name = "captchaProducerNumber")
private Producer captchaProducerNumber;
@Autowired @Autowired
private RedisService redisService; private RedisService redisService;
@@ -63,17 +66,24 @@ public class ValidateCodeServiceImpl implements ValidateCodeService
String captchaType = captchaProperties.getType(); String captchaType = captchaProperties.getType();
// 生成验证码 // 生成验证码
if ("math".equals(captchaType)) switch (captchaType) {
{ case "number": {
String capText = captchaProducerMath.createText(); capStr = code = captchaProducerNumber.createText();
capStr = capText.substring(0, capText.lastIndexOf("@")); image = captchaProducerNumber.createImage(capStr);
code = capText.substring(capText.lastIndexOf("@") + 1); }
image = captchaProducerMath.createImage(capStr); break;
} case "math": {
else if ("char".equals(captchaType)) String capText = captchaProducerMath.createText();
{ capStr = capText.substring(0, capText.lastIndexOf("@"));
capStr = code = captchaProducer.createText(); code = capText.substring(capText.lastIndexOf("@") + 1);
image = captchaProducer.createImage(capStr); image = captchaProducerMath.createImage(capStr);
}
break;
default: {
capStr = code = captchaProducer.createText();
image = captchaProducer.createImage(capStr);
}
break;
} }
redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);