Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c6d713c01 | ||
|
|
8ea34c3ee0 | ||
|
|
d357fa7c85 | ||
|
|
6332d1486b | ||
|
|
e709050ba3 | ||
|
|
59926aa2f4 | ||
|
|
5da83bb477 | ||
|
|
fb1f7c4e37 | ||
|
|
f831f4faf0 | ||
|
|
d7016b418e | ||
|
|
fd92109e2e |
93
CHANGELOG.md
@@ -1,94 +1,7 @@
|
|||||||
## 1.1.0
|
## 2.0.0.rc4
|
||||||
|
|
||||||
- feat:globalConfig增加ext属性。
|
- perf:TsTokenConfig不在提供静态方法
|
||||||
- feat:增加网络请求超时、重定向的配置。
|
- perf:移除TsTokenAspect,由TokenWebMvcConfigurer替代,并实现TokenBean参数注入
|
||||||
- perf:更新数据库对比插件。
|
|
||||||
- feat(web):增加DaoBase的常量。
|
|
||||||
- perf(web):操作日志优化。
|
|
||||||
|
|
||||||
|
|
||||||
## 1.0.12
|
|
||||||
|
|
||||||
- perf(encrypt):开启关闭加解密移动到**yaml**中配置,移除**EnableEncryptConfig**注解。
|
|
||||||
- feat(login):登录接口增加验签步骤,可通过**validLoginSign**属性开启或关闭(默认)。
|
|
||||||
- perf(login):可重写**onSignError**方法自定义验签错误的跳转。
|
|
||||||
- fix(login):修复微信、钉钉授权跳转地址错误的bug
|
|
||||||
|
|
||||||
## 1.0.7
|
|
||||||
|
|
||||||
- feat(web): 增加uploadFileCustomize方法,允许自定义文件存放情况
|
|
||||||
- feat(database): 增加db/data目录,存放初始化数据的sql
|
|
||||||
- perf(login): 增加默认值,防止token解析异常
|
|
||||||
|
|
||||||
## 1.0.6
|
|
||||||
|
|
||||||
- feat(web):新增 **OperationIgnore** 注解,可以指定接口忽略操作日志的收集。
|
|
||||||
- feat(web):**OperationLog** 增加 desensitize 属性,用来脱敏指定的字段。
|
|
||||||
|
|
||||||
## 1.0.2
|
|
||||||
|
|
||||||
- feat(database):增加数据库定时备份;
|
|
||||||
- feat(database):增加过期备份的删除操作,默认过期时间为7天;
|
|
||||||
- perf(message):调整阿里云短信类,方便扩展其他方法。
|
|
||||||
- perf(message):消息发送接口该body类型为 **JSONObject**
|
|
||||||
- perf(message):调整消息发送接口和方法(不兼容旧版本)
|
|
||||||
|
|
||||||
## 1.0.1
|
|
||||||
|
|
||||||
- perf(web):fastjson增加配置 **DisableCircularReferenceDetect**,禁用相同的对象写成引用的形式。
|
|
||||||
|
|
||||||
## 1.0.0
|
|
||||||
|
|
||||||
- perf:hutool依赖升级:5.8.11 -> 5.8.16
|
|
||||||
- perf:fastjson依赖升级:1.2.78 -> 1.2.83
|
|
||||||
- perf:mybatis-plus依赖升级:3.5.1 -> 3.5.3
|
|
||||||
- perf:**TieshengWebConfigurer** 增加 **configSystemCheck** 方法,可根据情况校验系统配置参数。
|
|
||||||
|
|
||||||
从该版本开始,仓库地址改为:
|
|
||||||
|
|
||||||
``` pom
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>kepai-repo</id>
|
|
||||||
<url>http://git.kepai365.com/tiesheng/repository/raw/master</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
```
|
|
||||||
|
|
||||||
## 0.9.3
|
|
||||||
|
|
||||||
> 1,增加版本对比器,防止某些情况下版本对比失效;
|
|
||||||
>
|
|
||||||
|
|
||||||
## 0.8.3
|
|
||||||
|
|
||||||
### 调整
|
|
||||||
|
|
||||||
> 1,优化返回数据加密;
|
|
||||||
> 2,上传文件接口调整,统一为**application/json**格式;
|
|
||||||
|
|
||||||
## 0.8.0
|
|
||||||
|
|
||||||
### 调整
|
|
||||||
|
|
||||||
> 1,移除**PasswordUtil**类,新增**EncryptConfig**配置;
|
|
||||||
> 2,默认启用网络请求的加解密,前端请配合接口使用。
|
|
||||||
|
|
||||||
## 0.7.4
|
|
||||||
|
|
||||||
### 新增
|
|
||||||
|
|
||||||
> 现在操作日志默认收集(不包括GET请求):使用方法名称和接口作为参数存储。如果存在OperationLog注解,则使用注解的内容。
|
|
||||||
|
|
||||||
## 0.7.3
|
|
||||||
|
|
||||||
### 增加
|
|
||||||
|
|
||||||
> 1,TsTokenConfig增加新的属性**ignorePaths**,用于通过路径忽略token;
|
|
||||||
> 2,PasswordUtils增加密码复杂度校验方法;
|
|
||||||
> 3,PasswordUtils.verifyPassword增加登录次数限制:10分钟内不能错误6次;
|
|
||||||
>
|
|
||||||
|
|
||||||
### 调整
|
|
||||||
|
|
||||||
> 1,TsTokenConfig中的**ignores**属性调整为**testMap**;
|
|
||||||
|
|||||||
94
CHANGELOG_V1.md
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
## 1.1.0
|
||||||
|
|
||||||
|
- feat:globalConfig增加ext属性。
|
||||||
|
- feat:增加网络请求超时、重定向的配置。
|
||||||
|
- perf:更新数据库对比插件。
|
||||||
|
- feat(web):增加DaoBase的常量。
|
||||||
|
- perf(web):操作日志优化。
|
||||||
|
|
||||||
|
|
||||||
|
## 1.0.12
|
||||||
|
|
||||||
|
- perf(encrypt):开启关闭加解密移动到**yaml**中配置,移除**EnableEncryptConfig**注解。
|
||||||
|
- feat(login):登录接口增加验签步骤,可通过**validLoginSign**属性开启或关闭(默认)。
|
||||||
|
- perf(login):可重写**onSignError**方法自定义验签错误的跳转。
|
||||||
|
- fix(login):修复微信、钉钉授权跳转地址错误的bug
|
||||||
|
|
||||||
|
## 1.0.7
|
||||||
|
|
||||||
|
- feat(web): 增加uploadFileCustomize方法,允许自定义文件存放情况
|
||||||
|
- feat(database): 增加db/data目录,存放初始化数据的sql
|
||||||
|
- perf(login): 增加默认值,防止token解析异常
|
||||||
|
|
||||||
|
## 1.0.6
|
||||||
|
|
||||||
|
- feat(web):新增 **OperationIgnore** 注解,可以指定接口忽略操作日志的收集。
|
||||||
|
- feat(web):**OperationLog** 增加 desensitize 属性,用来脱敏指定的字段。
|
||||||
|
|
||||||
|
## 1.0.2
|
||||||
|
|
||||||
|
- feat(database):增加数据库定时备份;
|
||||||
|
- feat(database):增加过期备份的删除操作,默认过期时间为7天;
|
||||||
|
- perf(message):调整阿里云短信类,方便扩展其他方法。
|
||||||
|
- perf(message):消息发送接口该body类型为 **JSONObject**
|
||||||
|
- perf(message):调整消息发送接口和方法(不兼容旧版本)
|
||||||
|
|
||||||
|
## 1.0.1
|
||||||
|
|
||||||
|
- perf(web):fastjson增加配置 **DisableCircularReferenceDetect**,禁用相同的对象写成引用的形式。
|
||||||
|
|
||||||
|
## 1.0.0
|
||||||
|
|
||||||
|
- perf:hutool依赖升级:5.8.11 -> 5.8.16
|
||||||
|
- perf:fastjson依赖升级:1.2.78 -> 1.2.83
|
||||||
|
- perf:mybatis-plus依赖升级:3.5.1 -> 3.5.3
|
||||||
|
- perf:**TieshengWebConfigurer** 增加 **configSystemCheck** 方法,可根据情况校验系统配置参数。
|
||||||
|
|
||||||
|
从该版本开始,仓库地址改为:
|
||||||
|
|
||||||
|
``` pom
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>kepai-repo</id>
|
||||||
|
<url>http://git.kepai365.com/tiesheng/repository/raw/master</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 0.9.3
|
||||||
|
|
||||||
|
> 1,增加版本对比器,防止某些情况下版本对比失效;
|
||||||
|
>
|
||||||
|
|
||||||
|
## 0.8.3
|
||||||
|
|
||||||
|
### 调整
|
||||||
|
|
||||||
|
> 1,优化返回数据加密;
|
||||||
|
> 2,上传文件接口调整,统一为**application/json**格式;
|
||||||
|
|
||||||
|
## 0.8.0
|
||||||
|
|
||||||
|
### 调整
|
||||||
|
|
||||||
|
> 1,移除**PasswordUtil**类,新增**EncryptConfig**配置;
|
||||||
|
> 2,默认启用网络请求的加解密,前端请配合接口使用。
|
||||||
|
|
||||||
|
## 0.7.4
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
> 现在操作日志默认收集(不包括GET请求):使用方法名称和接口作为参数存储。如果存在OperationLog注解,则使用注解的内容。
|
||||||
|
|
||||||
|
## 0.7.3
|
||||||
|
|
||||||
|
### 增加
|
||||||
|
|
||||||
|
> 1,TsTokenConfig增加新的属性**ignorePaths**,用于通过路径忽略token;
|
||||||
|
> 2,PasswordUtils增加密码复杂度校验方法;
|
||||||
|
> 3,PasswordUtils.verifyPassword增加登录次数限制:10分钟内不能错误6次;
|
||||||
|
>
|
||||||
|
|
||||||
|
### 调整
|
||||||
|
|
||||||
|
> 1,TsTokenConfig中的**ignores**属性调整为**testMap**;
|
||||||
22
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>springboot-parent</name>
|
<name>springboot-parent</name>
|
||||||
<description>杭州铁晟科技有限公司基础依赖</description>
|
<description>杭州铁晟科技有限公司基础依赖</description>
|
||||||
@@ -58,61 +58,61 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-database</artifactId>
|
<artifactId>springboot-database</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-login</artifactId>
|
<artifactId>springboot-login</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-web</artifactId>
|
<artifactId>springboot-web</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-util</artifactId>
|
<artifactId>springboot-util</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-platform</artifactId>
|
<artifactId>springboot-platform</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-message</artifactId>
|
<artifactId>springboot-message</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-encrypt</artifactId>
|
<artifactId>springboot-encrypt</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-role</artifactId>
|
<artifactId>springboot-role</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-annotation</artifactId>
|
<artifactId>springboot-annotation</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-poi</artifactId>
|
<artifactId>springboot-poi</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
BIN
springboot-ademo/.DS_Store
vendored
@@ -6,11 +6,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-ademo</artifactId>
|
<artifactId>springboot-ademo</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
@@ -36,6 +36,12 @@
|
|||||||
<artifactId>easyexcel</artifactId>
|
<artifactId>easyexcel</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>redis.clients</groupId>
|
||||||
|
<artifactId>jedis</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|||||||
BIN
springboot-ademo/src/main/java/com/tiesheng/.DS_Store
vendored
Normal file
BIN
springboot-ademo/src/main/java/com/tiesheng/demo/.DS_Store
vendored
Normal file
@@ -40,11 +40,11 @@ public class DemoWebConfigurer implements TieshengWebConfigurer {
|
|||||||
public void redirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
|
public void redirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
|
||||||
|
|
||||||
// 默认跳转到mobile
|
// 默认跳转到mobile
|
||||||
to = StrUtil.emptyToDefault(to, "mobile");
|
to = StrUtil.emptyToDefault(to, "static/mobile");
|
||||||
bean.setEnvironmentType(to);
|
bean.setEnvironmentType(to);
|
||||||
|
|
||||||
if (Objects.equals(bean.getEnvironmentType(), "mobile")) {
|
if (Objects.equals(bean.getEnvironmentType(), "static/mobile")) {
|
||||||
globalConfig.redirect("mobile", "/?token=" + bean.toToken(), response);
|
globalConfig.redirect("static/mobile", "/?token=" + bean.toToken(), response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,22 +9,25 @@ import com.alibaba.excel.EasyExcel;
|
|||||||
import com.alibaba.excel.context.AnalysisContext;
|
import com.alibaba.excel.context.AnalysisContext;
|
||||||
import com.alibaba.excel.read.listener.ReadListener;
|
import com.alibaba.excel.read.listener.ReadListener;
|
||||||
import com.tiesheng.annotation.token.TokenIgnore;
|
import com.tiesheng.annotation.token.TokenIgnore;
|
||||||
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.database.config.DbBackupConfig;
|
||||||
import com.tiesheng.demo.pojos.PoiBean;
|
import com.tiesheng.demo.pojos.PoiBean;
|
||||||
import com.tiesheng.demo.pojos.TestFile;
|
import com.tiesheng.demo.pojos.TestFile;
|
||||||
import com.tiesheng.util.config.TsTokenConfig;
|
|
||||||
import com.tiesheng.message.pojos.MessageReqResp;
|
import com.tiesheng.message.pojos.MessageReqResp;
|
||||||
import com.tiesheng.message.pojos.UserChannel;
|
import com.tiesheng.message.pojos.UserChannel;
|
||||||
import com.tiesheng.util.config.EncryptConfig;
|
import com.tiesheng.util.config.EncryptConfig;
|
||||||
import com.tiesheng.util.config.GlobalConfig;
|
import com.tiesheng.util.config.GlobalConfig;
|
||||||
import com.tiesheng.util.config.Ip2regionConfig;
|
import com.tiesheng.util.config.Ip2regionConfig;
|
||||||
|
import com.tiesheng.util.config.TsTokenConfig;
|
||||||
import com.tiesheng.util.pojos.ApiResp;
|
import com.tiesheng.util.pojos.ApiResp;
|
||||||
import com.tiesheng.util.pojos.FileUploadPath;
|
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.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 javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -52,11 +55,14 @@ public class TestController {
|
|||||||
CoreLogService coreLogService;
|
CoreLogService coreLogService;
|
||||||
@Autowired
|
@Autowired
|
||||||
DbBackupConfig dbBackupConfig;
|
DbBackupConfig dbBackupConfig;
|
||||||
|
@Autowired
|
||||||
|
TsCacheService tsCacheService;
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/index")
|
@RequestMapping("/index")
|
||||||
public ApiResp<String> index() {
|
@TokenIgnore
|
||||||
return ApiResp.respOK("hello world");
|
public void index(HttpServletResponse response) {
|
||||||
|
globalConfig.redirect("mobile", "/test", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/redirect")
|
@RequestMapping("/redirect")
|
||||||
@@ -98,8 +104,13 @@ public class TestController {
|
|||||||
|
|
||||||
|
|
||||||
@RequestMapping("/export")
|
@RequestMapping("/export")
|
||||||
|
@TokenIgnore
|
||||||
public ApiResp<String> export() {
|
public ApiResp<String> export() {
|
||||||
|
|
||||||
|
// tsCacheService.put("fdfhdfd", "fdfdfdfd");
|
||||||
|
String s = tsCacheService.get("fdfhdfd");
|
||||||
|
LogFactory.get().info("export: " + s);
|
||||||
|
|
||||||
// List<TestFile> list = new ArrayList<>();
|
// List<TestFile> list = new ArrayList<>();
|
||||||
// list.add(new TestFile("11111"));
|
// list.add(new TestFile("11111"));
|
||||||
// list.add(new TestFile("22222"));
|
// list.add(new TestFile("22222"));
|
||||||
|
|||||||
@@ -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
|
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
|
username: com_tiesheng_web
|
||||||
password: 4Xo$XheGFc
|
password: 4Xo$XheGFc
|
||||||
|
redis:
|
||||||
|
url: redis://kyF0zUL3011111@47.96.30.85:6234
|
||||||
|
|
||||||
platform:
|
platform:
|
||||||
wxmp:
|
wxmp:
|
||||||
|
|||||||
@@ -13,16 +13,9 @@ spring:
|
|||||||
web:
|
web:
|
||||||
resources:
|
resources:
|
||||||
static-locations: classpath:/static/,file:static/
|
static-locations: classpath:/static/,file:static/
|
||||||
mvc:
|
|
||||||
pathmatch:
|
|
||||||
matching-strategy: ant_path_matcher
|
|
||||||
|
|
||||||
## 日志
|
## 日志
|
||||||
logging:
|
logging:
|
||||||
file:
|
file:
|
||||||
name: runtime/logs/tiesheng.log
|
name: runtime/logs/tiesheng.log
|
||||||
tiesheng:
|
|
||||||
token:
|
|
||||||
ignore-paths:
|
|
||||||
- /test/index
|
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 75 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 8.9 KiB After Width: | Height: | Size: 8.9 KiB |
BIN
springboot-annotation/.DS_Store
vendored
Normal file
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-annotation</artifactId>
|
<artifactId>springboot-annotation</artifactId>
|
||||||
|
|||||||
BIN
springboot-database/.DS_Store
vendored
Normal file
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-database</artifactId>
|
<artifactId>springboot-database</artifactId>
|
||||||
|
|||||||
BIN
springboot-encrypt/.DS_Store
vendored
Normal file
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-encrypt</artifactId>
|
<artifactId>springboot-encrypt</artifactId>
|
||||||
|
|||||||
BIN
springboot-login/.DS_Store
vendored
Normal file
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-login</artifactId>
|
<artifactId>springboot-login</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package com.tiesheng.login.config;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjUtil;
|
||||||
|
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;
|
||||||
|
import org.springframework.web.context.request.NativeWebRequest;
|
||||||
|
import org.springframework.web.method.HandlerMethod;
|
||||||
|
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||||
|
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class TokenWebMvcConfigurer implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
TsTokenConfig tsTokenConfig;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
|
||||||
|
resolvers.add(new HandlerMethodArgumentResolver() {
|
||||||
|
@Override
|
||||||
|
public boolean supportsParameter(MethodParameter parameter) {
|
||||||
|
return parameter.getParameterType().isAssignableFrom(TokenBean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
|
||||||
|
String header = webRequest.getHeader(TsTokenConfig.TOKEN_KEY);
|
||||||
|
|
||||||
|
boolean thrExp = true;
|
||||||
|
Method method = parameter.getMethod();
|
||||||
|
if (method != null) {
|
||||||
|
TokenIgnore annotation = method.getAnnotation(TokenIgnore.class);
|
||||||
|
thrExp = annotation == null;
|
||||||
|
}
|
||||||
|
return tsTokenConfig.validToken(header, thrExp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
|
registry.addInterceptor(new HandlerInterceptor() {
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||||
|
|
||||||
|
// 非接口类直接跳过
|
||||||
|
if (!(handler instanceof HandlerMethod)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String requestURI = request.getRequestURI();
|
||||||
|
String[] ignorePaths = tsTokenConfig.getIgnorePaths();
|
||||||
|
if (ObjUtil.isNotEmpty(ignorePaths)) {
|
||||||
|
for (String path : ignorePaths) {
|
||||||
|
if (path.contains("/**") &&
|
||||||
|
StrUtil.startWith(requestURI, path.replace("/**", ""))) {
|
||||||
|
// 通配路径
|
||||||
|
return true;
|
||||||
|
} else if (requestURI.equals(path)) {
|
||||||
|
// 完整路径
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过滤不要需要验证的接口(注解)
|
||||||
|
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
||||||
|
if (handlerMethod.getBeanType() == BasicErrorController.class) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TokenIgnore annotation = handlerMethod.getBeanType().getAnnotation(TokenIgnore.class);
|
||||||
|
if (annotation != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
TokenIgnore apiTokenIgnore = handlerMethod.getMethodAnnotation(TokenIgnore.class);
|
||||||
|
if (apiTokenIgnore != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// token验证
|
||||||
|
tsTokenConfig.validToken(request, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
package com.tiesheng.login.config;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import com.tiesheng.annotation.token.TokenIgnore;
|
|
||||||
import com.tiesheng.util.ServletKit;
|
|
||||||
import com.tiesheng.util.config.TsTokenConfig;
|
|
||||||
import org.aspectj.lang.JoinPoint;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
|
||||||
import org.aspectj.lang.annotation.Before;
|
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hao
|
|
||||||
* @ProjectName CmccSpring
|
|
||||||
* @Copyright Hangzhou ShuoChuang Technology Co.,Ltd All Right Reserved
|
|
||||||
* @Description 这里是对文件的描述
|
|
||||||
* @data 2019-07-15
|
|
||||||
* @note 这里写文件的详细功能和改动
|
|
||||||
* @note
|
|
||||||
*/
|
|
||||||
@Aspect
|
|
||||||
@Component
|
|
||||||
public class TsTokenAspect {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
TsTokenConfig tsTokenConfig;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 切入点
|
|
||||||
*/
|
|
||||||
@Pointcut("execution(* com..controller..*.*(..))")
|
|
||||||
public void methodArgs() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取操作日志说明
|
|
||||||
*
|
|
||||||
* @param joinPoint
|
|
||||||
*/
|
|
||||||
@Before("methodArgs()")
|
|
||||||
public void before(JoinPoint joinPoint) {
|
|
||||||
|
|
||||||
// 过滤不要需要验证的接口(path)
|
|
||||||
String requestURI = ServletKit.getRequest().getRequestURI();
|
|
||||||
String[] ignorePaths = tsTokenConfig.getIgnorePaths();
|
|
||||||
if (ObjUtil.isNotEmpty(ignorePaths)) {
|
|
||||||
for (String path : ignorePaths) {
|
|
||||||
if (path.contains("/**") &&
|
|
||||||
StrUtil.startWith(requestURI, path.replace("/**", ""))) {
|
|
||||||
// 通配路径
|
|
||||||
return;
|
|
||||||
} else if (requestURI.equals(path)) {
|
|
||||||
// 完整路径
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 过滤不要需要验证的接口(注解)
|
|
||||||
Object aThis = joinPoint.getTarget();
|
|
||||||
TokenIgnore annotation = aThis.getClass().getAnnotation(TokenIgnore.class);
|
|
||||||
if (annotation != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
|
||||||
Method method = signature.getMethod();
|
|
||||||
TokenIgnore apiTokenIgnore = method.getAnnotation(TokenIgnore.class);
|
|
||||||
if (apiTokenIgnore != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// token验证
|
|
||||||
tsTokenConfig.validToken(true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
BIN
springboot-message/.DS_Store
vendored
Normal file
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-message</artifactId>
|
<artifactId>springboot-message</artifactId>
|
||||||
|
|||||||
BIN
springboot-platform/.DS_Store
vendored
Normal file
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-platform</artifactId>
|
<artifactId>springboot-platform</artifactId>
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import cn.hutool.json.JSONObject;
|
|||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import cn.hutool.log.LogFactory;
|
import cn.hutool.log.LogFactory;
|
||||||
import com.tiesheng.platform.config.ding.bean.*;
|
import com.tiesheng.platform.config.ding.bean.*;
|
||||||
import com.tiesheng.util.TimedCacheHelper;
|
|
||||||
import com.tiesheng.util.exception.ApiException;
|
import com.tiesheng.util.exception.ApiException;
|
||||||
|
import com.tiesheng.util.service.TsCacheService;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ public class PlatformDingConfig {
|
|||||||
*/
|
*/
|
||||||
private String getAccessToken(String service) {
|
private String getAccessToken(String service) {
|
||||||
DingConfigBean dingConfigBean = getConfigBean(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)) {
|
if (!StrUtil.isEmpty(accessToken)) {
|
||||||
return accessToken;
|
return accessToken;
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,8 @@ public class PlatformDingConfig {
|
|||||||
String response = HttpUtil.get("https://oapi.dingtalk.com/gettoken", query);
|
String response = HttpUtil.get("https://oapi.dingtalk.com/gettoken", query);
|
||||||
JSONObject respJson = JSONUtil.parseObj(response);
|
JSONObject respJson = JSONUtil.parseObj(response);
|
||||||
accessToken = respJson.getStr("access_token");
|
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;
|
return accessToken;
|
||||||
}
|
}
|
||||||
@@ -120,7 +121,7 @@ public class PlatformDingConfig {
|
|||||||
*/
|
*/
|
||||||
private String getJsapiTicket(String service) {
|
private String getJsapiTicket(String service) {
|
||||||
DingConfigBean dingConfigBean = getConfigBean(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)) {
|
if (StrUtil.isEmpty(jsapiTicket)) {
|
||||||
DingResponse<String> respJson = doRequest(service, "https://oapi.dingtalk.com/get_jsapi_ticket", null,
|
DingResponse<String> respJson = doRequest(service, "https://oapi.dingtalk.com/get_jsapi_ticket", null,
|
||||||
new TypeReference<DingResponse<String>>() {
|
new TypeReference<DingResponse<String>>() {
|
||||||
@@ -129,7 +130,7 @@ public class PlatformDingConfig {
|
|||||||
throw new ApiException(respJson.getErrmsg());
|
throw new ApiException(respJson.getErrmsg());
|
||||||
}
|
}
|
||||||
jsapiTicket = respJson.getTicket();
|
jsapiTicket = respJson.getTicket();
|
||||||
TimedCacheHelper.getTimedCache().put(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(),
|
TsCacheService.of().put(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(),
|
||||||
jsapiTicket, respJson.getExpiresIn());
|
jsapiTicket, respJson.getExpiresIn());
|
||||||
}
|
}
|
||||||
return jsapiTicket;
|
return jsapiTicket;
|
||||||
|
|||||||
@@ -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.WxJsapiSignature;
|
||||||
import com.tiesheng.platform.config.wxmp.bean.WxOAuth2AccessToken;
|
import com.tiesheng.platform.config.wxmp.bean.WxOAuth2AccessToken;
|
||||||
import com.tiesheng.platform.config.wxmp.bean.WxUserInfo;
|
import com.tiesheng.platform.config.wxmp.bean.WxUserInfo;
|
||||||
import com.tiesheng.util.TimedCacheHelper;
|
|
||||||
import com.tiesheng.util.exception.ApiException;
|
import com.tiesheng.util.exception.ApiException;
|
||||||
|
import com.tiesheng.util.service.TsCacheService;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@@ -63,17 +63,17 @@ public class PlatformWxmpConfig {
|
|||||||
*/
|
*/
|
||||||
private String getAccessToken(String service) {
|
private String getAccessToken(String service) {
|
||||||
WxConfigBean configBean = getConfigBean(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)) {
|
if (StrUtil.isEmpty(accessToken)) {
|
||||||
Map<String, Object> query = new HashMap<>(10);
|
Map<String, Object> query = new HashMap<>(10);
|
||||||
query.put("grant_type", "client_credential");
|
query.put("grant_type", "client_credential");
|
||||||
query.put("appid", configBean.getAppId());
|
query.put("appid", configBean.getAppId());
|
||||||
query.put("secret", configBean.getAppSecret());
|
query.put("secret", configBean.getAppSecret());
|
||||||
String response = HttpUtil.get("https://api.weixin.qq.com/cgi-bin/token", query);
|
String response = HttpUtil.get("https://api.weixin.qq.com/cgi-bin/token", query);
|
||||||
LogFactory.get().info("getAccessToken: " + response);
|
|
||||||
JSONObject respJson = JSONUtil.parseObj(response);
|
JSONObject respJson = JSONUtil.parseObj(response);
|
||||||
accessToken = respJson.getStr("access_token");
|
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;
|
return accessToken;
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ public class PlatformWxmpConfig {
|
|||||||
*/
|
*/
|
||||||
private String getJsapiTicket(String service) {
|
private String getJsapiTicket(String service) {
|
||||||
WxConfigBean configBean = getConfigBean(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)) {
|
if (StrUtil.isEmpty(jsapiTicket)) {
|
||||||
Map<String, Object> query = new HashMap<>(10);
|
Map<String, Object> query = new HashMap<>(10);
|
||||||
query.put("access_token", getAccessToken(service));
|
query.put("access_token", getAccessToken(service));
|
||||||
@@ -95,7 +95,8 @@ public class PlatformWxmpConfig {
|
|||||||
LogFactory.get().info("getJsapiTicket: " + response);
|
LogFactory.get().info("getJsapiTicket: " + response);
|
||||||
JSONObject respJson = JSONUtil.parseObj(response);
|
JSONObject respJson = JSONUtil.parseObj(response);
|
||||||
jsapiTicket = respJson.getStr("ticket");
|
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;
|
return jsapiTicket;
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
springboot-poi/.DS_Store
vendored
Normal file
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-poi</artifactId>
|
<artifactId>springboot-poi</artifactId>
|
||||||
|
|||||||
BIN
springboot-role/.DS_Store
vendored
Normal file
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-role</artifactId>
|
<artifactId>springboot-role</artifactId>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.tiesheng.role.controller;
|
package com.tiesheng.role.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@@ -12,7 +13,6 @@ import com.tiesheng.role.pojos.vo.GroupTypeDTO;
|
|||||||
import com.tiesheng.role.pojos.vo.RoleUserPageVO;
|
import com.tiesheng.role.pojos.vo.RoleUserPageVO;
|
||||||
import com.tiesheng.role.pojos.vo.ServiceMenuVO;
|
import com.tiesheng.role.pojos.vo.ServiceMenuVO;
|
||||||
import com.tiesheng.role.service.CoreRoleService;
|
import com.tiesheng.role.service.CoreRoleService;
|
||||||
import com.tiesheng.util.config.TsTokenConfig;
|
|
||||||
import com.tiesheng.util.exception.ApiException;
|
import com.tiesheng.util.exception.ApiException;
|
||||||
import com.tiesheng.util.pojos.ApiResp;
|
import com.tiesheng.util.pojos.ApiResp;
|
||||||
import com.tiesheng.util.pojos.IdDTO;
|
import com.tiesheng.util.pojos.IdDTO;
|
||||||
@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -43,6 +44,7 @@ public class RoleController {
|
|||||||
public ApiResp<List<CoreRoleGroup>> groupList(@Valid GroupTypeDTO dto) {
|
public ApiResp<List<CoreRoleGroup>> groupList(@Valid GroupTypeDTO dto) {
|
||||||
return ApiResp.respOK(coreRoleService.list(
|
return ApiResp.respOK(coreRoleService.list(
|
||||||
new QueryWrapper<CoreRoleGroup>()
|
new QueryWrapper<CoreRoleGroup>()
|
||||||
|
.eq("is_deleted", 0)
|
||||||
.eq("type", dto.getType())
|
.eq("type", dto.getType())
|
||||||
.orderByAsc("sort")
|
.orderByAsc("sort")
|
||||||
));
|
));
|
||||||
@@ -248,15 +250,18 @@ public class RoleController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/owner/server")
|
@GetMapping("/owner/server")
|
||||||
public ApiResp<List<CoreRoleServer>> ownerServer() {
|
public ApiResp<List<CoreRoleServer>> ownerServer(TokenBean tokenBean) {
|
||||||
TokenBean tokenBean = TsTokenConfig.get();
|
|
||||||
List<CoreRoleAuthority> allOwnerMenus = coreRoleService.getOwnerAuthorityLeafList(tokenBean.getId(), tokenBean.getRoleId());
|
List<CoreRoleAuthority> allOwnerMenus = coreRoleService.getOwnerAuthorityLeafList(tokenBean.getId(), tokenBean.getRoleId());
|
||||||
|
List<String> list = allOwnerMenus.stream().map(CoreRoleAuthority::getService).collect(Collectors.toList());
|
||||||
|
|
||||||
List<CoreRoleServer> roleServerList = coreRoleService.getServerMapper().selectList(new QueryWrapper<CoreRoleServer>()
|
List<CoreRoleServer> roleServerList = new ArrayList<>();
|
||||||
.in("id", allOwnerMenus.stream().map(CoreRoleAuthority::getService).collect(Collectors.toList()))
|
if (CollUtil.isNotEmpty(list)) {
|
||||||
.eq(CoreRoleServer.IS_DELETED, 0)
|
roleServerList = coreRoleService.getServerMapper().selectList(new QueryWrapper<CoreRoleServer>()
|
||||||
.eq("is_open", 1)
|
.in("id", list)
|
||||||
);
|
.eq(CoreRoleServer.IS_DELETED, 0)
|
||||||
|
.eq("is_open", 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return ApiResp.respOK(roleServerList);
|
return ApiResp.respOK(roleServerList);
|
||||||
}
|
}
|
||||||
@@ -268,11 +273,8 @@ public class RoleController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/owner/menu")
|
@GetMapping("/owner/menu")
|
||||||
public ApiResp<List<ServiceMenuVO>> ownerMenu(@Valid OwnerMenuDTO dto) {
|
public ApiResp<List<ServiceMenuVO>> ownerMenu(TokenBean tokenBean, @Valid OwnerMenuDTO dto) {
|
||||||
|
|
||||||
TokenBean tokenBean = TsTokenConfig.get();
|
|
||||||
List<ServiceMenuVO> ownerMenus = coreRoleService.getOwnerMenus(tokenBean.getId(), tokenBean.getRoleId(), dto);
|
List<ServiceMenuVO> ownerMenus = coreRoleService.getOwnerMenus(tokenBean.getId(), tokenBean.getRoleId(), dto);
|
||||||
|
|
||||||
return ApiResp.respOK(ownerMenus);
|
return ApiResp.respOK(ownerMenus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,9 +284,8 @@ public class RoleController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/owner/point")
|
@GetMapping("/owner/point")
|
||||||
public ApiResp<List<CoreRoleAuthority>> ownerPoint(@Valid OwnerPointDTO dto) {
|
public ApiResp<List<CoreRoleAuthority>> ownerPoint(TokenBean tokenBean, @Valid OwnerPointDTO dto) {
|
||||||
|
|
||||||
TokenBean tokenBean = TsTokenConfig.get();
|
|
||||||
List<CoreRoleAuthority> allOwnerMenus = coreRoleService.getOwnerAuthorityLeafList(tokenBean.getId(), tokenBean.getRoleId());
|
List<CoreRoleAuthority> allOwnerMenus = coreRoleService.getOwnerAuthorityLeafList(tokenBean.getId(), tokenBean.getRoleId());
|
||||||
|
|
||||||
String parentId;
|
String parentId;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import com.tiesheng.role.pojos.dao.CoreRoleAuthority;
|
|||||||
import com.tiesheng.role.pojos.dao.CoreRoleGroup;
|
import com.tiesheng.role.pojos.dao.CoreRoleGroup;
|
||||||
import com.tiesheng.role.pojos.dao.CoreRoleGroupRx;
|
import com.tiesheng.role.pojos.dao.CoreRoleGroupRx;
|
||||||
import com.tiesheng.role.pojos.dto.GroupRxUpdateDTO;
|
import com.tiesheng.role.pojos.dto.GroupRxUpdateDTO;
|
||||||
import com.tiesheng.role.pojos.dto.MenuListDTO;
|
|
||||||
import com.tiesheng.role.pojos.dto.OwnerMenuDTO;
|
import com.tiesheng.role.pojos.dto.OwnerMenuDTO;
|
||||||
import com.tiesheng.role.pojos.vo.ServiceMenuVO;
|
import com.tiesheng.role.pojos.vo.ServiceMenuVO;
|
||||||
import com.tiesheng.util.service.TsServiceBase;
|
import com.tiesheng.util.service.TsServiceBase;
|
||||||
@@ -17,7 +16,10 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -96,7 +98,10 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
|||||||
coreRoleGroupRx.setMenuId(menuId);
|
coreRoleGroupRx.setMenuId(menuId);
|
||||||
list.add(coreRoleGroupRx);
|
list.add(coreRoleGroupRx);
|
||||||
}
|
}
|
||||||
coreRoleGroupRxMapper.batchInsert(list);
|
|
||||||
|
if (CollUtil.isNotEmpty(list)) {
|
||||||
|
coreRoleGroupRxMapper.batchInsert(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
BIN
springboot-util/.DS_Store
vendored
Normal file
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.0.rc2</version>
|
<version>2.0.0.rc8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-util</artifactId>
|
<artifactId>springboot-util</artifactId>
|
||||||
@@ -68,6 +68,17 @@
|
|||||||
<version>1.68</version>
|
<version>1.68</version>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -8,8 +8,8 @@ import cn.hutool.crypto.SecureUtil;
|
|||||||
import cn.hutool.crypto.SmUtil;
|
import cn.hutool.crypto.SmUtil;
|
||||||
import cn.hutool.crypto.symmetric.SM4;
|
import cn.hutool.crypto.symmetric.SM4;
|
||||||
import com.tiesheng.util.ServletKit;
|
import com.tiesheng.util.ServletKit;
|
||||||
import com.tiesheng.util.TimedCacheHelper;
|
|
||||||
import com.tiesheng.util.exception.ApiException;
|
import com.tiesheng.util.exception.ApiException;
|
||||||
|
import com.tiesheng.util.service.TsCacheService;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@@ -104,12 +104,12 @@ public class EncryptConfig {
|
|||||||
String salt = decrypt(encrypted).substring(0, saltSize);
|
String salt = decrypt(encrypted).substring(0, saltSize);
|
||||||
String inputEncrypted = passwdCreate(inputPasswd, salt);
|
String inputEncrypted = passwdCreate(inputPasswd, salt);
|
||||||
if (!StrUtil.equals(inputEncrypted, encrypted)) {
|
if (!StrUtil.equals(inputEncrypted, encrypted)) {
|
||||||
String clientIp = ServletKit.getClientIP();
|
String clientIp = "passwdVerify_" + ServletKit.getClientIP();
|
||||||
int num = NumberUtil.parseInt(TimedCacheHelper.getTimedCache().get(clientIp, false));
|
int num = NumberUtil.parseInt(TsCacheService.of().get(clientIp, -1));
|
||||||
if (num > 5) {
|
if (num > 5) {
|
||||||
throw new ApiException("登录失败已达6次,请10分钟后再试");
|
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("账号或密码错误");
|
throw new ApiException("账号或密码错误");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ package com.tiesheng.util.config;
|
|||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import cn.hutool.jwt.JWT;
|
import cn.hutool.jwt.JWT;
|
||||||
import cn.hutool.jwt.JWTValidator;
|
import cn.hutool.jwt.JWTValidator;
|
||||||
import com.tiesheng.util.ServletKit;
|
|
||||||
import com.tiesheng.util.exception.ApiException;
|
import com.tiesheng.util.exception.ApiException;
|
||||||
import com.tiesheng.util.pojos.TokenBean;
|
import com.tiesheng.util.pojos.TokenBean;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
@@ -23,6 +23,11 @@ import java.util.Map;
|
|||||||
@ConfigurationProperties("tiesheng.token")
|
@ConfigurationProperties("tiesheng.token")
|
||||||
public class TsTokenConfig {
|
public class TsTokenConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token常量
|
||||||
|
*/
|
||||||
|
public static final String TOKEN_KEY = "token";
|
||||||
|
|
||||||
private Map<String, TokenBean> testMap = MapUtil.newHashMap();
|
private Map<String, TokenBean> testMap = MapUtil.newHashMap();
|
||||||
private String encryptKey = "%kIp9frQCu";
|
private String encryptKey = "%kIp9frQCu";
|
||||||
private Integer expireHours = 48;
|
private Integer expireHours = 48;
|
||||||
@@ -30,28 +35,6 @@ public class TsTokenConfig {
|
|||||||
private boolean validLoginSign = false;
|
private boolean validLoginSign = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前登录的token
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static TokenBean get() {
|
|
||||||
TsTokenConfig tokenConfig = SpringUtil.getBean(TsTokenConfig.class);
|
|
||||||
return tokenConfig.validToken(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前登录的token
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static TokenBean getWithoutThr() {
|
|
||||||
TsTokenConfig tokenConfig = SpringUtil.getBean(TsTokenConfig.class);
|
|
||||||
return tokenConfig.validToken(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证token
|
* 验证token
|
||||||
*
|
*
|
||||||
@@ -72,8 +55,8 @@ public class TsTokenConfig {
|
|||||||
* @param thrExp
|
* @param thrExp
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public TokenBean validToken(boolean thrExp) {
|
public TokenBean validToken(HttpServletRequest request, boolean thrExp) {
|
||||||
String token = ServletUtil.getHeader(ServletKit.getRequest(), "token", "utf-8");
|
String token = ServletUtil.getHeader(request, TOKEN_KEY, "utf-8");
|
||||||
return validToken(token, thrExp);
|
return validToken(token, thrExp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,14 +75,7 @@ public class TsTokenConfig {
|
|||||||
try {
|
try {
|
||||||
JWT decode = JWT.of(token);
|
JWT decode = JWT.of(token);
|
||||||
JWTValidator.of(decode).validateDate();
|
JWTValidator.of(decode).validateDate();
|
||||||
String id = decode.getPayload("id").toString();
|
tokenBean = JSONUtil.toBean(decode.getPayloads(), TokenBean.class);
|
||||||
String environmentType = decode.getPayload("environmentType").toString();
|
|
||||||
String service = decode.getPayload("service").toString();
|
|
||||||
String extra = StrUtil.toStringOrNull(decode.getPayload("extra"));
|
|
||||||
String roleId = StrUtil.toStringOrNull(decode.getPayload("roleId"));
|
|
||||||
tokenBean = new TokenBean(id, environmentType, service);
|
|
||||||
tokenBean.setRoleId(roleId);
|
|
||||||
tokenBean.setExtra(extra);
|
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
17
springboot-util/src/main/java/com/tiesheng/util/service/cache/TsCacheHandler.java
vendored
Normal 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);
|
||||||
|
|
||||||
|
}
|
||||||
56
springboot-util/src/main/java/com/tiesheng/util/service/cache/TsCacheRedisHandler.java
vendored
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
67
springboot-util/src/main/java/com/tiesheng/util/service/cache/TsCacheTimedHandler.java
vendored
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||