Appearance
Captcha验证码使用
引用
首先在项目中引用EasyCaptchaService
java
public class CaptchaController {
...
@Resource
private EasyCaptchaService captchaService;
...
}
1
2
3
4
5
6
2
3
4
5
6
生成验证码
java
@PostMapping("/get")
@Operation(summary = "生成验证码")
public BaseResponse<CaptchaResult> captcha() {
return captchaService.generateCaptcha();
}
1
2
3
4
5
2
3
4
5
校验验证码
java
@PostMapping("/check")
@Operation(summary = "校验验证码")
public BaseResponse<String> verifyCaptcha(@RequestBody CaptchaCheck CaptchaCheck){
String verifyCode = CaptchaCheck.getVerifyCode();
String verifyCodeKey = CaptchaCheck.getVerifyCodeKey();
return captchaService.verifyCaptcha(verifyCode, verifyCodeKey);
}
1
2
3
4
5
6
7
2
3
4
5
6
7
完整代码
java
@RestController
@Slf4j
@RequestMapping("/captcha")
public class CaptchaController {
@Resource
private EasyCaptchaService captchaService;
@PostMapping("/get")
@Operation(summary = "生成验证码")
public BaseResponse<CaptchaResult> captcha() {
return captchaService.generateCaptcha();
}
@PostMapping("/check")
@Operation(summary = "校验验证码")
public BaseResponse<String> verifyCaptcha(@RequestBody CaptchaCheck CaptchaCheck) {
String verifyCode = CaptchaCheck.getVerifyCode();
String verifyCodeKey = CaptchaCheck.getVerifyCodeKey();
return captchaService.verifyCaptcha(verifyCode, verifyCodeKey);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23