图片验证码获取
@Value("${file_server_url}")//图片服务器地址
String file_server_url;
@GetMapping("/getCode")
public Map send(){
CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(200, 100, 4, 20); //获取验证码获取
String code = captcha.getCode();
String imageBase64 = captcha.getImageBase64();
Map<String, String> map = new HashMap<>();
redisTemplate.opsForValue().set("captcha", captcha.getCode());
map.put("code",code);
map.put("imageBase64","data:image/png;base64,"+imageBase64);
return map;
}
验证
String code = (String) redisTemplate.opsForValue().get("captcha");
System.out.println(code);
if(null==code){
return new Result(false,StatusCode.ERROR,"验证码过期");
}
if(!code.equals(sysUser.getCode())){
return new Result(false,StatusCode.ERROR,"验证码错误");
}