From 163d37763c54d774dd4086758f58a594b80fef9a Mon Sep 17 00:00:00 2001 From: liuchen864 <23082234@qq.com> Date: Wed, 27 Sep 2023 17:34:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E9=99=86=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../captcha/config/KaptchaTextCreator.java | 56 +++++++++++++++++++ .../config/WinCaptchaConfiguration.java | 2 +- .../WinWebSecurityConfigurerAdapter.java | 2 +- .../admin/captcha/CaptchaController.java | 4 +- .../src/main/resources/application.yaml | 3 - 5 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/KaptchaTextCreator.java diff --git a/win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/KaptchaTextCreator.java b/win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/KaptchaTextCreator.java new file mode 100644 index 00000000..38c424be --- /dev/null +++ b/win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/KaptchaTextCreator.java @@ -0,0 +1,56 @@ +package com.win.framework.captcha.config; + +import com.google.code.kaptcha.text.impl.DefaultTextCreator; + +import java.util.Random; + +/** + * 验证码文本生成器 + * + * @author win + */ +public class KaptchaTextCreator extends DefaultTextCreator { + private static final String[] CNUMBERS = "0,1,2,3,4,5,6,7,8,9,10".split(","); + + @Override + public String getText() { + Integer result = 0; + Random random = new Random(); + int x = random.nextInt(10); + int y = random.nextInt(10); + StringBuilder suChinese = new StringBuilder(); + int randomoperands = random.nextInt(3); + if (randomoperands == 0) { + result = x * y; + suChinese.append(CNUMBERS[x]); + suChinese.append("*"); + suChinese.append(CNUMBERS[y]); + } else if (randomoperands == 1) { + if ((x != 0) && y % x == 0) { + result = y / x; + suChinese.append(CNUMBERS[y]); + suChinese.append("/"); + suChinese.append(CNUMBERS[x]); + } else { + result = x + y; + suChinese.append(CNUMBERS[x]); + suChinese.append("+"); + suChinese.append(CNUMBERS[y]); + } + } else { + if (x >= y) { + result = x - y; + suChinese.append(CNUMBERS[x]); + suChinese.append("-"); + suChinese.append(CNUMBERS[y]); + } else { + result = y - x; + suChinese.append(CNUMBERS[y]); + suChinese.append("-"); + suChinese.append(CNUMBERS[x]); + } + } + suChinese.append("=?@" + result); + return suChinese.toString(); + } +} \ No newline at end of file diff --git a/win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/WinCaptchaConfiguration.java b/win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/WinCaptchaConfiguration.java index cdc01096..43121952 100644 --- a/win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/WinCaptchaConfiguration.java +++ b/win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/WinCaptchaConfiguration.java @@ -57,7 +57,7 @@ public class WinCaptchaConfiguration { // KAPTCHA_SESSION_KEY properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath"); // 验证码文本生成器 - properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.win.tms.framework.config.KaptchaTextCreator"); + properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.win.framework.captcha.config.KaptchaTextCreator"); // 验证码文本字符间距 默认为2 properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3"); // 验证码文本字符长度 默认为5 diff --git a/win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/config/WinWebSecurityConfigurerAdapter.java b/win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/config/WinWebSecurityConfigurerAdapter.java index 0a31be24..0b61db62 100644 --- a/win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/config/WinWebSecurityConfigurerAdapter.java +++ b/win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/config/WinWebSecurityConfigurerAdapter.java @@ -128,7 +128,7 @@ public class WinWebSecurityConfigurerAdapter { // 1.4 设置 App API 无需认证 .antMatchers(buildAppApi("/**")).permitAll() // 1.5 验证码captcha 允许匿名访问 - .antMatchers("/captcha/get", "/captcha/check").permitAll() + .antMatchers("/captcha/captchaImage").permitAll() // 1.6 webSocket 允许匿名访问 .antMatchers("/websocket/message").permitAll() // ②:每个项目的自定义规则 diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/captcha/CaptchaController.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/captcha/CaptchaController.java index c476b7aa..9bdf8eac 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/captcha/CaptchaController.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/captcha/CaptchaController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import javax.annotation.security.PermitAll; import javax.imageio.ImageIO; import javax.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; @@ -30,7 +31,7 @@ import static com.win.framework.common.pojo.CommonResult.success; * * @author win */ -@RestController("adminCaptchaController") +@RestController @RequestMapping("/system/captcha") public class CaptchaController { @Resource(name = "captchaProducer") @@ -45,6 +46,7 @@ public class CaptchaController { /** * 生成验证码 */ + @PermitAll @GetMapping("/captchaImage") public CommonResult getCode(HttpServletResponse response) throws IOException { Map data = new HashMap<>(); diff --git a/win-server/src/main/resources/application.yaml b/win-server/src/main/resources/application.yaml index 27b28132..3fe7da65 100644 --- a/win-server/src/main/resources/application.yaml +++ b/win-server/src/main/resources/application.yaml @@ -142,10 +142,7 @@ win: - /admin-api/system/tenant/get-id-by-name # 基于名字获取租户,不许带租户编号 - /admin-api/system/captcha/captchaImage # 校验图片验证码,和租户无关 - /admin-api/infra/file/*/get/** # 获取图片,和租户无关 - - /admin-api/system/sms/callback/* # 短信回调接口,无法带上租户编号 - - /admin-api/pay/notify/** # 支付回调通知,不携带租户编号 - /jmreport/* # 积木报表,无法携带租户编号 - - /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,无法携带租户编号 ignore-tables: - system_tenant - system_tenant_package