Compare commits

..

4 Commits

Author SHA1 Message Date
曾文豪
6c6d713c01 publish 2.0.0.rc8 2024-07-25 17:35:51 +08:00
曾文豪
8ea34c3ee0 perf:移除TimedCacheService、TimedCacheHelper,新增TsCacheService,同时实现了内存缓存、Redis缓存 2024-07-25 17:35:01 +08:00
曾文豪
d357fa7c85 publish 2.0.0.rc7 2024-07-12 11:17:04 +08:00
曾文豪
6332d1486b publish 2.0.0.rc6 2024-07-12 11:16:46 +08:00
25 changed files with 295 additions and 155 deletions

22
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
<packaging>pom</packaging>
<name>springboot-parent</name>
<description>杭州铁晟科技有限公司基础依赖</description>
@@ -58,61 +58,61 @@
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-database</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-login</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-web</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-util</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-platform</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-message</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-encrypt</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-role</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-annotation</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-poi</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</dependency>
<dependency>

View File

@@ -6,11 +6,11 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</parent>
<artifactId>springboot-ademo</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
@@ -36,6 +36,12 @@
<artifactId>easyexcel</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.7.0</version>
</dependency>
</dependencies>
<repositories>

View File

@@ -9,23 +9,25 @@ import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.tiesheng.annotation.token.TokenIgnore;
import com.tiesheng.util.pojos.TokenBean;
import com.tiesheng.web.service.CoreLogService;
import com.tiesheng.web.service.CoreMessageService;
import com.tiesheng.web.util.ProcessImportConsumer;
import com.tiesheng.database.config.DbBackupConfig;
import com.tiesheng.demo.pojos.PoiBean;
import com.tiesheng.demo.pojos.TestFile;
import com.tiesheng.util.config.TsTokenConfig;
import com.tiesheng.message.pojos.MessageReqResp;
import com.tiesheng.message.pojos.UserChannel;
import com.tiesheng.util.config.EncryptConfig;
import com.tiesheng.util.config.GlobalConfig;
import com.tiesheng.util.config.Ip2regionConfig;
import com.tiesheng.util.config.TsTokenConfig;
import com.tiesheng.util.pojos.ApiResp;
import com.tiesheng.util.pojos.FileUploadPath;
import com.tiesheng.util.service.TsCacheService;
import com.tiesheng.web.service.CoreLogService;
import com.tiesheng.web.service.CoreMessageService;
import com.tiesheng.web.util.ProcessImportConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
@@ -53,6 +55,8 @@ public class TestController {
CoreLogService coreLogService;
@Autowired
DbBackupConfig dbBackupConfig;
@Autowired
TsCacheService tsCacheService;
@RequestMapping("/index")
@@ -100,8 +104,13 @@ public class TestController {
@RequestMapping("/export")
@TokenIgnore
public ApiResp<String> export() {
// tsCacheService.put("fdfhdfd", "fdfdfdfd");
String s = tsCacheService.get("fdfhdfd");
LogFactory.get().info("export: " + s);
// List<TestFile> list = new ArrayList<>();
// list.add(new TestFile("11111"));
// list.add(new TestFile("22222"));

View File

@@ -7,6 +7,8 @@ spring:
url: jdbc:mysql://47.96.30.85:3306/com_tiesheng_web?useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&queryTimeout=5400&allowMultiQueries=true&serverTimezone=GMT%2B8
username: com_tiesheng_web
password: 4Xo$XheGFc
redis:
url: redis://kyF0zUL3011111@47.96.30.85:6234
platform:
wxmp:

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</parent>
<artifactId>springboot-annotation</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</parent>
<artifactId>springboot-database</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</parent>
<artifactId>springboot-encrypt</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</parent>
<artifactId>springboot-login</artifactId>

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
import com.tiesheng.annotation.token.TokenIgnore;
import com.tiesheng.util.config.TsTokenConfig;
import com.tiesheng.util.pojos.TokenBean;
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
@@ -82,6 +83,10 @@ public class TokenWebMvcConfigurer implements WebMvcConfigurer {
// 过滤不要需要验证的接口(注解)
HandlerMethod handlerMethod = (HandlerMethod) handler;
if (handlerMethod.getBeanType() == BasicErrorController.class) {
return true;
}
TokenIgnore annotation = handlerMethod.getBeanType().getAnnotation(TokenIgnore.class);
if (annotation != null) {
return true;

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</parent>
<artifactId>springboot-message</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</parent>
<artifactId>springboot-platform</artifactId>

View File

@@ -10,8 +10,8 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.LogFactory;
import com.tiesheng.platform.config.ding.bean.*;
import com.tiesheng.util.TimedCacheHelper;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.service.TsCacheService;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@@ -94,7 +94,7 @@ public class PlatformDingConfig {
*/
private String getAccessToken(String service) {
DingConfigBean dingConfigBean = getConfigBean(service);
String accessToken = TimedCacheHelper.getTimedCache().get(CACHE_ACCESS_TOKEN + dingConfigBean.getAppKey(), false);
String accessToken = TsCacheService.of().get(CACHE_ACCESS_TOKEN + dingConfigBean.getAppKey(), -1);
if (!StrUtil.isEmpty(accessToken)) {
return accessToken;
}
@@ -106,7 +106,8 @@ public class PlatformDingConfig {
String response = HttpUtil.get("https://oapi.dingtalk.com/gettoken", query);
JSONObject respJson = JSONUtil.parseObj(response);
accessToken = respJson.getStr("access_token");
TimedCacheHelper.getTimedCache().put(CACHE_ACCESS_TOKEN + dingConfigBean.getAppKey(), accessToken, respJson.getLong("expires_in"));
TsCacheService.of().put(CACHE_ACCESS_TOKEN + dingConfigBean.getAppKey(),
accessToken, respJson.getLong("expires_in"));
return accessToken;
}
@@ -120,7 +121,7 @@ public class PlatformDingConfig {
*/
private String getJsapiTicket(String service) {
DingConfigBean dingConfigBean = getConfigBean(service);
String jsapiTicket = TimedCacheHelper.getTimedCache().get(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(), false);
String jsapiTicket = TsCacheService.of().get(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(), -1);
if (StrUtil.isEmpty(jsapiTicket)) {
DingResponse<String> respJson = doRequest(service, "https://oapi.dingtalk.com/get_jsapi_ticket", null,
new TypeReference<DingResponse<String>>() {
@@ -129,7 +130,7 @@ public class PlatformDingConfig {
throw new ApiException(respJson.getErrmsg());
}
jsapiTicket = respJson.getTicket();
TimedCacheHelper.getTimedCache().put(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(),
TsCacheService.of().put(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(),
jsapiTicket, respJson.getExpiresIn());
}
return jsapiTicket;

View File

@@ -12,8 +12,8 @@ import com.tiesheng.platform.config.wxmp.bean.WxConfigBean;
import com.tiesheng.platform.config.wxmp.bean.WxJsapiSignature;
import com.tiesheng.platform.config.wxmp.bean.WxOAuth2AccessToken;
import com.tiesheng.platform.config.wxmp.bean.WxUserInfo;
import com.tiesheng.util.TimedCacheHelper;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.service.TsCacheService;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@@ -63,17 +63,17 @@ public class PlatformWxmpConfig {
*/
private String getAccessToken(String service) {
WxConfigBean configBean = getConfigBean(service);
String accessToken = TimedCacheHelper.getTimedCache().get(CACHE_ACCESS_TOKEN + configBean.getAppId(), false);
String accessToken = TsCacheService.of().get(CACHE_ACCESS_TOKEN + configBean.getAppId(), -1);
if (StrUtil.isEmpty(accessToken)) {
Map<String, Object> query = new HashMap<>(10);
query.put("grant_type", "client_credential");
query.put("appid", configBean.getAppId());
query.put("secret", configBean.getAppSecret());
String response = HttpUtil.get("https://api.weixin.qq.com/cgi-bin/token", query);
LogFactory.get().info("getAccessToken: " + response);
JSONObject respJson = JSONUtil.parseObj(response);
accessToken = respJson.getStr("access_token");
TimedCacheHelper.getTimedCache().put(CACHE_ACCESS_TOKEN + configBean.getAppId(), accessToken, respJson.getLong("expires_in"));
TsCacheService.of().put(CACHE_ACCESS_TOKEN + configBean.getAppId(), accessToken,
respJson.getLong("expires_in"));
}
return accessToken;
}
@@ -86,7 +86,7 @@ public class PlatformWxmpConfig {
*/
private String getJsapiTicket(String service) {
WxConfigBean configBean = getConfigBean(service);
String jsapiTicket = TimedCacheHelper.getTimedCache().get(CACHE_JSAPI_TICKET + configBean.getAppId(), false);
String jsapiTicket = TsCacheService.of().get(CACHE_JSAPI_TICKET + configBean.getAppId(), -1);
if (StrUtil.isEmpty(jsapiTicket)) {
Map<String, Object> query = new HashMap<>(10);
query.put("access_token", getAccessToken(service));
@@ -95,7 +95,8 @@ public class PlatformWxmpConfig {
LogFactory.get().info("getJsapiTicket: " + response);
JSONObject respJson = JSONUtil.parseObj(response);
jsapiTicket = respJson.getStr("ticket");
TimedCacheHelper.getTimedCache().put(CACHE_JSAPI_TICKET + configBean.getAppId(), jsapiTicket, respJson.getLong("expires_in"));
TsCacheService.of().put(CACHE_JSAPI_TICKET + configBean.getAppId(), jsapiTicket,
respJson.getLong("expires_in"));
}
return jsapiTicket;
}

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</parent>
<artifactId>springboot-poi</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</parent>
<artifactId>springboot-role</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</parent>
<artifactId>springboot-util</artifactId>
@@ -68,6 +68,17 @@
<version>1.68</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

@@ -1,25 +0,0 @@
package com.tiesheng.util;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
public class TimedCacheHelper {
private static volatile TimedCache<String, String> timedCache;
/**
* 获取一个默认2分钟过期的缓存
*/
public static TimedCache<String, String> getTimedCache() {
if (timedCache == null) {
synchronized (TimedCacheHelper.class) {
if (timedCache == null) {
timedCache = CacheUtil.newTimedCache(2 * 60 * 1000);
timedCache.schedulePrune(1000);
}
}
}
return timedCache;
}
}

View File

@@ -8,8 +8,8 @@ import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.symmetric.SM4;
import com.tiesheng.util.ServletKit;
import com.tiesheng.util.TimedCacheHelper;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.service.TsCacheService;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@@ -104,12 +104,12 @@ public class EncryptConfig {
String salt = decrypt(encrypted).substring(0, saltSize);
String inputEncrypted = passwdCreate(inputPasswd, salt);
if (!StrUtil.equals(inputEncrypted, encrypted)) {
String clientIp = ServletKit.getClientIP();
int num = NumberUtil.parseInt(TimedCacheHelper.getTimedCache().get(clientIp, false));
String clientIp = "passwdVerify_" + ServletKit.getClientIP();
int num = NumberUtil.parseInt(TsCacheService.of().get(clientIp, -1));
if (num > 5) {
throw new ApiException("登录失败已达6次请10分钟后再试");
}
TimedCacheHelper.getTimedCache().put(clientIp, String.valueOf(num + 1), 10 * 60 * 1000);
TsCacheService.of().put(clientIp, String.valueOf(num + 1), 10 * 60 * 1000);
throw new ApiException("账号或密码错误");
}
}

View File

@@ -0,0 +1,72 @@
package com.tiesheng.util.service;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONUtil;
import com.tiesheng.util.ServletKit;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.service.cache.TsCacheHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TsCacheService {
@Autowired
TsCacheHandler tsCacheHandler;
/**
* 获取一个缓存
*
* @return
*/
public static TsCacheService of() {
return SpringUtil.getBean(TsCacheService.class);
}
public void put(String key, String value) {
tsCacheHandler.put(key, value);
}
public void put(String key, String value, long timeout) {
tsCacheHandler.put(key, value, timeout);
}
public void putObj(String key, Object value, long timeout) {
tsCacheHandler.put(key, JSONUtil.toJsonStr(value), timeout);
}
public String get(String key) {
return tsCacheHandler.get(key);
}
public String get(String key, long timeout) {
return tsCacheHandler.get(key, timeout);
}
public <T> T getObj(String key, Class<T> tClass, long timeout) {
return JSONUtil.toBean(get(key, timeout), tClass, true);
}
public void remove(String key) {
tsCacheHandler.remove(key);
}
///////////////////////////////////////////////////////////////////////////
// 图形验证码
///////////////////////////////////////////////////////////////////////////
/**
* 验证 图片验证码
*/
public void verifyCaptcha(String value) {
String captchaKey = ServletUtil.getHeader(ServletKit.getRequest(), "captcha", "utf-8");
String cache = get(captchaKey);
if (StrUtil.isEmpty(cache) || !StrUtil.equals(cache, value)) {
throw new ApiException("验证码不正确");
}
remove(captchaKey);
}
}

View File

@@ -0,0 +1,17 @@
package com.tiesheng.util.service.cache;
public interface TsCacheHandler {
String name();
void put(String key, String value);
void put(String key, String value, long timeout);
String get(String key);
String get(String key, long timeout);
void remove(String key);
}

View File

@@ -0,0 +1,56 @@
package com.tiesheng.util.service.cache;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
@Configuration
@ConditionalOnProperty("spring.redis.url")
public class TsCacheRedisHandler implements TsCacheHandler {
@Resource
RedisTemplate<String, String> redisTemplate;
@Override
public String name() {
return "RedisCache";
}
@Override
public void put(String key, String value) {
redisTemplate.opsForValue().set(key, value);
}
@Override
public void put(String key, String value, long timeout) {
redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.MICROSECONDS);
}
@Override
public String get(String key) {
return redisTemplate.opsForValue().get(key);
}
@Override
public String get(String key, long timeout) {
if (timeout > 0) {
return redisTemplate.opsForValue().getAndExpire(key, timeout, TimeUnit.MICROSECONDS);
} else if (timeout == 0) {
return redisTemplate.opsForValue().getAndDelete(key);
}
return redisTemplate.opsForValue().get(key);
}
@Override
public void remove(String key) {
redisTemplate.delete(key);
}
}

View File

@@ -0,0 +1,67 @@
package com.tiesheng.util.service.cache;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnMissingBean(value = TsCacheHandler.class, ignored = {TsCacheTimedHandler.class, TsCacheTimedHandler.class})
public class TsCacheTimedHandler implements TsCacheHandler {
private static volatile TimedCache<String, String> timedCache;
/**
* 获取一个默认2分钟过期的缓存
*/
private static TimedCache<String, String> getTimedCache() {
if (timedCache == null) {
synchronized (TsCacheTimedHandler.class) {
if (timedCache == null) {
timedCache = CacheUtil.newTimedCache(2 * 60 * 1000);
timedCache.schedulePrune(1000);
}
}
}
return timedCache;
}
@Override
public String name() {
return "TimedCache";
}
@Override
public void put(String key, String value) {
getTimedCache().put(key, value);
}
@Override
public void put(String key, String value, long timeout) {
getTimedCache().put(key, value, timeout);
}
@Override
public String get(String key) {
return getTimedCache().get(key);
}
@Override
public String get(String key, long timeout) {
String value = getTimedCache().get(key, false);
if (timeout > 0) {
getTimedCache().put(key, value, timeout);
} else if (timeout == 0) {
getTimedCache().remove(key);
}
return value;
}
@Override
public void remove(String key) {
getTimedCache().remove(key);
}
}

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.0.rc6</version>
<version>2.0.0.rc8</version>
</parent>
<artifactId>springboot-web</artifactId>

View File

@@ -5,12 +5,12 @@ import cn.hutool.captcha.LineCaptcha;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import com.tiesheng.annotation.token.TokenIgnore;
import com.tiesheng.util.service.TsCacheService;
import com.tiesheng.web.config.template.ToolTemplateHandler;
import com.tiesheng.web.pojos.dto.*;
import com.tiesheng.web.pojos.vo.TemplateInfoVO;
import com.tiesheng.web.pojos.vo.PicVerifyVo;
import com.tiesheng.web.service.FileUploadService;
import com.tiesheng.web.service.TimedCacheService;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.pojos.ApiResp;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,7 +31,7 @@ import java.util.stream.Collectors;
public class ToolController {
@Autowired
TimedCacheService timedCacheService;
TsCacheService tsCacheService;
@Autowired
FileUploadService fileUploadService;
@Autowired
@@ -51,7 +51,7 @@ public class ToolController {
PicVerifyVo vo = new PicVerifyVo();
vo.setBase64(lineCaptcha.getImageBase64Data());
vo.setKey(IdUtil.simpleUUID());
timedCacheService.setImageCode(vo.getKey(), lineCaptcha.getCode());
tsCacheService.put(vo.getKey(), lineCaptcha.getCode());
return ApiResp.respOK(vo);
}
@@ -113,7 +113,7 @@ public class ToolController {
/**
* 合并文件
*
* @param fileMd5
* @param dto
* @return
*/
@TokenIgnore

View File

@@ -1,82 +0,0 @@
package com.tiesheng.web.service;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import com.tiesheng.util.ServletKit;
import com.tiesheng.util.TimedCacheHelper;
import com.tiesheng.util.exception.ApiException;
import org.springframework.stereotype.Service;
/**
* @author hao
* @ProjectName cmcc
* @Copyright Hangzhou ShuoChuang Technology Co.,Ltd All Right Reserved
* @Description 这里是对文件的描述
* @data 2019-06-19
* @note 这里写文件的详细功能和改动
* @note
*/
@Service
public class TimedCacheService {
/**
* 清空数据
*
* @param key
*/
public void clearByKey(String key) {
TimedCacheHelper.getTimedCache().remove(key);
}
/**
* 放入缓存
*
* @param key
* @param val
*/
public void putCache(String key, String val) {
TimedCacheHelper.getTimedCache().put(key, val);
}
/**
* 获取缓存
*
* @param key
* @return
*/
public String getCache(String key) {
return TimedCacheHelper.getTimedCache().get(key);
}
///////////////////////////////////////////////////////////////////////////
// 图片验证码缓存
///////////////////////////////////////////////////////////////////////////
/**
* 缓存 图片验证码
*
* @param session
* @param value
*/
public void setImageCode(String captcha, String value) {
putCache(captcha, value);
}
/**
* 验证 图片验证码
*/
public void verifyImage(String value) {
String captchaKey = ServletUtil.getHeader(ServletKit.getRequest(), "captcha", "utf-8");
String cache = getCache(captchaKey);
if (StrUtil.isEmpty(cache) || !StrUtil.equals(cache, value)) {
throw new ApiException("验证码不正确");
}
clearByKey(captchaKey);
}
}