feat(auth): 优化图形验证码生成逻辑,新增自定义颜色支持

(cherry picked from commit af900df10d6e9df4b9812332f126c2e96474722e)
This commit is contained in:
PIGCLOUD committed 2026-09-22 21:43:38 +08:00
1 parent 4023b142d1
commit d46af13a2e
1 file changed
+12 -1
@@ -18,6 +18,8 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.awt.Color;
/**
* 验证码相关的接口
*
@@ -39,7 +41,7 @@ public class ImageCodeEndpoint {
@SneakyThrows
@GetMapping("/image")
public void image(String randomStr, HttpServletResponse response) {
ArithmeticCaptcha captcha = new ArithmeticCaptcha(DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT);
ArithmeticCaptcha captcha = createCaptcha();
String result = captcha.text();
@@ -53,6 +55,15 @@ public class ImageCodeEndpoint {
captcha.out(response.getOutputStream());
}
static ArithmeticCaptcha createCaptcha() {
return new ArithmeticCaptcha(DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT) {
@Override
protected Color color() {
return Color.BLACK;
}
};
}
/**
* 行为 创建滑块图形验证码
*/