easy-captcha介绍
easy-captcha,提供了Java图形验证码,支持gif、中文、算术等类型,可用于Java Web、JavaSE等项目,是个很好用的工具库,文档比较完备。
用法
添加maven依赖
<!--图形验证码-->
<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>easy-captcha</artifactId>
<version>1.6.2</version>
</dependency>
前后端分离时,返回图形验证码的key和图片的base64;
import com.wf.captcha.SpecCaptcha;
/**
* 获取图形验证码
*
* @return
*/
@RequestMapping(value = "/getCaptcha", method = RequestMethod.GET)
public Response getCaptcha() {
final int width = 111;
final int height = 36;
String