Compare commits
3 Commits
2.0.0.rc24
...
zjut/1.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70c6d7568e | ||
|
|
051e7a063b | ||
|
|
345d99e6a9 |
25
.gitea/workflows/mvn-deploy.yaml
Normal file
@@ -0,0 +1,25 @@
|
||||
## 工作流触发时机
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
|
||||
## 任务名称
|
||||
local-deploy:
|
||||
|
||||
## 任务执行的服务器
|
||||
runs-on: tiesheng-local
|
||||
|
||||
## 任务步骤
|
||||
steps:
|
||||
|
||||
## 检出代码(固定配置)
|
||||
- name: Check out repository code
|
||||
uses: https://git.tieshengkeji.com/actions/checkout@v4
|
||||
|
||||
## maven打包
|
||||
- name: Maven deploy
|
||||
run: |
|
||||
mvn deploy
|
||||
93
CHANGELOG.md
@@ -1,7 +1,94 @@
|
||||
## 2.0.0.rc4
|
||||
## 1.1.0
|
||||
|
||||
- perf:TsTokenConfig不在提供静态方法
|
||||
- perf:移除TsTokenAspect,由TokenWebMvcConfigurer替代,并实现TokenBean参数注入
|
||||
- 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**;
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
## 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**;
|
||||
38
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>springboot-parent</name>
|
||||
<description>杭州铁晟科技有限公司基础依赖</description>
|
||||
@@ -28,7 +28,6 @@
|
||||
<module>springboot-message</module>
|
||||
<module>springboot-encrypt</module>
|
||||
<module>springboot-annotation</module>
|
||||
<module>springboot-role</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
@@ -58,61 +57,55 @@
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-database</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-login</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-web</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-util</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-platform</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-message</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-encrypt</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-role</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-poi</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -130,10 +123,17 @@
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>gitea</id>
|
||||
<url>https://git.tieshengkeji.com/api/packages/tieshengkeji/maven</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>kepai-repo-plugin</id>
|
||||
<url>http://git.kepai365.com/tiesheng/repository/raw/master</url>
|
||||
<id>tiesheng-repo-plugin</id>
|
||||
<url>https://git.tieshengkeji.com/api/packages/tieshengkeji/maven</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
|
||||
BIN
springboot-ademo/.DS_Store
vendored
@@ -6,11 +6,11 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-ademo</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
@@ -26,22 +26,11 @@
|
||||
<artifactId>springboot-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-role</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>3.7.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.tiesheng.demo;
|
||||
|
||||
|
||||
import com.tiesheng.web.EnableTieshengWeb;
|
||||
import com.tiesheng.core.EnableTieshengWeb;
|
||||
import com.tiesheng.demo.config.DemoWebConfigurer;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -13,6 +13,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
@EnableTransactionManagement
|
||||
@SpringBootApplication
|
||||
@EnableTieshengWeb(webConfigurer = DemoWebConfigurer.class)
|
||||
//@EnableEncryptConfig
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.tiesheng.demo.config;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.tiesheng.login.pojos.RequestUserInfo;
|
||||
import com.tiesheng.login.pojos.dao.CorePlatformUnique;
|
||||
import com.tiesheng.login.service.TsLoginConfigurer;
|
||||
import com.tiesheng.core.pojos.RequestUserInfo;
|
||||
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
|
||||
import com.tiesheng.core.service.TieshengWebConfigurer;
|
||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||
import com.tiesheng.util.config.GlobalConfig;
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
import com.tiesheng.web.service.TieshengWebConfigurer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -14,31 +13,24 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
public class DemoWebConfigurer implements TieshengWebConfigurer, TsLoginConfigurer {
|
||||
public class DemoWebConfigurer implements TieshengWebConfigurer {
|
||||
|
||||
@Autowired
|
||||
GlobalConfig globalConfig;
|
||||
|
||||
|
||||
@Override
|
||||
public RequestUserInfo getCurrentUserName(TokenBean tokenBean) {
|
||||
RequestUserInfo info = new RequestUserInfo();
|
||||
if (Objects.equals(tokenBean.getId(), "1")) {
|
||||
return info;
|
||||
}
|
||||
info.setId("1");
|
||||
info.setName("test");
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenBean login(CorePlatformUnique platformUnique) {
|
||||
TokenBean tokenBean = null;
|
||||
if (!StrUtil.isEmpty(platformUnique.getUserId())) {
|
||||
tokenBean = new TokenBean(platformUnique.getUserId(), "super");
|
||||
} else if (Objects.equals(platformUnique.getUniqueId(), "1110290049")) {
|
||||
tokenBean = new TokenBean("1", "super");
|
||||
}
|
||||
|
||||
if (tokenBean != null) {
|
||||
tokenBean.setExtra("1110290049");
|
||||
tokenBean = new TokenBean(platformUnique.getUserId(), "", globalConfig.getService());
|
||||
}
|
||||
|
||||
return tokenBean;
|
||||
@@ -47,11 +39,13 @@ public class DemoWebConfigurer implements TieshengWebConfigurer, TsLoginConfigur
|
||||
@Override
|
||||
public void redirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
|
||||
|
||||
// 默认跳转到mobile
|
||||
to = StrUtil.emptyToDefault(to, "mobile");
|
||||
bean.setEnvironmentType(to);
|
||||
|
||||
if (Objects.equals(bean.getEnvironmentType(), "mobile")) {
|
||||
globalConfig.redirect("mobile", "/?token=" + bean.toToken(), response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TsLoginConfigurer configureLogin() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.tiesheng.demo.config;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Component
|
||||
public class DemoWebMvcConfigurer implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/mobile/**").addResourceLocations("classpath:/mobile/0.0.13/");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.tiesheng.demo.config;
|
||||
|
||||
|
||||
import com.tiesheng.web.service.CoreConfigService;
|
||||
import com.tiesheng.core.service.CoreConfigService;
|
||||
import com.tiesheng.core.service.CoreJobService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -13,11 +14,19 @@ import javax.annotation.PostConstruct;
|
||||
@Component
|
||||
public class TestJobConfig {
|
||||
|
||||
@Autowired
|
||||
CoreJobService coreJobService;
|
||||
@Autowired
|
||||
CoreConfigService coreConfigService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
coreConfigService.refreshFunc("230328001", "demo", "辅导员统计", "辅导员责任班级,学生展示");
|
||||
|
||||
// 辅导员职位
|
||||
coreJobService.refresh("class_fdy", "辅导员", "辅导员", 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,45 +2,42 @@ package com.tiesheng.demo.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.read.listener.ReadListener;
|
||||
import com.tiesheng.annotation.role.RoleAuthority;
|
||||
import com.tiesheng.annotation.operation.OperationLog;
|
||||
import com.tiesheng.annotation.token.TokenIgnore;
|
||||
import com.tiesheng.core.service.CoreLogService;
|
||||
import com.tiesheng.core.service.CoreMessageService;
|
||||
import com.tiesheng.core.util.ProcessImportConsumer;
|
||||
import com.tiesheng.database.config.DbBackupConfig;
|
||||
import com.tiesheng.demo.pojos.PoiBean;
|
||||
import com.tiesheng.demo.pojos.TestFile;
|
||||
import com.tiesheng.platform.config.ding.PlatformDingConfig;
|
||||
import com.tiesheng.platform.config.ding.bean.DingUserInfo;
|
||||
import com.tiesheng.login.config.token.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.util.ProcessImportConsumer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
@RoleAuthority(value = "test", group = "test")
|
||||
public class TestController {
|
||||
|
||||
@Autowired
|
||||
@@ -52,75 +49,60 @@ public class TestController {
|
||||
@Autowired
|
||||
EncryptConfig encryptConfig;
|
||||
@Autowired
|
||||
CoreMessageService coreMessageService;
|
||||
@Autowired
|
||||
CoreLogService coreLogService;
|
||||
@Autowired
|
||||
DbBackupConfig dbBackupConfig;
|
||||
@Autowired
|
||||
TsCacheService tsCacheService;
|
||||
@Autowired
|
||||
PlatformDingConfig platformDingConfig;
|
||||
|
||||
|
||||
@RequestMapping("/index")
|
||||
@TokenIgnore
|
||||
public void index(HttpServletResponse response) {
|
||||
globalConfig.redirect("mobile", "/test", response);
|
||||
public ApiResp<String> index() {
|
||||
dbBackupConfig.dbBackup();
|
||||
return ApiResp.respOK("hello world");
|
||||
}
|
||||
|
||||
@RequestMapping("/redirect")
|
||||
@TokenIgnore
|
||||
@RoleAuthority("redirect")
|
||||
public ApiResp<String> redirect(HttpServletResponse response) {
|
||||
public void redirect(HttpServletResponse response) {
|
||||
|
||||
// ArrayList<String> strings = CollUtil.newArrayList("11111", "22222");
|
||||
// coreLogService.addProcess("fdfd", strings, new ProcessImportConsumer<String>() {
|
||||
// @Override
|
||||
// public int accept(List<String> list) {
|
||||
// LogFactory.get().info("list: " + list.size());
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getFailFile() {
|
||||
// LogFactory.get().info("getFailFile: " + strings.size());
|
||||
// return null;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// LogFactory.get().info("strings: " + strings.size());
|
||||
ArrayList<String> strings = CollUtil.newArrayList("11111", "22222");
|
||||
coreLogService.addProcess("fdfd", strings, new ProcessImportConsumer<String>() {
|
||||
@Override
|
||||
public int accept(List<String> list) {
|
||||
LogFactory.get().info("list: " + list.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFailFile() {
|
||||
LogFactory.get().info("getFailFile: " + strings.size());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
LogFactory.get().info("strings: " + strings.size());
|
||||
|
||||
|
||||
// tsTokenConfig.validToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzYwMDY4NzUsImlkIjoiMSIsImVudmlyb25tZW50VHlwZSI6Im1vYmlsZSIsInNlcnZpY2UiOiJjb250ZXN0LXJlc2VydmUiLCJleHRyYSI6IiJ9.nsfxEFpCNHC7eNCS5DJXdu1VDdnHrTjSfgrozND70Lc", true);
|
||||
// globalConfig.redirect("mobile", "/test", response);
|
||||
return ApiResp.respOK("");
|
||||
globalConfig.redirect("mobile", "/test", response);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/send")
|
||||
@TokenIgnore
|
||||
public ApiResp<String> sendMessage() {
|
||||
public ApiResp<MessageReqResp> sendMessage() {
|
||||
|
||||
// MessageReqResp reqResp = coreMessageService.send(new UserChannel("13567116463", "sms"),
|
||||
// JSONUtil.createObj().putOpt("action", "sms-visitor-invite"));
|
||||
MessageReqResp reqResp = coreMessageService.send(new UserChannel("13567116463", "sms"),
|
||||
JSONUtil.createObj().putOpt("code", "123456").putOpt("template_code", "SMS_154950909"));
|
||||
|
||||
return ApiResp.respOK(null);
|
||||
return ApiResp.respOK(reqResp);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/export")
|
||||
@TokenIgnore
|
||||
public ApiResp<String> export() {
|
||||
|
||||
// tsCacheService.put("fdfhdfd", "fdfdfdfd");
|
||||
// String s = tsCacheService.get("fdfhdfd");
|
||||
// LogFactory.get().info("export: " + s);
|
||||
|
||||
platformDingConfig.syncDeptUser("", null, new Consumer<DingUserInfo>() {
|
||||
@Override
|
||||
public void accept(DingUserInfo dingUserInfo) {
|
||||
}
|
||||
});
|
||||
|
||||
// List<TestFile> list = new ArrayList<>();
|
||||
// list.add(new TestFile("11111"));
|
||||
// list.add(new TestFile("22222"));
|
||||
@@ -141,13 +123,14 @@ public class TestController {
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("searchIP")
|
||||
@RequestMapping("searchIP")
|
||||
@TokenIgnore
|
||||
public ApiResp<String> searchIp() {
|
||||
String search = ip2regionConfig.search("127.0.0.1");
|
||||
return ApiResp.respOK(search);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("desensitize")
|
||||
@TokenIgnore
|
||||
public ApiResp<List<TestFile>> desensitize() {
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.tiesheng.demo.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.tiesheng.message.config.aliyun.AliyunSmsHandler;
|
||||
import com.tiesheng.message.config.aliyun.AliyunTempParam;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class DemoSmsHandler implements AliyunSmsHandler {
|
||||
|
||||
@Override
|
||||
public AliyunTempParam handler(JSONObject obj) {
|
||||
|
||||
String action = obj.getStr("action");
|
||||
|
||||
AliyunTempParam param = new AliyunTempParam();
|
||||
param.setSignName("智慧校园");
|
||||
|
||||
if (Objects.equals(action, "sms-visitor-invite")) {
|
||||
param.setTemplateCode("SMS_276125463");
|
||||
param.setTemplateParam(JSONUtil.createObj()
|
||||
.putOpt("date", DateUtil.today())
|
||||
);
|
||||
}
|
||||
|
||||
return param;
|
||||
}
|
||||
}
|
||||
@@ -7,16 +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:
|
||||
ding:
|
||||
global:
|
||||
corpId: dingebe664cb3baf3a52a39a90f97fcb1e09
|
||||
agentId: 2474444028
|
||||
appKey: dingyvf1niiajfaajyo5
|
||||
appSecret: y6SGZ4fvPbdbj4RVbDWLeMBkGgplaOdnTA_9wN5TDdOV_Y47alYc1LDlIHjsBJE1
|
||||
wxmp:
|
||||
global:
|
||||
app-id: wxa0343fe519824651
|
||||
@@ -26,14 +18,11 @@ tiesheng:
|
||||
token:
|
||||
test-map:
|
||||
"1111":
|
||||
id: "1"
|
||||
role-id: "1822829641023524865"
|
||||
id: "1111"
|
||||
global:
|
||||
version: 2
|
||||
host: http://localhost:8100
|
||||
service: yrx
|
||||
aliyun:
|
||||
access-key-id: LTAI5tJtbgBCnTY5eS4SmrTf
|
||||
access-key-secret: JIHqpRUFffCHhXaJEVvWN31WcexWqG
|
||||
encrypt:
|
||||
body: false
|
||||
sign-name: 阿里云短信测试
|
||||
|
||||
@@ -9,13 +9,18 @@ spring:
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 20MB
|
||||
max-request-size: 20MB
|
||||
web:
|
||||
resources:
|
||||
static-locations: classpath:/static/,file:static/
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
|
||||
## 日志
|
||||
logging:
|
||||
file:
|
||||
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
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.tiesheng.annotation.role;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface RoleAuthority {
|
||||
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String value();
|
||||
|
||||
/**
|
||||
* 平台类型
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String platform() default "web";
|
||||
|
||||
|
||||
/**
|
||||
* 分组
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String[] group() default {};
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.tiesheng.annotation.role;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.METHOD})
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface RoleIgnore {
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-database</artifactId>
|
||||
|
||||
BIN
springboot-encrypt/.DS_Store
vendored
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-encrypt</artifactId>
|
||||
|
||||
BIN
springboot-login/.DS_Store
vendored
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-login</artifactId>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.tiesheng.login;
|
||||
|
||||
import com.tiesheng.platform.PlatformAutoConfigurer;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
|
||||
@ComponentScan({
|
||||
"com.tiesheng.login.**.*",
|
||||
})
|
||||
@Import(PlatformAutoConfigurer.class)
|
||||
public class LoginAutoConfigurer {
|
||||
}
|
||||
@@ -1,121 +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.login.pojos.RequestUserInfo;
|
||||
import com.tiesheng.login.service.TsLoginConfigurer;
|
||||
import com.tiesheng.util.config.TsTokenConfig;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
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;
|
||||
@Resource
|
||||
TsLoginConfigurer tsLoginConfigurer;
|
||||
|
||||
@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是否存在
|
||||
TokenBean tokenBean = tsTokenConfig.validToken(request, true);
|
||||
|
||||
// 验证用户是否存在
|
||||
RequestUserInfo cachedUserInfo = tsLoginConfigurer.getCachedUserInfo(tokenBean);
|
||||
if (cachedUserInfo == null) {
|
||||
throw new ApiException("非法TOKEN,请重新登录");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.tiesheng.login.config.token;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.tiesheng.annotation.token.TokenIgnore;
|
||||
import com.tiesheng.util.ServletKit;
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
package com.tiesheng.util.config;
|
||||
package com.tiesheng.login.config.token;
|
||||
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.jwt.JWT;
|
||||
import cn.hutool.jwt.JWTValidator;
|
||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||
import com.tiesheng.util.ServletKit;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -23,17 +23,6 @@ import java.util.Map;
|
||||
@ConfigurationProperties("tiesheng.token")
|
||||
public class TsTokenConfig {
|
||||
|
||||
/**
|
||||
* 用户登录的KEY
|
||||
*/
|
||||
public static String CACHE_REQUEST_LOGIN_KEY = "CACHE:LOGIN:{}";
|
||||
|
||||
|
||||
/**
|
||||
* token常量
|
||||
*/
|
||||
public static final String TOKEN_KEY = "token";
|
||||
|
||||
private Map<String, TokenBean> testMap = MapUtil.newHashMap();
|
||||
private String encryptKey = "%kIp9frQCu";
|
||||
private Integer expireHours = 48;
|
||||
@@ -41,6 +30,28 @@ public class TsTokenConfig {
|
||||
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
|
||||
*
|
||||
@@ -61,8 +72,8 @@ public class TsTokenConfig {
|
||||
* @param thrExp
|
||||
* @return
|
||||
*/
|
||||
public TokenBean validToken(HttpServletRequest request, boolean thrExp) {
|
||||
String token = ServletUtil.getHeader(request, TOKEN_KEY, "utf-8");
|
||||
public TokenBean validToken(boolean thrExp) {
|
||||
String token = ServletUtil.getHeader(ServletKit.getRequest(), "token", "utf-8");
|
||||
return validToken(token, thrExp);
|
||||
}
|
||||
|
||||
@@ -81,11 +92,16 @@ public class TsTokenConfig {
|
||||
try {
|
||||
JWT decode = JWT.of(token);
|
||||
JWTValidator.of(decode).validateDate();
|
||||
tokenBean = JSONUtil.toBean(decode.getPayloads(), TokenBean.class);
|
||||
String id = decode.getPayload("id").toString();
|
||||
String environmentType = decode.getPayload("environmentType").toString();
|
||||
String service = decode.getPayload("service").toString();
|
||||
String extra = decode.getPayload("extra").toString();
|
||||
tokenBean = new TokenBean(id, environmentType, service);
|
||||
tokenBean.setExtra(extra);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
if ((tokenBean == null || StrUtil.isEmpty(tokenBean.getId())) && thrExp) {
|
||||
if (tokenBean == null && thrExp) {
|
||||
throw new ApiException(StrUtil.isEmpty(token) ? 110 : 112,
|
||||
StrUtil.isEmpty(token) ? "请先登录" : "登录过期,请重新登陆");
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.tiesheng.util.pojos;
|
||||
package com.tiesheng.login.config.token.bean;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.jwt.JWT;
|
||||
import com.tiesheng.util.config.TsTokenConfig;
|
||||
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
@@ -12,15 +12,17 @@ import com.tiesheng.util.config.TsTokenConfig;
|
||||
public class TokenBean {
|
||||
|
||||
private String id;
|
||||
private String roleId;
|
||||
private String environmentType;
|
||||
private String service;
|
||||
private String extra;
|
||||
|
||||
public TokenBean() {
|
||||
}
|
||||
|
||||
public TokenBean(String id, String roleId) {
|
||||
public TokenBean(String id, String environmentType, String service) {
|
||||
this.id = id;
|
||||
this.roleId = roleId;
|
||||
this.environmentType = environmentType;
|
||||
this.service = service;
|
||||
this.extra = "";
|
||||
}
|
||||
|
||||
@@ -33,7 +35,8 @@ public class TokenBean {
|
||||
return JWT.create()
|
||||
.setExpiresAt(DateUtil.offsetHour(DateUtil.date(), tsTokenConfig.getExpireHours()))
|
||||
.setPayload("id", getId())
|
||||
.setPayload("roleId", StrUtil.emptyToDefault(getRoleId(), ""))
|
||||
.setPayload("environmentType", StrUtil.emptyToDefault(getEnvironmentType(), ""))
|
||||
.setPayload("service", StrUtil.emptyToDefault(getService(), ""))
|
||||
.setPayload("extra", StrUtil.emptyToDefault(getExtra(), ""))
|
||||
.setKey(tsTokenConfig.getEncryptKey().getBytes())
|
||||
.sign();
|
||||
@@ -51,6 +54,22 @@ public class TokenBean {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEnvironmentType() {
|
||||
return environmentType;
|
||||
}
|
||||
|
||||
public void setEnvironmentType(String environmentType) {
|
||||
this.environmentType = environmentType;
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public String getExtra() {
|
||||
return extra;
|
||||
}
|
||||
@@ -58,12 +77,4 @@ public class TokenBean {
|
||||
public void setExtra(String extra) {
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
public String getRoleId() {
|
||||
return roleId;
|
||||
}
|
||||
|
||||
public void setRoleId(String roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,13 @@ import cn.hutool.core.util.URLUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.tiesheng.annotation.operation.OperationIgnore;
|
||||
import com.tiesheng.annotation.token.TokenIgnore;
|
||||
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||
import com.tiesheng.login.pojos.CodeExtraDTO;
|
||||
import com.tiesheng.login.pojos.DoLoginInfo;
|
||||
import com.tiesheng.login.pojos.UniqueIndexDTO;
|
||||
import com.tiesheng.login.pojos.WxminiLoginVo;
|
||||
import com.tiesheng.login.service.CorePlatformUniqueService;
|
||||
import com.tiesheng.login.service.TieshengLoginConfigurer;
|
||||
import com.tiesheng.platform.config.ding.PlatformDingConfig;
|
||||
import com.tiesheng.platform.config.ding.bean.DingJsapiSignature;
|
||||
import com.tiesheng.platform.config.ding.bean.DingUserInfo;
|
||||
@@ -21,10 +23,8 @@ import com.tiesheng.platform.config.wxmp.bean.WxConfigBean;
|
||||
import com.tiesheng.platform.config.wxmp.bean.WxJsapiSignature;
|
||||
import com.tiesheng.platform.config.wxmp.bean.WxUserInfo;
|
||||
import com.tiesheng.util.config.GlobalConfig;
|
||||
import com.tiesheng.util.config.TsTokenConfig;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class LoginController {
|
||||
@Autowired
|
||||
PlatformWxminiConfig platformWxminiConfig;
|
||||
@Autowired
|
||||
CorePlatformUniqueService corePlatformUniqueService;
|
||||
TieshengLoginConfigurer tieshengLoginConfigurer;
|
||||
@Autowired
|
||||
GlobalConfig globalConfig;
|
||||
@Autowired
|
||||
@@ -65,13 +65,13 @@ public class LoginController {
|
||||
@OperationIgnore
|
||||
public void uniqueIndex(UniqueIndexDTO dto, HttpServletResponse response) {
|
||||
if (tsTokenConfig.isValidLoginSign() && !dto.validSign()) {
|
||||
corePlatformUniqueService.onSignError(response);
|
||||
tieshengLoginConfigurer.onSignError(response);
|
||||
return;
|
||||
}
|
||||
|
||||
TokenBean tokenBean = corePlatformUniqueService.login(new DoLoginInfo("web_unique_redirect",
|
||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("web_unique_redirect",
|
||||
dto.getNo(), dto.getPlatform(), dto.getInfo()));
|
||||
corePlatformUniqueService.redirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class LoginController {
|
||||
@PostMapping("/unique/index")
|
||||
@OperationIgnore
|
||||
public ApiResp<String> uniqueIndex(@RequestBody UniqueIndexDTO dto) {
|
||||
TokenBean tokenBean = corePlatformUniqueService.login(new DoLoginInfo("web_unique_index",
|
||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("web_unique_index",
|
||||
dto.getNo(), dto.getPlatform(), dto.getInfo()));
|
||||
if (tokenBean == null || StrUtil.isEmpty(tokenBean.getId())) {
|
||||
throw new ApiException("登录失败");
|
||||
@@ -134,9 +134,9 @@ public class LoginController {
|
||||
public void dingOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
|
||||
DingUserSimple userSimple = platformDingConfig.getUserIdByCode(service, dto.getCode());
|
||||
DingUserInfo dingUserInfo = platformDingConfig.topapiV2UserGet(service, userSimple.getUserid());
|
||||
TokenBean tokenBean = corePlatformUniqueService.login(new DoLoginInfo(dingUserInfo.getAppId(),
|
||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(dingUserInfo.getAppId(),
|
||||
dingUserInfo.getUserid(), "ding", JSON.toJSONString(dingUserInfo)));
|
||||
corePlatformUniqueService.redirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,9 +182,9 @@ public class LoginController {
|
||||
@OperationIgnore
|
||||
public void wxmpOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
|
||||
WxUserInfo wxUserInfo = platformWxmpConfig.getOAuth2AccessToken(service, dto.getCode());
|
||||
TokenBean tokenBean = corePlatformUniqueService.login(new DoLoginInfo(wxUserInfo.getAppId(),
|
||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(wxUserInfo.getAppId(),
|
||||
wxUserInfo.getOpenid(), "wxmp", JSON.toJSONString(wxUserInfo)));
|
||||
corePlatformUniqueService.redirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ public class LoginController {
|
||||
public ApiResp<WxminiLoginVo> wxminiIndex(@PathVariable String service, String code) {
|
||||
String openid = platformWxminiConfig.jscode2session(service, code);
|
||||
WxConfigBean configBean = platformWxminiConfig.getConfigBean(service);
|
||||
TokenBean tokenBean = corePlatformUniqueService.login(new DoLoginInfo(configBean.getAppId(),
|
||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(configBean.getAppId(),
|
||||
openid, "wxmini", "{}"));
|
||||
|
||||
WxminiLoginVo loginVo = new WxminiLoginVo();
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
package com.tiesheng.login.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import com.tiesheng.login.mapper.CoreLogLoginMapper;
|
||||
import com.tiesheng.login.mapper.CorePlatformUniqueMapper;
|
||||
import com.tiesheng.login.pojos.DoLoginInfo;
|
||||
import com.tiesheng.login.pojos.RequestUserInfo;
|
||||
import com.tiesheng.login.pojos.dao.CoreLogLogin;
|
||||
import com.tiesheng.login.pojos.dao.CorePlatformUnique;
|
||||
import com.tiesheng.util.ServletKit;
|
||||
import com.tiesheng.util.config.Ip2regionConfig;
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
import com.tiesheng.util.service.TsServiceBase;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@Service
|
||||
public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueMapper, CorePlatformUnique> {
|
||||
|
||||
@Resource
|
||||
CoreLogLoginMapper coreLogLoginMapper;
|
||||
@Resource
|
||||
Ip2regionConfig ip2regionConfig;
|
||||
@Resource
|
||||
TsLoginConfigurer tsLoginConfigurer;
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public TokenBean login(DoLoginInfo loginInfo) {
|
||||
|
||||
CorePlatformUnique platformUnique = getOneByColumn("unique_id", loginInfo.getUnique());
|
||||
if (platformUnique == null) {
|
||||
platformUnique = new CorePlatformUnique();
|
||||
platformUnique.setAppId(loginInfo.getAppId());
|
||||
platformUnique.setUniqueId(loginInfo.getUnique());
|
||||
}
|
||||
platformUnique.setPlatform(loginInfo.getPlatform());
|
||||
platformUnique.setInfo(loginInfo.getInfo());
|
||||
saveOrUpdate(platformUnique);
|
||||
|
||||
String oldUserId = platformUnique.getUserId();
|
||||
TokenBean tokenBean = tsLoginConfigurer.login(platformUnique);
|
||||
if (tokenBean != null) {
|
||||
|
||||
// 添加登录日志
|
||||
addLoginLog(platformUnique, tokenBean);
|
||||
|
||||
// 更新唯一值
|
||||
if (!StrUtil.isEmpty(tokenBean.getId()) &&
|
||||
!Objects.equals(oldUserId, tokenBean.getId())) {
|
||||
platformUnique.setUserId(tokenBean.getId());
|
||||
saveOrUpdate(platformUnique);
|
||||
}
|
||||
}
|
||||
|
||||
return tokenBean;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 授权登录回调
|
||||
*
|
||||
* @param bean
|
||||
*/
|
||||
public void redirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
|
||||
tsLoginConfigurer.redirect(bean, to, extra, response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 签名错误的时候
|
||||
*/
|
||||
public void onSignError(HttpServletResponse response) {
|
||||
tsLoginConfigurer.onSignError(response);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// 登录日志
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* 添加登录日志
|
||||
*
|
||||
* @param platformUnique
|
||||
* @param tokenBean
|
||||
*/
|
||||
public void addLoginLog(CorePlatformUnique platformUnique, TokenBean tokenBean) {
|
||||
|
||||
HttpServletRequest request = ServletKit.getRequest();
|
||||
String ip = ServletUtil.getClientIP(request);
|
||||
|
||||
CoreLogLogin login = new CoreLogLogin();
|
||||
login.setUserId(tokenBean.getId());
|
||||
login.setPlatform(platformUnique.getPlatform());
|
||||
|
||||
RequestUserInfo requestUserInfo = tsLoginConfigurer.getCachedUserInfo(tokenBean);
|
||||
login.setUserName(requestUserInfo.getName());
|
||||
|
||||
login.setIp(ip);
|
||||
login.setAddress(ip2regionConfig.search(login.getIp()));
|
||||
coreLogLoginMapper.insert(login);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.tiesheng.login.service;
|
||||
|
||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||
import com.tiesheng.login.pojos.DoLoginInfo;
|
||||
import com.tiesheng.util.ServletKit;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@Configuration
|
||||
public interface TieshengLoginConfigurer {
|
||||
|
||||
/**
|
||||
* 执行登录
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
TokenBean doLogin(DoLoginInfo loginInfo);
|
||||
|
||||
|
||||
/**
|
||||
* 授权登录回调
|
||||
*
|
||||
* @param bean
|
||||
*/
|
||||
void onLoginRedirect(TokenBean bean, String to, String extra, HttpServletResponse response);
|
||||
|
||||
|
||||
/**
|
||||
* 签名错误的时候
|
||||
*/
|
||||
void onSignError(HttpServletResponse response);
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package com.tiesheng.login.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import com.tiesheng.login.pojos.RequestUserInfo;
|
||||
import com.tiesheng.login.pojos.dao.CorePlatformUnique;
|
||||
import com.tiesheng.util.config.TsTokenConfig;
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
import com.tiesheng.util.service.TsCacheService;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@Configuration
|
||||
public interface TsLoginConfigurer {
|
||||
|
||||
/**
|
||||
* 执行登录
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
TokenBean login(CorePlatformUnique platformUnique);
|
||||
|
||||
|
||||
/**
|
||||
* 授权登录回调
|
||||
*
|
||||
* @param bean
|
||||
*/
|
||||
void redirect(TokenBean bean, String to, String extra, HttpServletResponse response);
|
||||
|
||||
|
||||
/**
|
||||
* 签名错误的时候
|
||||
*/
|
||||
default void onSignError(HttpServletResponse response) {
|
||||
ServletUtil.write(response, "404", "text");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前用户的信息
|
||||
*
|
||||
* @param tokenBean
|
||||
* @return
|
||||
*/
|
||||
default RequestUserInfo getCachedUserInfo(TokenBean tokenBean) {
|
||||
String key = StrUtil.format(TsTokenConfig.CACHE_REQUEST_LOGIN_KEY, tokenBean.getId());
|
||||
RequestUserInfo obj = TsCacheService.of().getObj(key, RequestUserInfo.class, -1);
|
||||
if (obj == null) {
|
||||
obj = getCurrentUserName(tokenBean);
|
||||
}
|
||||
if (obj != null) {
|
||||
TsCacheService.of().putObj(key, obj, 30 * 60);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户的姓名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
RequestUserInfo getCurrentUserName(TokenBean userId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.tiesheng.login.service.impl;
|
||||
|
||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||
import com.tiesheng.login.pojos.DoLoginInfo;
|
||||
import com.tiesheng.login.service.TieshengLoginConfigurer;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnMissingBean(value = TieshengLoginConfigurer.class, ignored = DefaultLoginConfigurer.class)
|
||||
public class DefaultLoginConfigurer implements TieshengLoginConfigurer {
|
||||
|
||||
@Override
|
||||
public TokenBean doLogin(DoLoginInfo loginInfo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoginRedirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSignError(HttpServletResponse response) {
|
||||
|
||||
}
|
||||
}
|
||||
BIN
springboot-message/.DS_Store
vendored
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc23</version>
|
||||
<version>zjut-1.1.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-message</artifactId>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.tiesheng.message.config.aliyun;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.tiesheng.message.pojos.AliyunTempParam;
|
||||
|
||||
public interface AliyunSmsHandler {
|
||||
|
||||
|
||||
@@ -3,18 +3,22 @@ package com.tiesheng.message.config.aliyun;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.extra.validation.ValidationUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.tiesheng.message.service.TsMessageSender;
|
||||
import com.tiesheng.message.pojos.AliyunTempParam;
|
||||
import com.tiesheng.message.pojos.MessageReqResp;
|
||||
import com.tiesheng.message.service.TieshengMessageSender;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import com.tiesheng.util.service.http.OkHttpUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -30,7 +34,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "tiesheng.aliyun")
|
||||
public class AliyunSmsSender implements TsMessageSender {
|
||||
public class AliyunSmsSender implements TieshengMessageSender {
|
||||
|
||||
/**
|
||||
* 请求地址
|
||||
@@ -99,16 +103,7 @@ public class AliyunSmsSender implements TsMessageSender {
|
||||
String signature = specialUrlEncode(digest);
|
||||
queryMap.put("Signature", signature);
|
||||
|
||||
String respBody = "";
|
||||
try {
|
||||
respBody = OkHttpUtil.get(ENDPOINT + "?Signature=" + signature + sortQueryStringTmp);
|
||||
} catch (Exception e) {
|
||||
respBody = JSONUtil.createObj()
|
||||
.putOpt("Code", "Error")
|
||||
.putOpt("Message", "消息通道异常")
|
||||
.toString();
|
||||
}
|
||||
return respBody;
|
||||
return HttpUtil.get(ENDPOINT + "?Signature=" + signature + sortQueryStringTmp, 10 * 1000);
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +114,17 @@ public class AliyunSmsSender implements TsMessageSender {
|
||||
* @param tempParam 短信模板
|
||||
* @return
|
||||
*/
|
||||
public ApiResp<String> sendSms(String phoneNumbers, AliyunTempParam tempParam) {
|
||||
public MessageReqResp sendSms(String phoneNumbers, AliyunTempParam tempParam) {
|
||||
|
||||
MessageReqResp reqResp = new MessageReqResp("阿里云短信");
|
||||
reqResp.setTarget(phoneNumbers);
|
||||
reqResp.setResult(1);
|
||||
reqResp.setContent(JSONUtil.createObj()
|
||||
.putOpt("PhoneNumbers", phoneNumbers)
|
||||
.putOpt("SignName", tempParam.getSignName())
|
||||
.putOpt("TemplateCode", tempParam.getTemplateCode())
|
||||
.putOpt("TemplateParam", tempParam.getTemplateParam())
|
||||
.toString());
|
||||
|
||||
// 业务API参数
|
||||
ConcurrentHashMap<String, String> queryMap = new ConcurrentHashMap<>();
|
||||
@@ -130,16 +135,18 @@ public class AliyunSmsSender implements TsMessageSender {
|
||||
queryMap.put("TemplateParam", tempParam.getTemplateParam().toString());
|
||||
}
|
||||
|
||||
JSONObject respObj = JSONUtil.parseObj(request("SendSms", queryMap));
|
||||
reqResp.setRespBody(request("SendSms", queryMap));
|
||||
JSONObject respObj = JSONUtil.parseObj(reqResp.getRespBody());
|
||||
if (!Objects.equals(respObj.getStr("Code"), "OK")) {
|
||||
return ApiResp.resp130(respObj.getStr("Message"));
|
||||
reqResp.setResult(0);
|
||||
reqResp.setToast(respObj.getStr("Message"));
|
||||
}
|
||||
|
||||
return ApiResp.respOK("");
|
||||
return reqResp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResp<String> send(String user, JSONObject body) {
|
||||
public MessageReqResp send(String user, JSONObject body) {
|
||||
boolean mobile = Validator.isMobile(user);
|
||||
if (!mobile) {
|
||||
return null;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.tiesheng.message.config.aliyun;
|
||||
package com.tiesheng.message.pojos;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.tiesheng.message.pojos;
|
||||
|
||||
public class MessageReqResp {
|
||||
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 发送对象
|
||||
*/
|
||||
private String target;
|
||||
|
||||
/**
|
||||
* 发送内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 返回结果
|
||||
*/
|
||||
private String respBody;
|
||||
|
||||
/**
|
||||
* 结果,0-否,1-是
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 提示的异常信息
|
||||
*/
|
||||
private String toast;
|
||||
|
||||
public MessageReqResp(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(String target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getRespBody() {
|
||||
return respBody;
|
||||
}
|
||||
|
||||
public void setRespBody(String respBody) {
|
||||
this.respBody = respBody;
|
||||
}
|
||||
|
||||
public Integer getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(Integer result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public String getToast() {
|
||||
return toast;
|
||||
}
|
||||
|
||||
public void setToast(String toast) {
|
||||
this.toast = toast;
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,12 @@ package com.tiesheng.message.service;
|
||||
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import com.tiesheng.message.pojos.MessageReqResp;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
public interface TsMessageSender {
|
||||
public interface TieshengMessageSender {
|
||||
|
||||
|
||||
/**
|
||||
@@ -20,7 +20,7 @@ public interface TsMessageSender {
|
||||
* @param channel 消息通道,如果为空表示所有通道
|
||||
* @return 返回的内容,如果为空表示发送成功
|
||||
*/
|
||||
ApiResp<String> send(String user, JSONObject body);
|
||||
MessageReqResp send(String user, JSONObject body);
|
||||
|
||||
|
||||
/**
|
||||