Skip to content

Commit 9ab2cfb

Browse files
authored
Merge pull request #1577 from Wechat-Group/develop
合并Develop分支,发布正式版本
2 parents 23c1b0b + d8a1fce commit 9ab2cfb

File tree

284 files changed

+10153
-1545
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+10153
-1545
lines changed

pom.xml

+24-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.github.binarywang</groupId>
88
<artifactId>wx-java</artifactId>
9-
<version>3.7.0</version>
9+
<version>3.8.0</version>
1010
<packaging>pom</packaging>
1111
<name>WxJava - Weixin/Wechat Java SDK</name>
1212
<description>微信开发Java SDK</description>
@@ -116,7 +116,7 @@
116116

117117
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
118118
<httpclient.version>4.5</httpclient.version>
119-
<jetty.version>9.4.17.v20190418</jetty.version>
119+
<jetty.version>9.4.28.v20200408</jetty.version>
120120
</properties>
121121

122122
<dependencyManagement>
@@ -130,13 +130,13 @@
130130
<dependency>
131131
<groupId>org.jodd</groupId>
132132
<artifactId>jodd-http</artifactId>
133-
<version>3.7.1</version>
133+
<version>5.1.4</version>
134134
<scope>provided</scope>
135135
</dependency>
136136
<dependency>
137137
<groupId>com.squareup.okhttp3</groupId>
138138
<artifactId>okhttp</artifactId>
139-
<version>3.7.0</version>
139+
<version>4.5.0</version>
140140
<scope>provided</scope>
141141
</dependency>
142142

@@ -163,7 +163,7 @@
163163
<dependency>
164164
<groupId>org.apache.commons</groupId>
165165
<artifactId>commons-lang3</artifactId>
166-
<version>3.5</version>
166+
<version>3.10</version>
167167
</dependency>
168168
<dependency>
169169
<groupId>org.slf4j</groupId>
@@ -191,31 +191,31 @@
191191
<dependency>
192192
<groupId>joda-time</groupId>
193193
<artifactId>joda-time</artifactId>
194-
<version>2.9.7</version>
194+
<version>2.10.6</version>
195195
<scope>test</scope>
196196
</dependency>
197197
<dependency>
198198
<groupId>ch.qos.logback</groupId>
199199
<artifactId>logback-classic</artifactId>
200-
<version>1.1.11</version>
200+
<version>1.2.3</version>
201201
<scope>test</scope>
202202
</dependency>
203203
<dependency>
204204
<groupId>com.google.inject</groupId>
205205
<artifactId>guice</artifactId>
206-
<version>3.0</version>
206+
<version>4.2.3</version>
207207
<scope>test</scope>
208208
</dependency>
209209
<dependency>
210210
<groupId>org.testng</groupId>
211211
<artifactId>testng</artifactId>
212-
<version>6.10</version>
212+
<version>7.1.0</version>
213213
<scope>test</scope>
214214
</dependency>
215215
<dependency>
216216
<groupId>org.mockito</groupId>
217217
<artifactId>mockito-all</artifactId>
218-
<version>1.9.5</version>
218+
<version>1.10.19</version>
219219
<scope>test</scope>
220220
</dependency>
221221
<dependency>
@@ -243,10 +243,24 @@
243243
<version>2.9.0</version>
244244
<scope>provided</scope>
245245
</dependency>
246+
<dependency>
247+
<groupId>com.github.jedis-lock</groupId>
248+
<artifactId>jedis-lock</artifactId>
249+
<version>1.0.0</version>
250+
<scope>provided</scope>
251+
</dependency>
246252
<dependency>
247253
<groupId>org.redisson</groupId>
248254
<artifactId>redisson</artifactId>
249255
<version>3.12.0</version>
256+
<optional>true</optional>
257+
<scope>provided</scope>
258+
</dependency>
259+
<dependency>
260+
<groupId>org.springframework.data</groupId>
261+
<artifactId>spring-data-redis</artifactId>
262+
<version>1.8.23.RELEASE</version>
263+
<optional>true</optional>
250264
<scope>provided</scope>
251265
</dependency>
252266
<dependency>

