mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-29 00:42:50 +08:00
优化配置读取
This commit is contained in:
parent
2813e98d9e
commit
0e51cd7ceb
18
pom.xml
18
pom.xml
@ -95,6 +95,24 @@
|
|||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.12.0</version>
|
<version>3.12.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-api</artifactId>
|
||||||
|
<version>0.11.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-impl</artifactId>
|
||||||
|
<version>0.11.5</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-gson</artifactId>
|
||||||
|
<version>0.11.5</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -3,12 +3,12 @@ package xyz.playedu.api.service.impl;
|
|||||||
import com.google.code.kaptcha.impl.DefaultKaptcha;
|
import com.google.code.kaptcha.impl.DefaultKaptcha;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.FastByteArrayOutputStream;
|
import org.springframework.util.FastByteArrayOutputStream;
|
||||||
import xyz.playedu.api.service.ImageCaptchaService;
|
import xyz.playedu.api.service.ImageCaptchaService;
|
||||||
import xyz.playedu.api.types.ImageCaptchaResult;
|
import xyz.playedu.api.types.ImageCaptchaResult;
|
||||||
import xyz.playedu.api.util.Base64Util;
|
import xyz.playedu.api.util.Base64Util;
|
||||||
import xyz.playedu.api.util.EnvUtil;
|
|
||||||
import xyz.playedu.api.util.RedisUtil;
|
import xyz.playedu.api.util.RedisUtil;
|
||||||
import xyz.playedu.api.util.ToolUtil;
|
import xyz.playedu.api.util.ToolUtil;
|
||||||
|
|
||||||
@ -20,6 +20,12 @@ import java.io.IOException;
|
|||||||
@Service
|
@Service
|
||||||
public class ImageCaptchaServiceImpl implements ImageCaptchaService {
|
public class ImageCaptchaServiceImpl implements ImageCaptchaService {
|
||||||
|
|
||||||
|
@Value("${playedu.captcha.cache-prefix}")
|
||||||
|
private String ConfigCachePrefix;
|
||||||
|
|
||||||
|
@Value("${playedu.captcha.expire}")
|
||||||
|
private Long ConfigExpire;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private DefaultKaptcha defaultKaptcha;
|
private DefaultKaptcha defaultKaptcha;
|
||||||
|
|
||||||
@ -37,7 +43,7 @@ public class ImageCaptchaServiceImpl implements ImageCaptchaService {
|
|||||||
image = defaultKaptcha.createImage(imageCaptcha.getCode());
|
image = defaultKaptcha.createImage(imageCaptcha.getCode());
|
||||||
|
|
||||||
// 写入到redis中
|
// 写入到redis中
|
||||||
RedisUtil.set(getCacheKey(randomKey), imageCaptcha.getCode(), getExpireSeconds());
|
RedisUtil.set(getCacheKey(randomKey), imageCaptcha.getCode(), ConfigExpire);
|
||||||
|
|
||||||
FastByteArrayOutputStream os = new FastByteArrayOutputStream();
|
FastByteArrayOutputStream os = new FastByteArrayOutputStream();
|
||||||
ImageIO.write(image, "png", os);
|
ImageIO.write(image, "png", os);
|
||||||
@ -66,10 +72,6 @@ public class ImageCaptchaServiceImpl implements ImageCaptchaService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getCacheKey(String val) {
|
private String getCacheKey(String val) {
|
||||||
return EnvUtil.get("playedu.captcha.cache-name") + val;
|
return ConfigCachePrefix + val;
|
||||||
}
|
|
||||||
|
|
||||||
private Long getExpireSeconds() {
|
|
||||||
return Long.parseLong(EnvUtil.get("playedu.captcha.expire"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -34,5 +34,5 @@ mybatis-plus:
|
|||||||
playedu:
|
playedu:
|
||||||
captcha:
|
captcha:
|
||||||
expire: 300 #分5钟
|
expire: 300 #分5钟
|
||||||
cache-name: "captcha:key:"
|
cache-prefix: "captcha:key:"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user