代码拉取完成,页面将自动刷新
同步操作将从 baomidou/kaptcha-spring-boot-starter 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
简单快速集成 Google Kaptcha验证码
QQ群:710314529
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>kaptcha-spring-boot-starter</artifactId>
<version>${version}</version>
</dependency>
Kaptcha
。@RestController
@RequestMapping("/kaptcha")
public class KaptchaController {
@Autowired
private Kaptcha kaptcha;
@GetMapping("/render")
public void render() {
kaptcha.render();
}
@PostMapping("/valid")
public void validDefaultTime(@RequestParam String code) {
//default timeout 900 seconds
kaptcha.validate(code);
}
@PostMapping("/validTime")
public void validCustomTime(@RequestParam String code) {
kaptcha.validate(code, 60);
}
}
KaptchaException //super Exception
KaptchaIncorrectException
KaptchaNotFoundException
KaptchaTimeoutException
KaptchaRenderException //If something is wrong then Image.write when render.
import com.baomidou.kaptcha.exception.KaptchaException;
import com.baomidou.kaptcha.exception.KaptchaIncorrectException;
import com.baomidou.kaptcha.exception.KaptchaNotFoundException;
import com.baomidou.kaptcha.exception.KaptchaTimeoutException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(value = KaptchaException.class)
public String kaptchaExceptionHandler(KaptchaException kaptchaException) {
if (kaptchaException instanceof KaptchaIncorrectException) {
return "验证码不正确";
} else if (kaptchaException instanceof KaptchaNotFoundException) {
return "验证码未找到";
} else if (kaptchaException instanceof KaptchaTimeoutException) {
return "验证码过期";
} else {
return "验证码渲染失败";
}
}
}
kaptcha:
height: 50
width: 200
content:
length: 4
source: abcdefghjklmnopqrstuvwxyz23456789
space: 2
font:
color: black
name: Arial
size: 40
background-color:
from: lightGray
to: white
border:
enabled: true
color: black
thickness: 1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。