From 8a11a020e04e271da7b700b5d73cf8475b50ee5c Mon Sep 17 00:00:00 2001 From: Charles7c Date: Fri, 24 Nov 2023 23:45:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=80=82=E9=85=8D=20ContiNew=20Sta?= =?UTF-8?q?rter=20=E5=9B=BE=E5=BD=A2=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- continew-admin-common/pom.xml | 16 +-- .../mybatis/MybatisPlusConfiguration.java | 10 -- .../config/properties/CaptchaProperties.java | 105 +----------------- .../controller/common/CaptchaController.java | 9 +- .../main/resources/config/application-dev.yml | 9 +- .../resources/config/application-prod.yml | 9 +- pom.xml | 16 --- 7 files changed, 22 insertions(+), 152 deletions(-) diff --git a/continew-admin-common/pom.xml b/continew-admin-common/pom.xml index 81a2aafb9..dcaea4ce7 100644 --- a/continew-admin-common/pom.xml +++ b/continew-admin-common/pom.xml @@ -29,10 +29,10 @@ continew-starter-cache-redisson - + top.charles7c.continew - continew-starter-json-jackson + continew-starter-captcha-graphic @@ -41,6 +41,12 @@ continew-starter-api-doc + + + top.charles7c.continew + continew-starter-json-jackson + + @@ -106,11 +112,5 @@ net.dreamlu mica-ip2region - - - - com.github.whvcse - easy-captcha - \ No newline at end of file diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/config/mybatis/MybatisPlusConfiguration.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/config/mybatis/MybatisPlusConfiguration.java index 3fbf1ca1e..fa452dd67 100644 --- a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/config/mybatis/MybatisPlusConfiguration.java +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/config/mybatis/MybatisPlusConfiguration.java @@ -16,20 +16,10 @@ package top.charles7c.cnadmin.common.config.mybatis; -import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; -import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator; -import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator; -import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; - -import cn.hutool.core.net.NetUtil; /** * MyBatis Plus 配置 diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/config/properties/CaptchaProperties.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/config/properties/CaptchaProperties.java index 7f4b6c9fa..9983799fd 100644 --- a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/config/properties/CaptchaProperties.java +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/config/properties/CaptchaProperties.java @@ -19,17 +19,12 @@ import java.awt.*; import lombok.Data; -import lombok.Getter; -import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import com.wf.captcha.*; -import com.wf.captcha.base.Captcha; - -import cn.hutool.core.util.ReflectUtil; -import cn.hutool.core.util.StrUtil; /** * 验证码配置属性 @@ -43,9 +38,10 @@ public class CaptchaProperties { /** - * 图片验证码配置 + * 过期时间 */ - private CaptchaImage image; + @Value("${captcha.graphic.expirationInMinutes}") + private long expirationInMinutes; /** * 邮箱验证码配置 @@ -57,61 +53,6 @@ public class CaptchaProperties { */ private CaptchaSms sms; - /** - * 图片验证码配置 - */ - @Data - public static class CaptchaImage { - /** - * 类型 - */ - private CaptchaImageTypeEnum type; - - /** - * 内容长度 - */ - private int length; - - /** - * 过期时间 - */ - private long expirationInMinutes; - - /** - * 宽度 - */ - private int width = 111; - - /** - * 高度 - */ - private int height = 36; - - /** - * 字体 - */ - private String fontName; - - /** - * 字体大小 - */ - private int fontSize = 25; - - /** - * 获取图片验证码对象 - * - * @return 验证码对象 - */ - public Captcha getCaptcha() { - Captcha captcha = ReflectUtil.newInstance(type.getClazz(), this.width, this.height); - captcha.setLen(length); - if (StrUtil.isNotBlank(this.fontName)) { - captcha.setFont(new Font(this.fontName, Font.PLAIN, this.fontSize)); - } - return captcha; - } - } - /** * 邮箱验证码配置 */ @@ -163,42 +104,4 @@ public static class CaptchaSms { */ private String templateId; } - - /** - * 图片验证码类型枚举 - */ - @Getter - @RequiredArgsConstructor - private enum CaptchaImageTypeEnum { - - /** - * 算术 - */ - ARITHMETIC(ArithmeticCaptcha.class), - - /** - * 中文 - */ - CHINESE(ChineseCaptcha.class), - - /** - * 中文闪图 - */ - CHINESE_GIF(ChineseGifCaptcha.class), - - /** - * 闪图 - */ - GIF(GifCaptcha.class), - - /** - * 特殊类型 - */ - SPEC(SpecCaptcha.class),; - - /** - * 验证码字节码类型 - */ - private final Class clazz; - } } diff --git a/continew-admin-webapi/src/main/java/top/charles7c/cnadmin/webapi/controller/common/CaptchaController.java b/continew-admin-webapi/src/main/java/top/charles7c/cnadmin/webapi/controller/common/CaptchaController.java index 837f57f09..47ede464c 100644 --- a/continew-admin-webapi/src/main/java/top/charles7c/cnadmin/webapi/controller/common/CaptchaController.java +++ b/continew-admin-webapi/src/main/java/top/charles7c/cnadmin/webapi/controller/common/CaptchaController.java @@ -56,6 +56,7 @@ import top.charles7c.cnadmin.common.util.TemplateUtils; import top.charles7c.cnadmin.common.util.validate.CheckUtils; import top.charles7c.continew.starter.cache.redisson.util.RedisUtils; +import top.charles7c.continew.starter.captcha.graphic.autoconfigure.GraphicCaptchaProperties; /** * 验证码 API @@ -73,17 +74,15 @@ public class CaptchaController { private final CaptchaProperties captchaProperties; private final ProjectProperties projectProperties; + private final GraphicCaptchaProperties graphicCaptchaProperties; @Operation(summary = "获取图片验证码", description = "获取图片验证码(Base64编码,带图片格式:data:image/gif;base64)") @GetMapping("/img") public CaptchaResp getImageCaptcha() { - // 生成验证码 - CaptchaProperties.CaptchaImage captchaImage = captchaProperties.getImage(); - Captcha captcha = captchaImage.getCaptcha(); - // 保存验证码 + Captcha captcha = graphicCaptchaProperties.getCaptcha(); String uuid = IdUtil.fastUUID(); String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, uuid); - RedisUtils.set(captchaKey, captcha.text(), Duration.ofMinutes(captchaImage.getExpirationInMinutes())); + RedisUtils.set(captchaKey, captcha.text(), Duration.ofMinutes(captchaProperties.getExpirationInMinutes())); return CaptchaResp.builder().uuid(uuid).img(captcha.toBase64()).build(); } diff --git a/continew-admin-webapi/src/main/resources/config/application-dev.yml b/continew-admin-webapi/src/main/resources/config/application-dev.yml index 4844e8a67..64b31f6a9 100644 --- a/continew-admin-webapi/src/main/resources/config/application-dev.yml +++ b/continew-admin-webapi/src/main/resources/config/application-dev.yml @@ -130,18 +130,15 @@ spring.mail: --- ### 验证码配置 captcha: - ## 图片验证码配置 - image: + ## 图形验证码配置 + graphic: + enabled: true # 类型 type: SPEC # 内容长度 length: 4 # 过期时间 expirationInMinutes: 2 - # 宽度 - width: 111 - # 高度 - height: 36 ## 邮箱验证码配置 mail: # 内容长度 diff --git a/continew-admin-webapi/src/main/resources/config/application-prod.yml b/continew-admin-webapi/src/main/resources/config/application-prod.yml index 2327bd7bc..f4f4fd6a0 100644 --- a/continew-admin-webapi/src/main/resources/config/application-prod.yml +++ b/continew-admin-webapi/src/main/resources/config/application-prod.yml @@ -132,18 +132,15 @@ spring.mail: --- ### 验证码配置 captcha: - ## 图片验证码配置 - image: + ## 图形验证码配置 + graphic: + enabled: true # 类型 type: SPEC # 内容长度 length: 4 # 过期时间 expirationInMinutes: 2 - # 宽度 - width: 111 - # 高度 - height: 36 ## 邮箱验证码配置 mail: # 内容长度 diff --git a/pom.xml b/pom.xml index ca89902c4..2748a5c91 100644 --- a/pom.xml +++ b/pom.xml @@ -38,8 +38,6 @@ 1.16.5 3.3.2 3.1.5.1 - 1.6.2 - 5.8.22 2.40.0 @@ -113,20 +111,6 @@ ${ip2region.version} - - - com.github.whvcse - easy-captcha - ${easy-captcha.version} - - - - - cn.hutool - hutool-all - ${hutool.version} - -