spring-boot-starters/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.github.binarywang</groupId>
88
<artifactId>wx-java</artifactId>
9-
<version>3.7.0</version>
9+
<version>3.8.0</version>
1010
</parent>
1111
<packaging>pom</packaging>
1212
<artifactId>wx-java-spring-boot-starters</artifactId>
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1-
# 使用说明
2-
1. 在自己的Spring Boot项目里,引入maven依赖
3-
```xml
1+
# wx-java-miniapp-spring-boot-starter
2+
## 快速开始
3+
1. 引入依赖
4+
```xml
45
<dependency>
56
<groupId>com.github.binarywang</groupId>
67
<artifactId>wx-java-miniapp-spring-boot-starter</artifactId>
78
<version>${version}</version>
89
</dependency>
9-
```
10-
2. 添加配置(application.yml)
11-
```yml
12-
wx:
13-
miniapp:
14-
appid: 111
15-
secret: 111
16-
token: 111
17-
aesKey: 111
18-
msgDataFormat: JSON
19-
```
20-
21-
22-
23-
24-
25-
10+
```
11+
2. 添加配置(application.properties)
12+
```properties
13+
# 公众号配置(必填)
14+
wx.miniapp.appid = appId
15+
wx.miniapp.secret = @secret
16+
wx.miniapp.token = @token
17+
wx.miniapp.aesKey = @aesKey
18+
wx.miniapp.msgDataFormat = @msgDataFormat # 消息格式,XML或者JSON.
19+
# 存储配置redis(可选)
20+
# 注意: 指定redis.host值后不会使用容器注入的redis连接(JedisPool)
21+
wx.miniapp.config-storage.type = jedis # 配置类型: memory(默认), jedis, redistemplate
22+
wx.miniapp.config-storage.key-prefix = wa # 相关redis前缀配置: wa(默认)
23+
wx.miniapp.config-storage.redis.host = 127.0.0.1
24+
wx.miniapp.config-storage.redis.port = 6379
25+
# http客户端配置
26+
wx.miniapp.config-storage.http-client-type=httpclient # http客户端类型: httpclient(默认)
27+
wx.miniapp.config-storage.http-proxy-host=
28+
wx.miniapp.config-storage.http-proxy-port=
29+
wx.miniapp.config-storage.http-proxy-username=
30+
wx.miniapp.config-storage.http-proxy-password=
31+
```
32+
3. 自动注入的类型
33+
- `WxMaService`
34+
- `WxMaConfig`
2635

spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>wx-java-spring-boot-starters</artifactId>
77
<groupId>com.github.binarywang</groupId>
8-
<version>3.7.0</version>
8+
<version>3.8.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -19,6 +19,17 @@
1919
<artifactId>weixin-java-miniapp</artifactId>
2020
<version>${project.version}</version>
2121
</dependency>
22+
<dependency>
23+
<groupId>redis.clients</groupId>
24+
<artifactId>jedis</artifactId>
25+
<scope>provided</scope>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.data</groupId>
29+
<artifactId>spring-data-redis</artifactId>
30+
<version>${spring.boot.version}</version>
31+
<scope>provided</scope>
32+
</dependency>
2233
</dependencies>
2334

2435
<build>

spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java

+91-10
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@
44
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
55
import cn.binarywang.wx.miniapp.config.WxMaConfig;
66
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
7+
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
78
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
89
import lombok.AllArgsConstructor;
10+
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
11+
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
12+
import me.chanjar.weixin.common.redis.WxRedisOps;
913
import org.apache.commons.lang3.StringUtils;
1014
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
1115
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
1216
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
1317
import org.springframework.boot.context.properties.EnableConfigurationProperties;
18+
import org.springframework.context.ApplicationContext;
1419
import org.springframework.context.annotation.Bean;
1520
import org.springframework.context.annotation.Configuration;
21+
import org.springframework.data.redis.core.StringRedisTemplate;
22+
import redis.clients.jedis.JedisPool;
23+
import redis.clients.jedis.JedisPoolConfig;
1624

