基于 captcha 和Spring Boot集成,已经发布到maven中央仓库
<dependency>
<groupId>com.github.aqiu202</groupId>
<artifactId>captcha-spring-boot-starter</artifactId>
<version>0.0.3</version>
</dependency>
项目开源地址:https://github.com/aqiu202/captcha-spring-boot-starter
captcha:
height: 80 #图片高度
width: 200 #图片宽度
has-border: true #设置图片为有边框
noise: #噪化方式先阴影,再添加曲线,再扭曲变形最后添加噪点
styles:
- SHADOW
- LINE
- SHEAR
- POINT
@Validated
@RestController
public class VerifyCodeController {
@Autowired
private CaptchaProducer producer;
/**
* 获取验证码
* @author aqiu
**/
@GetMapping("/verify-code/code")
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String text = this.producer.createText();
req.getSession().setAttribute("CODE", text);
this.producer.writeToResponse(text, resp);
}
}