生成验证码
public class VerificationCodeUtil {
public static VerificationCode getVerification() {
LineCaptcha captcha = CaptchaUtil.createLineCaptcha(70, 35, 4, 30);
String key = IdUtil.get32Uuid();
VerificationCode verificationCode= new VerificationCode();
verificationCode.setCode(captcha.getCode());
verificationCode.setKey(key);
verificationCode.setBase64Img(captcha.getImageBase64());
return verificationCode;
}
}
存储验证码的key到redis 将图片的base64返给前端
@ApiOperation(value = "获取验证码", notes = "获取验证码")
@GetMapping("/getVerificationCode")
public CommonResult getVerificationCode() {
VerificationCode verificationCode = VerificationCodeUtil.getVerification();
redisService.set(RedisKeyConstant.VERIFICATIONCODE_KEY + ":" + verificationCode.getKey(), verificationCode.getCode(), 60);
verificationCode.setCode(null);
return CommonResult.success(verificationCode);
}