diff --git a/pom.xml b/pom.xml
index 8c115354e..1faea9f31 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
4.0.0
com.github.binarywang
wx-java
- 3.9.3.B
+ 3.9.4.B
pom
WxJava - Weixin/Wechat Java SDK
微信开发Java SDK
diff --git a/spring-boot-starters/pom.xml b/spring-boot-starters/pom.xml
index 776d39b04..72cde108a 100644
--- a/spring-boot-starters/pom.xml
+++ b/spring-boot-starters/pom.xml
@@ -6,7 +6,7 @@
com.github.binarywang
wx-java
- 3.9.3.B
+ 3.9.4.B
pom
wx-java-spring-boot-starters
diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml
index a3e19a356..869042f31 100644
--- a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml
+++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml
@@ -5,7 +5,7 @@
wx-java-spring-boot-starters
com.github.binarywang
- 3.9.3.B
+ 3.9.4.B
4.0.0
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md b/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md
index 5059a59f5..ae6ed9459 100644
--- a/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md
@@ -20,12 +20,19 @@
wx.mp.config-storage.key-prefix = wx # 相关redis前缀配置: wx(默认)
wx.mp.config-storage.redis.host = 127.0.0.1
wx.mp.config-storage.redis.port = 6379
+ #单机和sentinel同时存在时,优先使用sentinel配置
+ #wx.mp.config-storage.redis.sentinel-ips=127.0.0.1:16379,127.0.0.1:26379
+ #wx.mp.config-storage.redis.sentinel-name=mymaster
# http客户端配置
wx.mp.config-storage.http-client-type=httpclient # http客户端类型: HttpClient(默认), OkHttp, JoddHttp
wx.mp.config-storage.http-proxy-host=
wx.mp.config-storage.http-proxy-port=
wx.mp.config-storage.http-proxy-username=
wx.mp.config-storage.http-proxy-password=
+ # 公众号地址host配置
+ #wx.mp.hosts.api-host=http://proxy.com/
+ #wx.mp.hosts.open-host=http://proxy.com/
+ #wx.mp.hosts.mp-host=http://proxy.com/
```
3. 自动注入的类型
- `WxMpService`以及~~相关的服务类, 比如: `wxMpService.getXxxService`。~~
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml b/spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml
index 4b69b18b0..c4613752f 100644
--- a/spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml
@@ -5,7 +5,7 @@
wx-java-spring-boot-starters
com.github.binarywang
- 3.9.3.B
+ 3.9.4.B
4.0.0
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java
index ad4fb31e4..ef8e5348e 100644
--- a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java
@@ -1,15 +1,7 @@
package com.binarywang.spring.starter.wxjava.mp.config;
-import com.binarywang.spring.starter.wxjava.mp.properties.RedisProperties;
-import com.binarywang.spring.starter.wxjava.mp.enums.StorageType;
-import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
-import lombok.RequiredArgsConstructor;
-import me.chanjar.weixin.common.redis.JedisWxRedisOps;
-import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
-import me.chanjar.weixin.common.redis.WxRedisOps;
-import me.chanjar.weixin.mp.config.WxMpConfigStorage;
-import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
-import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
+import java.util.Set;
+
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -17,8 +9,24 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
+
+import com.binarywang.spring.starter.wxjava.mp.enums.StorageType;
+import com.binarywang.spring.starter.wxjava.mp.properties.RedisProperties;
+import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
+import com.google.common.collect.Sets;
+
+import lombok.RequiredArgsConstructor;
+import me.chanjar.weixin.common.redis.JedisWxRedisOps;
+import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
+import me.chanjar.weixin.common.redis.WxRedisOps;
+import me.chanjar.weixin.mp.bean.WxMpHostConfig;
+import me.chanjar.weixin.mp.config.WxMpConfigStorage;
+import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
+import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.JedisPoolAbstract;
import redis.clients.jedis.JedisPoolConfig;
+import redis.clients.jedis.JedisSentinelPool;
/**
* 微信公众号存储策略自动配置.
@@ -28,99 +36,113 @@ import redis.clients.jedis.JedisPoolConfig;
@Configuration
@RequiredArgsConstructor
public class WxMpStorageAutoConfiguration {
- private final ApplicationContext applicationContext;
+ private final ApplicationContext applicationContext;
- private final WxMpProperties wxMpProperties;
+ private final WxMpProperties wxMpProperties;
- @Value("${wx.mp.config-storage.redis.host:")
- private String redisHost;
+ @Value("${wx.mp.config-storage.redis.host:")
+ private String redisHost;
- @Value("${wx.mp.configStorage.redis.host:")
- private String redisHost2;
+ @Value("${wx.mp.configStorage.redis.host:")
+ private String redisHost2;
- @Bean
- @ConditionalOnMissingBean(WxMpConfigStorage.class)
- public WxMpConfigStorage wxMpConfigStorage() {
- StorageType type = wxMpProperties.getConfigStorage().getType();
- WxMpConfigStorage config;
- switch (type) {
- case Jedis:
- config = jedisConfigStorage();
- break;
- case RedisTemplate:
- config = redisTemplateConfigStorage();
- break;
- default:
- config = defaultConfigStorage();
- break;
- }
- return config;
- }
+ @Bean
+ @ConditionalOnMissingBean(WxMpConfigStorage.class)
+ public WxMpConfigStorage wxMpConfigStorage() {
+ StorageType type = wxMpProperties.getConfigStorage().getType();
+ WxMpConfigStorage config;
+ switch (type) {
+ case Jedis:
+ config = jedisConfigStorage();
+ break;
+ case RedisTemplate:
+ config = redisTemplateConfigStorage();
+ break;
+ default:
+ config = defaultConfigStorage();
+ break;
+ }
+ // wx host config
+ if (null != wxMpProperties.getHosts() && StringUtils.isNotEmpty(wxMpProperties.getHosts().getApiHost())) {
+ WxMpHostConfig hostConfig = new WxMpHostConfig();
+ hostConfig.setApiHost(wxMpProperties.getHosts().getApiHost());
+ hostConfig.setMpHost(wxMpProperties.getHosts().getMpHost());
+ hostConfig.setOpenHost(wxMpProperties.getHosts().getOpenHost());
+ config.setHostConfig(hostConfig);
+ }
+ return config;
+ }
- private WxMpConfigStorage defaultConfigStorage() {
- WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
- setWxMpInfo(config);
- return config;
- }
+ private WxMpConfigStorage defaultConfigStorage() {
+ WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
+ setWxMpInfo(config);
+ return config;
+ }
- private WxMpConfigStorage jedisConfigStorage() {
- JedisPool jedisPool;
- if (StringUtils.isNotEmpty(redisHost) || StringUtils.isNotEmpty(redisHost2)) {
- jedisPool = getJedisPool();
- } else {
- jedisPool = applicationContext.getBean(JedisPool.class);
- }
- WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
- WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps, wxMpProperties.getConfigStorage().getKeyPrefix());
- setWxMpInfo(wxMpRedisConfig);
- return wxMpRedisConfig;
- }
+ private WxMpConfigStorage jedisConfigStorage() {
+ JedisPoolAbstract jedisPool;
+ if (StringUtils.isNotEmpty(redisHost) || StringUtils.isNotEmpty(redisHost2)) {
+ jedisPool = getJedisPool();
+ } else {
+ jedisPool = applicationContext.getBean(JedisPool.class);
+ }
+ WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
+ WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps,
+ wxMpProperties.getConfigStorage().getKeyPrefix());
+ setWxMpInfo(wxMpRedisConfig);
+ return wxMpRedisConfig;
+ }
- private WxMpConfigStorage redisTemplateConfigStorage() {
- StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
- WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
- WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps, wxMpProperties.getConfigStorage().getKeyPrefix());
- setWxMpInfo(wxMpRedisConfig);
- return wxMpRedisConfig;
- }
+ private WxMpConfigStorage redisTemplateConfigStorage() {
+ StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
+ WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
+ WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps,
+ wxMpProperties.getConfigStorage().getKeyPrefix());
+ setWxMpInfo(wxMpRedisConfig);
+ return wxMpRedisConfig;
+ }
- private void setWxMpInfo(WxMpDefaultConfigImpl config) {
- WxMpProperties properties = wxMpProperties;
- WxMpProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
- config.setAppId(properties.getAppId());
- config.setSecret(properties.getSecret());
- config.setToken(properties.getToken());
- config.setAesKey(properties.getAesKey());
+ private void setWxMpInfo(WxMpDefaultConfigImpl config) {
+ WxMpProperties properties = wxMpProperties;
+ WxMpProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
+ config.setAppId(properties.getAppId());
+ config.setSecret(properties.getSecret());
+ config.setToken(properties.getToken());
+ config.setAesKey(properties.getAesKey());
- config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
- config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
- config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
- if (configStorageProperties.getHttpProxyPort() != null) {
- config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
- }
- }
+ config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
+ config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
+ config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
+ if (configStorageProperties.getHttpProxyPort() != null) {
+ config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
+ }
+ }
- private JedisPool getJedisPool() {
- WxMpProperties.ConfigStorage storage = wxMpProperties.getConfigStorage();
- RedisProperties redis = storage.getRedis();
+ private JedisPoolAbstract getJedisPool() {
+ WxMpProperties.ConfigStorage storage = wxMpProperties.getConfigStorage();
+ RedisProperties redis = storage.getRedis();
- JedisPoolConfig config = new JedisPoolConfig();
- if (redis.getMaxActive() != null) {
- config.setMaxTotal(redis.getMaxActive());
- }
- if (redis.getMaxIdle() != null) {
- config.setMaxIdle(redis.getMaxIdle());
- }
- if (redis.getMaxWaitMillis() != null) {
- config.setMaxWaitMillis(redis.getMaxWaitMillis());
- }
- if (redis.getMinIdle() != null) {
- config.setMinIdle(redis.getMinIdle());
- }
- config.setTestOnBorrow(true);
- config.setTestWhileIdle(true);
+ JedisPoolConfig config = new JedisPoolConfig();
+ if (redis.getMaxActive() != null) {
+ config.setMaxTotal(redis.getMaxActive());
+ }
+ if (redis.getMaxIdle() != null) {
+ config.setMaxIdle(redis.getMaxIdle());
+ }
+ if (redis.getMaxWaitMillis() != null) {
+ config.setMaxWaitMillis(redis.getMaxWaitMillis());
+ }
+ if (redis.getMinIdle() != null) {
+ config.setMinIdle(redis.getMinIdle());
+ }
+ config.setTestOnBorrow(true);
+ config.setTestWhileIdle(true);
+ if (StringUtils.isNotEmpty(redis.getSentinelIps())) {
+ Set sentinels = Sets.newHashSet(redis.getSentinelIps().split(","));
+ return new JedisSentinelPool(redis.getSentinelName(), sentinels);
+ }
- return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(),
- redis.getDatabase());
- }
+ return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(),
+ redis.getDatabase());
+ }
}
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/HostConfig.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/HostConfig.java
new file mode 100644
index 000000000..3ade23b9a
--- /dev/null
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/HostConfig.java
@@ -0,0 +1,18 @@
+package com.binarywang.spring.starter.wxjava.mp.properties;
+
+import java.io.Serializable;
+
+import lombok.Data;
+
+@Data
+public class HostConfig implements Serializable {
+
+ private static final long serialVersionUID = -4172767630740346001L;
+
+ private String apiHost;
+
+ private String openHost;
+
+ private String mpHost;
+
+}
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java
index c8c3307fe..07e4280b2 100644
--- a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java
@@ -38,6 +38,16 @@ public class RedisProperties implements Serializable {
* 数据库.
*/
private int database = 0;
+
+ /**
+ * sentinel ips
+ */
+ private String sentinelIps;
+
+ /**
+ * sentinel name
+ */
+ private String sentinelName;
private Integer maxActive;
private Integer maxIdle;
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java
index 14a61b574..818d55f3e 100644
--- a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java
@@ -40,6 +40,11 @@ public class WxMpProperties {
* 设置微信公众号的EncodingAESKey.
*/
private String aesKey;
+
+ /**
+ * 自定义host配置
+ */
+ private HostConfig hosts;
/**
* 存储策略
diff --git a/spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml b/spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml
index e53792de0..e2a25ae12 100644
--- a/spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml
+++ b/spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml
@@ -5,7 +5,7 @@
wx-java-spring-boot-starters
com.github.binarywang
- 3.9.3.B
+ 3.9.4.B
4.0.0
diff --git a/spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml b/spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml
index 7348faf05..53205d559 100644
--- a/spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml
+++ b/spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml
@@ -5,7 +5,7 @@
wx-java-spring-boot-starters
com.github.binarywang
- 3.9.3.B
+ 3.9.4.B
4.0.0
diff --git a/weixin-graal/pom.xml b/weixin-graal/pom.xml
index 4e86c896c..1e9961671 100644
--- a/weixin-graal/pom.xml
+++ b/weixin-graal/pom.xml
@@ -6,7 +6,7 @@
com.github.binarywang
wx-java
- 3.9.3.B
+ 3.9.4.B
weixin-graal
diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml
index e9c72fd9b..31c04cd08 100644
--- a/weixin-java-common/pom.xml
+++ b/weixin-java-common/pom.xml
@@ -6,7 +6,7 @@
com.github.binarywang
wx-java
- 3.9.3.B
+ 3.9.4.B
weixin-java-common
diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml
index 2dbfa4965..10fab71e2 100644
--- a/weixin-java-cp/pom.xml
+++ b/weixin-java-cp/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.9.3.B
+ 3.9.4.B
weixin-java-cp
diff --git a/weixin-java-miniapp/pom.xml b/weixin-java-miniapp/pom.xml
index 5963679be..43f460cee 100644
--- a/weixin-java-miniapp/pom.xml
+++ b/weixin-java-miniapp/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.9.3.B
+ 3.9.4.B
weixin-java-miniapp
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index e3bd89b06..89efb9869 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.9.3.B
+ 3.9.4.B
weixin-java-mp
diff --git a/weixin-java-open/pom.xml b/weixin-java-open/pom.xml
index 1c76f92b2..03f4e2c00 100644
--- a/weixin-java-open/pom.xml
+++ b/weixin-java-open/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.9.3.B
+ 3.9.4.B
weixin-java-open
diff --git a/weixin-java-pay/pom.xml b/weixin-java-pay/pom.xml
index 35b5cb741..d84db0f46 100644
--- a/weixin-java-pay/pom.xml
+++ b/weixin-java-pay/pom.xml
@@ -5,7 +5,7 @@
com.github.binarywang
wx-java
- 3.9.3.B
+ 3.9.4.B
4.0.0