easy-captcha 图片验证码
使用
1、导入依赖
在maven仓库中查找,发现只有这个依赖,所以直接复制这个即可
com.github.whvcse easy-captcha1.6.2
2、使用
总共有这么多种验证类型
3、测试
public static void main(String[] args) {
ArithmeticCaptcha arithmeticCaptcha = new ArithmeticCaptcha(138, 48);
//定义几位数的运算,默认是2位数
arithmeticCaptcha.setLen(3);
//获取算数式
String arithmeticString = arithmeticCaptcha.getArithmeticString();
//获取返回结果
String result = arithmeticCaptcha.text();
//返回图片格式
String imageUrl = arithmeticCaptcha.tobase64();
System.out.println("arithmeticString:"+arithmeticString);
System.out.println("text:"+result);
System.out.println("图片:"+imageUrl);
ChineseCaptcha chineseCaptcha = new ChineseCaptcha();
String chineseRes = chineseCaptcha.text();
String chineseUrl = chineseCaptcha.tobase64();
System.out.println("chineseRes:"+chineseRes);
System.out.println("chineseUrl:"+chineseUrl);
}
返回结果:
//算数验证码返回结果
arithmeticString:3x6+5=?
text:23
图片:data:image/png;base64 …
//中文返回结果
chineseRes:个动来紧
chineseUrl:data:image/png;base64 …
4、最佳实践
可以结合redis,使用uuid作为key,结果作为value存储起来
@GetMapping(value = "/code") public ResponseEntity