1725
/**
1826
* 自动配置.
@@ -26,7 +34,9 @@
2634
@EnableConfigurationProperties(WxMaProperties.class)
2735
@ConditionalOnProperty(prefix = "wx.miniapp", value = "enabled", matchIfMissing = true)
2836
public class WxMaAutoConfiguration {
29-
private WxMaProperties properties;
37+
38+
private final WxMaProperties wxMaProperties;
39+
private final ApplicationContext applicationContext;
3040

3141
/**
3242
* 小程序service.
@@ -35,16 +45,87 @@ public class WxMaAutoConfiguration {
3545
*/
3646
@Bean
3747
@ConditionalOnMissingBean(WxMaService.class)
38-
public WxMaService service() {
39-
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
40-
config.setAppid(StringUtils.trimToNull(this.properties.getAppid()));
41-
config.setSecret(StringUtils.trimToNull(this.properties.getSecret()));
42-
config.setToken(StringUtils.trimToNull(this.properties.getToken()));
43-
config.setAesKey(StringUtils.trimToNull(this.properties.getAesKey()));
44-
config.setMsgDataFormat(StringUtils.trimToNull(this.properties.getMsgDataFormat()));
45-
48+
public WxMaService service(WxMaConfig wxMaConfig) {
4649
final WxMaServiceImpl service = new WxMaServiceImpl();
47-
service.setWxMaConfig(config);
50+
service.setWxMaConfig(wxMaConfig);
4851
return service;
4952
}
53+
54+
@Bean
55+
@ConditionalOnMissingBean(WxMaConfig.class)
56+
public WxMaConfig wxMaConfig() {
57+
WxMaProperties.StorageType type = wxMaProperties.getConfigStorage().getType();
58+
WxMaDefaultConfigImpl config;
59+
if (type == WxMaProperties.StorageType.jedis) {
60+
config = wxMaInJedisConfigStorage();
61+
} else if (type == WxMaProperties.StorageType.redistemplate) {
62+
config = wxMaInRedisTemplateConfigStorage();
63+
} else {
64+
config = wxMaInMemoryConfigStorage();
65+
}
66+
67+
config.setAppid(StringUtils.trimToNull(this.wxMaProperties.getAppid()));
68+
config.setSecret(StringUtils.trimToNull(this.wxMaProperties.getSecret()));
69+
config.setToken(StringUtils.trimToNull(this.wxMaProperties.getToken()));
70+
config.setAesKey(StringUtils.trimToNull(this.wxMaProperties.getAesKey()));
71+
config.setMsgDataFormat(StringUtils.trimToNull(this.wxMaProperties.getMsgDataFormat()));
72+
73+
WxMaProperties.ConfigStorage configStorageProperties = wxMaProperties.getConfigStorage();
74+
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
75+
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
76+
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
77+
if (configStorageProperties.getHttpProxyPort() != null) {
78+
config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
79+
}
80+
return config;
81+
}
82+
83+
private WxMaDefaultConfigImpl wxMaInMemoryConfigStorage() {
84+
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
85+
return config;
86+
}
87+
88+
private WxMaDefaultConfigImpl wxMaInJedisConfigStorage() {
89+
WxMaProperties.RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
90+
JedisPool jedisPool;
91+
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
92+
jedisPool = getJedisPool();
93+
} else {
94+
jedisPool = applicationContext.getBean(JedisPool.class);
95+
}
96+
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
97+
WxMaRedisBetterConfigImpl wxMaRedisConfig = new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
98+
return wxMaRedisConfig;
99+
}
100+
101+
private WxMaDefaultConfigImpl wxMaInRedisTemplateConfigStorage() {
102+
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
103+
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
104+
WxMaRedisBetterConfigImpl wxMaRedisConfig = new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
105+
return wxMaRedisConfig;
106+
}
107+
108+
private JedisPool getJedisPool() {
109+
WxMaProperties.ConfigStorage storage = wxMaProperties.getConfigStorage();
110+
WxMaProperties.RedisProperties redis = storage.getRedis();
111+
112+
JedisPoolConfig config = new JedisPoolConfig();
113+
if (redis.getMaxActive() != null) {
114+
config.setMaxTotal(redis.getMaxActive());
115+
}
116+
if (redis.getMaxIdle() != null) {
117+
config.setMaxIdle(redis.getMaxIdle());
118+
}
119+
if (redis.getMaxWaitMillis() != null) {
120+
config.setMaxWaitMillis(redis.getMaxWaitMillis());
121+
}
122+
if (redis.getMinIdle() != null) {
123+
config.setMinIdle(redis.getMinIdle());
124+
}
125+
config.setTestOnBorrow(true);
126+
config.setTestWhileIdle(true);
127+
128+
return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(),
129+
redis.getDatabase());
130+
}
50131
}

0 commit comments

Comments
 (0)