Skip to content

Commit 804260f

Browse files
committed
完善warp工具,去除api-wrap-boot中的redis依赖
1 parent 5a9b1ae commit 804260f

File tree

6 files changed

+67
-32
lines changed

6 files changed

+67
-32
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 服务端安全签名验签
22

3+
## chang list
4+
- api-wrap-boot去除redis依赖
5+
36
## 引入jar包
47
### gradle
58
```
@@ -103,11 +106,15 @@ wrapStore.putSecret(appKey, appSecret);
103106
api.wrap.secret=testjjhdsa
104107
# 单位秒,请求时间和服务器时间不能超过300秒
105108
api.wrap.legal-time=300
109+
# 若没有redis配置,wrapStore为本地存储
110+
# 若配置了redis,则wrapStore为redis存储
106111
#===========api wrap redis=============
107112
spring.redis.host=localhost
108113
spring.redis.port=6379
109114
spring.redis.database=0
110115
```
116+
- 若没有redis配置,wrapStore为本地存储
117+
- 若配置了redis,则wrapStore为redis存储
111118

112119
# 客户端辅助签名工具
113120

api-wrap-boot/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<dependency>
3232
<groupId>org.springframework.boot</groupId>
3333
<artifactId>spring-boot-starter-data-redis</artifactId>
34+
<scope>provided</scope>
3435
</dependency>
3536

3637
<dependency>

api-wrap-boot/src/main/java/com/seelyn/apiwrap/ApiWrapAutoConfiguration.java

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import com.seelyn.apiwrap.store.LocalWrapStore;
55
import com.seelyn.apiwrap.store.RedisWrapStore;
66
import org.springframework.beans.factory.annotation.Autowired;
7-
import org.springframework.beans.factory.annotation.Qualifier;
87
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
98
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
9+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
1010
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
11+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
1112
import org.springframework.boot.context.properties.EnableConfigurationProperties;
1213
import org.springframework.context.annotation.Bean;
1314
import org.springframework.context.annotation.Configuration;
1415
import org.springframework.context.annotation.Import;
15-
import org.springframework.data.redis.core.RedisTemplate;
1616
import org.springframework.data.redis.core.StringRedisTemplate;
1717

1818
/**
@@ -36,32 +36,6 @@ public ApiWrapAspect apiWrapAspect() {
3636
return new ApiWrapAspect();
3737
}
3838

39-
/**
40-
* API包裹存储
41-
*
42-
* @param apiWrapProperties 配置
43-
* @param stringRedisTemplate redis
44-
* @return 签名验签处理服务
45-
*/
46-
@Bean
47-
@ConditionalOnBean(value = StringRedisTemplate.class)
48-
@ConditionalOnMissingBean
49-
public WrapStore redisWrapStore(@Autowired ApiWrapProperties apiWrapProperties,
50-
@Autowired StringRedisTemplate stringRedisTemplate) {
51-
52-
return new RedisWrapStore(apiWrapProperties, stringRedisTemplate);
53-
}
54-
55-
/**
56-
* @param apiWrapProperties 配置
57-
* @return
58-
*/
59-
@Bean
60-
@ConditionalOnMissingBean(value = {RedisTemplate.class, WrapStore.class})
61-
public WrapStore localWrapStore(@Autowired ApiWrapProperties apiWrapProperties) {
62-
63-
return new LocalWrapStore(apiWrapProperties);
64-
}
6539

6640
/**
6741
* 包裹通过
@@ -71,7 +45,6 @@ public WrapStore localWrapStore(@Autowired ApiWrapProperties apiWrapProperties)
7145
* @return 签名验签处理
7246
*/
7347
@Bean
74-
@ConditionalOnMissingBean(value = {WrapHandler.class})
7548
public WrapHandler defaultWrapHandler(@Autowired ApiWrapProperties apiWrapProperties,
7649
@Autowired WrapStore wrapStore) {
7750

@@ -88,4 +61,38 @@ public WrapBeanFactoryUtils wrapBeanFactoryUtils() {
8861
return new WrapBeanFactoryUtils();
8962
}
9063

64+
/**
65+
* @param apiWrapProperties 配置
66+
* @return
67+
*/
68+
@Bean
69+
@ConditionalOnMissingClass(value = {"org.springframework.data.redis.core.StringRedisTemplate"})
70+
@ConditionalOnMissingBean
71+
public WrapStore localWrapStore(@Autowired ApiWrapProperties apiWrapProperties) {
72+
73+
return new LocalWrapStore(apiWrapProperties);
74+
}
75+
76+
@Configuration
77+
@ConditionalOnClass(value = StringRedisTemplate.class)
78+
static class RedisWrapStoreConfiguration {
79+
80+
/**
81+
* API包裹存储
82+
*
83+
* @param apiWrapProperties 配置
84+
* @param stringRedisTemplate redis
85+
* @return 签名验签处理服务
86+
*/
87+
@Bean
88+
@ConditionalOnMissingBean
89+
public WrapStore redisWrapStore(@Autowired ApiWrapProperties apiWrapProperties,
90+
@Autowired StringRedisTemplate stringRedisTemplate) {
91+
92+
return new RedisWrapStore(apiWrapProperties, stringRedisTemplate);
93+
}
94+
95+
96+
}
97+
9198
}

api-wrap-test/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
<groupId>org.springframework.boot</groupId>
3232
<artifactId>spring-boot-starter-test</artifactId>
3333
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-data-redis</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.alibaba</groupId>
40+
<artifactId>fastjson</artifactId>
41+
<version>1.2.69</version>
42+
</dependency>
3443
</dependencies>
3544

3645
<build>
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
package com.parsechina.apiwarp;
22

3+
import com.seelyn.apiwrap.WrapStore;
34
import com.seelyn.apiwrap.annotation.EnableApiWrap;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.CommandLineRunner;
47
import org.springframework.boot.SpringApplication;
58
import org.springframework.boot.autoconfigure.SpringBootApplication;
69

710
@EnableApiWrap
811
@SpringBootApplication
9-
public class ApiWrapApplication {
12+
public class ApiWrapApplication implements CommandLineRunner {
1013

1114
public static void main(String[] args) {
1215
SpringApplication.run(ApiWrapApplication.class, args);
1316
}
1417

18+
@Autowired
19+
private WrapStore wrapStore;
20+
21+
@Override
22+
public void run(String... args) throws Exception {
23+
wrapStore.putSecret("eqxiu", "eqxiu");
24+
}
1525
}

api-wrap-test/src/test/java/com/seelyn/apiwrap/utils/WrapUtilsTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.seelyn.apiwrap.utils;
22

3+
import com.alibaba.fastjson.JSON;
34
import com.parsechina.apiwarp.web.DefaultWrapData;
45
import com.seelyn.apiwrap.WrapRequest;
56
import com.seelyn.apiwrap.client.WrapClient;
@@ -10,8 +11,8 @@ public class WrapUtilsTest {
1011
public void beanToMap() {
1112
DefaultWrapData wrapData = new DefaultWrapData();
1213
wrapData.setUrl("http://www.baidu.com");
13-
WrapClient wrapClient = WrapClient.create("123", "123");
14+
WrapClient wrapClient = WrapClient.create("eqxiu", "eqxiu");
1415
WrapRequest<DefaultWrapData> wrapDataWrapRequest = wrapClient.wrap(wrapData);
15-
16+
System.out.println(JSON.toJSONString(wrapDataWrapRequest));
1617
}
1718
}

0 commit comments

Comments
 (0)