|
@@ -2,6 +2,10 @@ package org.jetlinks.community.auth.captcha;
|
|
|
|
|
|
import com.wf.captcha.SpecCaptcha;
|
|
|
import com.wf.captcha.base.Captcha;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
+import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.Getter;
|
|
|
import lombok.NoArgsConstructor;
|
|
@@ -23,6 +27,7 @@ import java.util.UUID;
|
|
|
@Authorize(ignore = true)
|
|
|
@AllArgsConstructor
|
|
|
@RequestMapping("/authorize/captcha")
|
|
|
+@Tag(name = "验证码接口")
|
|
|
public class CaptchaController {
|
|
|
|
|
|
private final CaptchaProperties properties;
|
|
@@ -30,20 +35,24 @@ public class CaptchaController {
|
|
|
private final ReactiveRedisOperations<String, String> redis;
|
|
|
|
|
|
@GetMapping("/config")
|
|
|
- public Mono<CaptchaConfig> getCaptcha() {
|
|
|
- CaptchaConfig captchaConfig=new CaptchaConfig();
|
|
|
+ @Operation(summary = "获取验证码相关配置信息")
|
|
|
+ public Mono<CaptchaConfig> createCaptcha() {
|
|
|
+ CaptchaConfig captchaConfig = new CaptchaConfig();
|
|
|
captchaConfig.setEnabled(properties.isEnabled());
|
|
|
captchaConfig.setType(properties.getType().name());
|
|
|
return Mono.just(captchaConfig);
|
|
|
}
|
|
|
|
|
|
@GetMapping("/image")
|
|
|
- public Mono<CaptchaInfo> createCaptcha(@RequestParam(defaultValue = "130") int width,
|
|
|
- @RequestParam(defaultValue = "40") int height) {
|
|
|
+ @Operation(summary = "获取验证码图片")
|
|
|
+ public Mono<CaptchaInfo> createCaptcha(@RequestParam(defaultValue = "130")
|
|
|
+ @Parameter(description = "宽度,默认130px") int width,
|
|
|
+ @RequestParam(defaultValue = "40")
|
|
|
+ @Parameter(description = "高度,默认40px") int height) {
|
|
|
if (!properties.isEnabled()) {
|
|
|
return Mono.empty();
|
|
|
}
|
|
|
- SpecCaptcha captcha = new SpecCaptcha(width, height, 5);
|
|
|
+ SpecCaptcha captcha = new SpecCaptcha(width, height, 4);
|
|
|
captcha.setCharType(Captcha.TYPE_DEFAULT);
|
|
|
|
|
|
String base64 = captcha.toBase64();
|
|
@@ -82,8 +91,10 @@ public class CaptchaController {
|
|
|
@AllArgsConstructor
|
|
|
@NoArgsConstructor
|
|
|
public static class CaptchaInfo {
|
|
|
+ @Schema(description = "验证码标识,登录时需要在参数[verifyKey]传入此值.")
|
|
|
private String key;
|
|
|
|
|
|
+ @Schema(description = "图片Base64,以data:image/png;base64,开头")
|
|
|
private String base64;
|
|
|
}
|
|
|
|
|
@@ -91,9 +102,11 @@ public class CaptchaController {
|
|
|
@Setter
|
|
|
@AllArgsConstructor
|
|
|
@NoArgsConstructor
|
|
|
- public static class CaptchaConfig{
|
|
|
+ public static class CaptchaConfig {
|
|
|
+ @Schema(description = "是否开启验证码")
|
|
|
private boolean enabled;
|
|
|
|
|
|
+ @Schema(description = "验证码类型")
|
|
|
private String type;
|
|
|
}
|
|
|
}
|