# 公众服务平台组件
**Repository Path**: saintman/pusbsv
## Basic Information
- **Project Name**: 公众服务平台组件
- **Description**: 公众服务平台组件
基于springboot接口快速开发框架
1、基于注解/配置方式,接口级别入参出参自动加解密,目前支持AES或者RSA或者RSAWITHAES三种加解密方式
2、支持接口限流,支持ip白名单控制,支持访问限流控制
3、支持通过注解快速启动xxlrpc
4、支持通过注解快速启动xxljob
5、支持通过注解快速启动xxlconf
- **Primary Language**: Java
- **License**: BSD-3-Clause
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2022-06-21
- **Last Updated**: 2025-08-26
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 公众服务平台组件
#### 介绍
SpringBoot快速开发组件,公众服务平台组件用于公众服务平台快速开发。
其支持 **Jdk 1.8+, SpringBoot 2.x.x,xxl-conf 1.6.1,xxl-job 2.2.0,xxl-rpc1.6.0**。
#### 软件架构
软件架构说明
pubsv-component-parent
|--pubsv-component-apifilter #api接口安全拦截器
|--pubsv-component-base #基础模块
|--pubsv-component-example #示例
|--pubsv-component-mybatisplus #mybatis快速启动组件
|--pubsv-component-xxlconf #xxl-conf快速启动组件
|--pubsv-component-xxljob #xxl-job快速启动组件
|--pubsv-component-xxlrpc #xxl-rpc快速启动组件
#### 功能说明
##### pubsv-component-apifilter
1、支持通过注解快速启动apifilter
2、支持接口入参出参自动加解密,支持AES或者RSA或者RSAWITHAES三种加解密方式
3、支持token校验,用户可以重写IOAuthCacheTokenService来自定义token校验
如果设置token校验,bizContent需要传输tokenid
4、支持时间校验
如果设置时间校验,bizContent需要传输13位时间戳time
5、支持ip限流
6、支持业务key限流
##### pubsv-component-xxlconf
1、支持通过注解快速启动xxlconf
##### pubsv-component-xxljob
1、支持通过注解快速启动xxljob
##### pubsv-component-xxlrpc
1、支持通过注解快速启动xxlrpc
##### pubsv-component-mybatisplus(计划中)
支持通过注解快速启动mybatisplus
#### 说明
##### xxl-rpc快速启动组件使用说明
1. 在项目的pom.xml的dependencies中加入以下内容
```xml
com.hgsoft.pubsv.component
pubsv-component-xxlrpc
1.0.0
```
2. Springboot启用注解@EnableXxlRpcInvoker、@EnableXxlRpcProvider
客户端
```java
@EnableXxlRpcInvoker
@SpringBootApplication(scanBasePackages = "com.hgsoft.pubsv")
@Slf4j
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(ExampleApplication.class);
application.setBannerMode(Banner.Mode.OFF);
ConfigurableApplicationContext context = application.run(args);
}
}
```
服务端
```java
@EnableXxlRpcProvider
@SpringBootApplication(scanBasePackages = "com.hgsoft.pubsv")
@Slf4j
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(ExampleApplication.class);
application.setBannerMode(Banner.Mode.OFF);
ConfigurableApplicationContext context = application.run(args);
}
}
```
3. application.yml添加配置
```yaml
################### XXL-RPC 客户端配置 ###################
xxl-rpc:
admin-address: http://127.0.0.1:8081/xxl-rpc-admin
accesstoken: A123456
env: test #环境标识
biz: pubsv #业务标识
################### XXL-RPC 服务端配置 ###################
xxl-rpc:
admin-address: http://127.0.0.1:8081/xxl-rpc-admin
ip: 127.0.0.1
port: 7084
accesstoken: A123456
env: test
biz: pubsv
```
##### xxl-conf快速启动组件使用说明
1. 在项目的pom.xml的dependencies中加入以下内容
```xml
com.hgsoft.pubsv.component
pubsv-component-xxlconf
1.0.0
```
2. Springboot启用注解@EnableXxlConf
```java
@EnableXxlConf
@SpringBootApplication(scanBasePackages = "com.hgsoft.pubsv")
@Slf4j
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(ExampleApplication.class);
application.setBannerMode(Banner.Mode.OFF);
ConfigurableApplicationContext context = application.run(args);
}
}
```
3. application.yml添加配置
```yaml
################### XXL-Conf配置 ###################
xxl-conf:
admin-address: http://127.0.0.1:8082/xxl-conf-admin
access-token:
env: test
mirrorfile: /data/applogs/xxl-conf/xxl-conf-mirror-sample.properties
```
##### xxl-job快速启动组件使用说明
1. 在项目的pom.xml的dependencies中加入以下内容
```xml
com.hgsoft.pubsv.component
pubsv-component-xxljob
1.0.0
```
2. Springboot启用注解@EnableXxlJob
```java
@EnableXxlJob
@SpringBootApplication(scanBasePackages = "com.hgsoft.pubsv")
@Slf4j
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(ExampleApplication.class);
application.setBannerMode(Banner.Mode.OFF);
ConfigurableApplicationContext context = application.run(args);
}
}
```
3. application.yml添加配置
```yaml
################### XXL-Job配置 ###################
xxl-job:
admin-address: http://127.0.0.1:8080/xxl-job-admin
app-name: pubsv-xz-timing-server
address:
ip: 127.0.0.1
port: 9999
access-token:
log-path: /data/applogs/xxl-job/jobhandler
log-retention-days: -1
```
##### apifilter快速启动组件使用说明
1. 在项目的pom.xml的dependencies中加入以下内容
```xml
com.hgsoft.pubsv.component
pubsv-component-apifilter
1.0.0
```
2. Springboot启用注解@EnableSecurity
```java
@EnableSecurity
@SpringBootApplication(scanBasePackages = "com.hgsoft.pubsv")
@Slf4j
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(ExampleApplication.class);
application.setBannerMode(Banner.Mode.OFF);
ConfigurableApplicationContext context = application.run(args);
}
}
```
springMVC添加注解@SecurityParam
```java
@SecurityParam
@RequestMapping(value = "/demoPost", method = RequestMethod.POST)
@ResponseBody
public String http(String name) {
log.info("name:{}", name);
return name;
}
```
3. application.yml添加配置
```yaml
################### 接口安全配置 ###################
pubsv-security:
#是否开启debug模式
isDebug: false
#入参是否解密,默认解密
inDecode: true
#出参是否加密,默认加密
outEncode: true
#是否需要登录token校验,默认需要
needCheckToken: true
#是否需要校验时间戳,默认需要
#需要时需带上请求参数,系统会校验时间有效期,时间超过一定范围不处理
needCheckTime: true
#是否开启ipLimit,同一IP才能访问一次接口,默认不需要
ipLimit: false
#获取IP限制时间范围 单位秒
ipLimitPeriod: 300
#获取IP限制访问次数
ipLimitCount: 3
#接入方AES密钥配置
accessNoAesKey:
5713498500: ABCDEF0123456789
5713498501: ABCDEF0123456789
#接入方限制ip白名单
accessNoAuthIps:
5713498500: 10.173.207.1-10.173.207.255;172.20.32.88-172.20.32.89
5713498501: 10.173.207.1-10.173.207.255;172.20.32.88-172.20.32.89
#接入方Rsa渠道私钥配置
accessNoRsaPrivateKey:
5713498500: XXX
5713498501: XXX
#接入方Rsa渠道公钥配置
accessNoRsaPublicKey:
5713498500: XXX
5713498501: XXX
```
4、第三方接口请求说明详见公共请求接口说明.md
5、客户端请求demo
一、引入第三方请求工具sdk
```xml
cn.hutool
hutool-all
5.0.6
```
引入UTIL
AESUtil.java
RSAUtils.java
二、请求示例
AES加解密方式
```java
Map map = new HashMap<>();
map.put("time", Date.from(Instant.now()).getTime());//13位时间戳
map.put("idNum", "622621199808088888");
map.put("idType", 0);
map.put("clientKey", "20220223091233423412341234");//accessno+随机唯一编码,也可以固定
String json = JSONUtil.toJsonStr(map);
String aesKey = "62JXC0ZOO7788888";//分配
HttpResponse response = HttpRequest.post("http://127.0.0.1:8092/pubsv-xz-nm/ioapi/applyissue/queryCustomerInfo")
.form("bizContent", AESUtil.encrypt(json, aesKey, "UTF-8"))
.form("accessNo", "2022022309")
.form("encryptType", "AES")
.form("format", "JSON")
.form("timestamp", DateUtil.now())
.form("version", "1.0")
.form("charset", "UTF-8").execute();
String result2 = response.body();
System.out.println(result2);
```
RSA加解密方式
```java
Map map = new HashMap<>();
map.put("time", Date.from(Instant.now()).getTime());//13位时间戳
map.put("idNum", "622621199808088888");
map.put("idType", 0);
map.put("clientKey", "20220223091233423412341234");//accessno+随机唯一编码,也可以固定
String json = JSONUtil.toJsonStr(map);
String pub = "";//公钥
System.out.println("明文:"+json);
System.out.println("密文:"+RSAUtils.encrypt(json,pub));
String url = "http://127.0.0.1:8092/pubsv-xz-nm/ioapi/applyissue/queryCustomerInfo";
Map req = new HashMap<>();
req.put("bizContent", RSAUtils.encrypt(json,pub));
req.put("accessNo", "2022022309");
req.put("encryptType", "RSA");
req.put("format", "JSON");
req.put("timestamp", DateUtil.now());
req.put("version", "1.0");
req.put("charset", "UTF-8");
String result = HttpUtil.post(url, req);
System.out.println(result);
```
RSAWITHAES加解密方式
```java
Map map = new HashMap<>();
map.put("time", Date.from(Instant.now()).getTime());//13位时间戳
map.put("idNum", "622621199808062814");
map.put("idType", 0);
map.put("clientKey", "20220223091233423412341234");//accessno+随机唯一编码,也可以固定
String json = JSONUtil.toJsonStr(map);
String aesKey = RandomUtil.randomStringUpper(16);//随机生成
String pub = "";//公钥
String encryAesKey = RSAUtils.encrypt(aesKey,pub);
System.out.println("aesKey明文:"+aesKey);
System.out.println("aesKey密文:"+encryAesKey);
String pub = "";//公钥
System.out.println("明文:"+json);
System.out.println("密文:"+RSAUtils.encrypt(json,pub));
String url = "http://127.0.0.1:8092/pubsv-xz-nm/ioapi/applyissue/queryCustomerInfo";
Map req = new HashMap<>();
req.put("bizContent", AESUtil.encrypt(json, aesKey, "UTF-8"));
req.put("accessNo", "2022022309");
req.put("encryptType", "RSAWITHAES");
req.put("format", "JSON");
req.put("timestamp", DateUtil.now());
req.put("version", "1.0");
req.put("charset", "UTF-8");
req.put("encryAesKey", encryAesKey);
String result = HttpUtil.post(url, req);
System.out.println(result);
```
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request