diff --git a/pom.xml b/pom.xml index b395525..cc9f5ae 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,24 @@ commons-lang3 3.12.0 + + + io.jsonwebtoken + jjwt-api + 0.11.5 + + + io.jsonwebtoken + jjwt-impl + 0.11.5 + runtime + + + io.jsonwebtoken + jjwt-gson + 0.11.5 + compile + diff --git a/src/main/java/xyz/playedu/api/service/impl/ImageCaptchaServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/ImageCaptchaServiceImpl.java index dbb83cb..5c8d3cb 100644 --- a/src/main/java/xyz/playedu/api/service/impl/ImageCaptchaServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/ImageCaptchaServiceImpl.java @@ -3,12 +3,12 @@ package xyz.playedu.api.service.impl; import com.google.code.kaptcha.impl.DefaultKaptcha; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.util.FastByteArrayOutputStream; import xyz.playedu.api.service.ImageCaptchaService; import xyz.playedu.api.types.ImageCaptchaResult; import xyz.playedu.api.util.Base64Util; -import xyz.playedu.api.util.EnvUtil; import xyz.playedu.api.util.RedisUtil; import xyz.playedu.api.util.ToolUtil; @@ -20,6 +20,12 @@ import java.io.IOException; @Service public class ImageCaptchaServiceImpl implements ImageCaptchaService { + @Value("${playedu.captcha.cache-prefix}") + private String ConfigCachePrefix; + + @Value("${playedu.captcha.expire}") + private Long ConfigExpire; + @Resource private DefaultKaptcha defaultKaptcha; @@ -37,7 +43,7 @@ public class ImageCaptchaServiceImpl implements ImageCaptchaService { image = defaultKaptcha.createImage(imageCaptcha.getCode()); // 写入到redis中 - RedisUtil.set(getCacheKey(randomKey), imageCaptcha.getCode(), getExpireSeconds()); + RedisUtil.set(getCacheKey(randomKey), imageCaptcha.getCode(), ConfigExpire); FastByteArrayOutputStream os = new FastByteArrayOutputStream(); ImageIO.write(image, "png", os); @@ -66,10 +72,6 @@ public class ImageCaptchaServiceImpl implements ImageCaptchaService { } private String getCacheKey(String val) { - return EnvUtil.get("playedu.captcha.cache-name") + val; - } - - private Long getExpireSeconds() { - return Long.parseLong(EnvUtil.get("playedu.captcha.expire")); + return ConfigCachePrefix + val; } } diff --git a/src/main/java/xyz/playedu/api/util/EnvUtil.java b/src/main/java/xyz/playedu/api/util/EnvUtil.java deleted file mode 100644 index 313d46a..0000000 --- a/src/main/java/xyz/playedu/api/util/EnvUtil.java +++ /dev/null @@ -1,37 +0,0 @@ -package xyz.playedu.api.util; - -import org.springframework.context.EnvironmentAware; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -/** - * 系统文件配置操作工具 - */ -@Component -public class EnvUtil implements EnvironmentAware { - - private static Environment env; - - /** - * 设置环境变量 - * - * @author fzr - * @param environment 环境变量 - */ - @Override - public void setEnvironment(Environment environment) { - EnvUtil.env = environment; - } - - /** - * 根据Key获取值 - * - * @author fzr - * @param key 键 - * @return String - */ - public static String get(String key) { - return env.getProperty(key); - } - -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 376e155..357360a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -34,5 +34,5 @@ mybatis-plus: playedu: captcha: expire: 300 #分5钟 - cache-name: "captcha:key:" + cache-prefix: "captcha:key:"