From 3eabfedd9c93e10e52348dab9cd415bdaba69402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Forever=E6=9D=A8?= <453190450@qq.com> Date: Wed, 21 Apr 2021 13:27:59 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20wx-java-open-spring-boot-starter=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=8D=E8=AF=95=E6=AC=A1=E6=95=B0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../README.md | 4 ++ .../WxOpenStorageAutoConfiguration.java | 4 +- ...tractWxOpenConfigStorageConfiguration.java | 32 ++++++++++++++ ...penInJedisConfigStorageConfiguration.java} | 13 +----- ...penInMemoryConfigStorageConfiguration.java | 13 +----- ...disTemplateConfigStorageConfiguration.java | 13 +----- ...nInRedissonConfigStorageConfiguration.java | 13 +----- .../open/properties/WxOpenProperties.java | 17 ++++++++ .../wx/miniapp/config/WxMaConfig.java | 18 +++++++- .../config/impl/WxMaDefaultConfigImpl.java | 22 ++++++++++ .../weixin/mp/config/WxMpConfigStorage.java | 16 +++++++ .../mp/config/impl/WxMpDefaultConfigImpl.java | 5 ++- .../weixin/open/api/WxOpenConfigStorage.java | 19 +++++++++ .../api/impl/WxOpenComponentServiceImpl.java | 42 +++++++++++++++---- .../api/impl/WxOpenInMemoryConfigStorage.java | 29 ++++++++++++- 15 files changed, 201 insertions(+), 59 deletions(-) create mode 100644 spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/AbstractWxOpenConfigStorageConfiguration.java rename spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/{WxOpenInRedisConfigStorageConfiguration.java => WxOpenInJedisConfigStorageConfiguration.java} (81%) diff --git a/spring-boot-starters/wx-java-open-spring-boot-starter/README.md b/spring-boot-starters/wx-java-open-spring-boot-starter/README.md index 44333f8e4..12650ac93 100644 --- a/spring-boot-starters/wx-java-open-spring-boot-starter/README.md +++ b/spring-boot-starters/wx-java-open-spring-boot-starter/README.md @@ -27,6 +27,10 @@ wx.open.config-storage.http-proxy-port= wx.open.config-storage.http-proxy-username= wx.open.config-storage.http-proxy-password= + # 最大重试次数,默认:5 次,如果小于 0,则为 0 + wx.open.config-storage.max-retry-times=5 + # 重试时间间隔步进,默认:1000 毫秒,如果小于 0,则为 1000 + wx.open.config-storage.retry-sleep-millis=1000 ``` 3. 支持自动注入的类型: `WxOpenService, WxOpenMessageRouter, WxOpenComponentService` diff --git a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/WxOpenStorageAutoConfiguration.java b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/WxOpenStorageAutoConfiguration.java index 48d023750..efbefbe0a 100644 --- a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/WxOpenStorageAutoConfiguration.java +++ b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/WxOpenStorageAutoConfiguration.java @@ -1,7 +1,7 @@ package com.binarywang.spring.starter.wxjava.open.config; +import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInJedisConfigStorageConfiguration; import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInMemoryConfigStorageConfiguration; -import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInRedisConfigStorageConfiguration; import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInRedisTemplateConfigStorageConfiguration; import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInRedissonConfigStorageConfiguration; import org.springframework.context.annotation.Configuration; @@ -16,7 +16,7 @@ import org.springframework.context.annotation.Import; @Import({ WxOpenInMemoryConfigStorageConfiguration.class, WxOpenInRedisTemplateConfigStorageConfiguration.class, - WxOpenInRedisConfigStorageConfiguration.class, + WxOpenInJedisConfigStorageConfiguration.class, WxOpenInRedissonConfigStorageConfiguration.class }) public class WxOpenStorageAutoConfiguration { diff --git a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/AbstractWxOpenConfigStorageConfiguration.java b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/AbstractWxOpenConfigStorageConfiguration.java new file mode 100644 index 000000000..0f77633e4 --- /dev/null +++ b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/AbstractWxOpenConfigStorageConfiguration.java @@ -0,0 +1,32 @@ +package com.binarywang.spring.starter.wxjava.open.config.storage; + +import com.binarywang.spring.starter.wxjava.open.properties.WxOpenProperties; +import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage; + +/** + * @author yl + */ +public abstract class AbstractWxOpenConfigStorageConfiguration { + + protected WxOpenInMemoryConfigStorage config(WxOpenInMemoryConfigStorage config, WxOpenProperties properties) { + WxOpenProperties.ConfigStorage configStorageProperties = properties.getConfigStorage(); + config.setWxOpenInfo(properties.getAppId(), properties.getSecret(), properties.getToken(), properties.getAesKey()); + config.setHttpProxyHost(configStorageProperties.getHttpProxyHost()); + config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername()); + config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword()); + if (configStorageProperties.getHttpProxyPort() != null) { + config.setHttpProxyPort(configStorageProperties.getHttpProxyPort()); + } + int maxRetryTimes = configStorageProperties.getMaxRetryTimes(); + if (configStorageProperties.getMaxRetryTimes() < 0) { + maxRetryTimes = 0; + } + int retrySleepMillis = configStorageProperties.getRetrySleepMillis(); + if (retrySleepMillis < 0) { + retrySleepMillis = 1000; + } + config.setRetrySleepMillis(retrySleepMillis); + config.setMaxRetryTimes(maxRetryTimes); + return config; + } +} diff --git a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedisConfigStorageConfiguration.java b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInJedisConfigStorageConfiguration.java similarity index 81% rename from spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedisConfigStorageConfiguration.java rename to spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInJedisConfigStorageConfiguration.java index d547a26d7..353b670e6 100644 --- a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedisConfigStorageConfiguration.java +++ b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInJedisConfigStorageConfiguration.java @@ -27,7 +27,7 @@ import redis.clients.jedis.JedisPoolConfig; ) @ConditionalOnClass({JedisPool.class, JedisPoolConfig.class}) @RequiredArgsConstructor -public class WxOpenInRedisConfigStorageConfiguration { +public class WxOpenInJedisConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration { private final WxOpenProperties properties; private final ApplicationContext applicationContext; @@ -35,16 +35,7 @@ public class WxOpenInRedisConfigStorageConfiguration { @ConditionalOnMissingBean(WxOpenConfigStorage.class) public WxOpenConfigStorage wxOpenConfigStorage() { WxOpenInMemoryConfigStorage config = getWxOpenInRedisConfigStorage(); - - WxOpenProperties.ConfigStorage configStorageProperties = properties.getConfigStorage(); - config.setWxOpenInfo(properties.getAppId(), properties.getSecret(), properties.getToken(), properties.getAesKey()); - config.setHttpProxyHost(configStorageProperties.getHttpProxyHost()); - config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername()); - config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword()); - if (configStorageProperties.getHttpProxyPort() != null) { - config.setHttpProxyPort(configStorageProperties.getHttpProxyPort()); - } - return config; + return this.config(config, properties); } private WxOpenInRedisConfigStorage getWxOpenInRedisConfigStorage() { diff --git a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInMemoryConfigStorageConfiguration.java b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInMemoryConfigStorageConfiguration.java index b85c226c7..ef1790549 100644 --- a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInMemoryConfigStorageConfiguration.java +++ b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInMemoryConfigStorageConfiguration.java @@ -18,22 +18,13 @@ import org.springframework.context.annotation.Configuration; matchIfMissing = true, havingValue = "memory" ) @RequiredArgsConstructor -public class WxOpenInMemoryConfigStorageConfiguration { +public class WxOpenInMemoryConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration { private final WxOpenProperties properties; @Bean @ConditionalOnMissingBean(WxOpenConfigStorage.class) public WxOpenConfigStorage wxOpenConfigStorage() { WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage(); - - WxOpenProperties.ConfigStorage configStorageProperties = properties.getConfigStorage(); - config.setWxOpenInfo(properties.getAppId(), properties.getSecret(), properties.getToken(), properties.getAesKey()); - config.setHttpProxyHost(configStorageProperties.getHttpProxyHost()); - config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername()); - config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword()); - if (configStorageProperties.getHttpProxyPort() != null) { - config.setHttpProxyPort(configStorageProperties.getHttpProxyPort()); - } - return config; + return this.config(config, properties); } } diff --git a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedisTemplateConfigStorageConfiguration.java b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedisTemplateConfigStorageConfiguration.java index df4008ffd..54daf8a52 100644 --- a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedisTemplateConfigStorageConfiguration.java +++ b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedisTemplateConfigStorageConfiguration.java @@ -24,7 +24,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; ) @ConditionalOnClass(StringRedisTemplate.class) @RequiredArgsConstructor -public class WxOpenInRedisTemplateConfigStorageConfiguration { +public class WxOpenInRedisTemplateConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration { private final WxOpenProperties properties; private final ApplicationContext applicationContext; @@ -32,16 +32,7 @@ public class WxOpenInRedisTemplateConfigStorageConfiguration { @ConditionalOnMissingBean(WxOpenConfigStorage.class) public WxOpenConfigStorage wxOpenConfigStorage() { WxOpenInMemoryConfigStorage config = getWxOpenInRedisTemplateConfigStorage(); - - WxOpenProperties.ConfigStorage configStorageProperties = properties.getConfigStorage(); - config.setWxOpenInfo(properties.getAppId(), properties.getSecret(), properties.getToken(), properties.getAesKey()); - config.setHttpProxyHost(configStorageProperties.getHttpProxyHost()); - config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername()); - config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword()); - if (configStorageProperties.getHttpProxyPort() != null) { - config.setHttpProxyPort(configStorageProperties.getHttpProxyPort()); - } - return config; + return this.config(config, properties); } private WxOpenInRedisConfigStorage getWxOpenInRedisTemplateConfigStorage() { diff --git a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedissonConfigStorageConfiguration.java b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedissonConfigStorageConfiguration.java index 8d3bf1214..85aa1d20e 100644 --- a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedissonConfigStorageConfiguration.java +++ b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedissonConfigStorageConfiguration.java @@ -29,7 +29,7 @@ import org.springframework.context.annotation.Configuration; ) @ConditionalOnClass({Redisson.class, RedissonClient.class}) @RequiredArgsConstructor -public class WxOpenInRedissonConfigStorageConfiguration { +public class WxOpenInRedissonConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration { private final WxOpenProperties properties; private final ApplicationContext applicationContext; @@ -37,16 +37,7 @@ public class WxOpenInRedissonConfigStorageConfiguration { @ConditionalOnMissingBean(WxOpenConfigStorage.class) public WxOpenConfigStorage wxOpenConfigStorage() { WxOpenInMemoryConfigStorage config = getWxOpenInRedissonConfigStorage(); - - WxOpenProperties.ConfigStorage configStorageProperties = properties.getConfigStorage(); - config.setWxOpenInfo(properties.getAppId(), properties.getSecret(), properties.getToken(), properties.getAesKey()); - config.setHttpProxyHost(configStorageProperties.getHttpProxyHost()); - config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername()); - config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword()); - if (configStorageProperties.getHttpProxyPort() != null) { - config.setHttpProxyPort(configStorageProperties.getHttpProxyPort()); - } - return config; + return this.config(config, properties); } private WxOpenInRedisConfigStorage getWxOpenInRedissonConfigStorage() { diff --git a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/properties/WxOpenProperties.java b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/properties/WxOpenProperties.java index 6e351a4cc..adb35c2fa 100644 --- a/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/properties/WxOpenProperties.java +++ b/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/properties/WxOpenProperties.java @@ -91,6 +91,23 @@ public class WxOpenProperties { */ private String httpProxyPassword; + /** + * http 请求重试间隔 + *
+ * {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setRetrySleepMillis(int)}
+ * {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)}
+ *
+ */
+ private int retrySleepMillis = 1000;
+ /**
+ * http 请求最大重试次数
+ *
+ * {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setMaxRetryTimes(int)}
+ * {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)}
+ *
+ */
+ private int maxRetryTimes = 5;
+
}
public enum StorageType {
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/WxMaConfig.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/WxMaConfig.java
index c1ad10682..b8ba1e188 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/WxMaConfig.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/WxMaConfig.java
@@ -205,6 +205,22 @@ public interface WxMaConfig {
*/
String getHttpProxyPassword();
+ /**
+ * http 请求重试间隔
+ *
+ * {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)}
+ *
+ */
+ int getRetrySleepMillis();
+
+ /**
+ * http 请求最大重试次数
+ *
+ * {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)}
+ *
+ */
+ int getMaxRetryTimes();
+
/**
* http client builder
*
@@ -231,7 +247,7 @@ public interface WxMaConfig {
* 获取自定义的apiHost地址,用于替换原请求中的https://api.weixin.qq.com
* 具体取值,可以参考https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Interface_field_description.html
*
- * @return 自定义的api域名地址
+ * @return 自定义的api域名地址
*/
String getApiHostUrl();
}
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/WxMaDefaultConfigImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/WxMaDefaultConfigImpl.java
index ffec79141..c05d6f1aa 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/WxMaDefaultConfigImpl.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/WxMaDefaultConfigImpl.java
@@ -41,6 +41,10 @@ public class WxMaDefaultConfigImpl implements WxMaConfig {
private volatile int httpProxyPort;
private volatile String httpProxyUsername;
private volatile String httpProxyPassword;
+
+ private volatile int retrySleepMillis = 1000;
+ private volatile int maxRetryTimes = 5;
+
private volatile String jsapiTicket;
private volatile long jsapiTicketExpiresTime;
/**
@@ -257,6 +261,24 @@ public class WxMaDefaultConfigImpl implements WxMaConfig {
this.httpProxyPassword = httpProxyPassword;
}
+ @Override
+ public int getRetrySleepMillis() {
+ return this.retrySleepMillis;
+ }
+
+ public void setRetrySleepMillis(int retrySleepMillis) {
+ this.retrySleepMillis = retrySleepMillis;
+ }
+
+ @Override
+ public int getMaxRetryTimes() {
+ return this.maxRetryTimes;
+ }
+
+ public void setMaxRetryTimes(int maxRetryTimes) {
+ this.maxRetryTimes = maxRetryTimes;
+ }
+
@Override
public String toString() {
return WxMaGsonBuilder.create().toJson(this);
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/config/WxMpConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/config/WxMpConfigStorage.java
index b9f4d13e7..8604bfd72 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/config/WxMpConfigStorage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/config/WxMpConfigStorage.java
@@ -172,6 +172,22 @@ public interface WxMpConfigStorage {
*/
String getHttpProxyPassword();
+ /**
+ * http 请求重试间隔
+ *
+ * {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setRetrySleepMillis(int)}
+ *
+ */
+ int getRetrySleepMillis();
+
+ /**
+ * http 请求最大重试次数
+ *
+ * {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setMaxRetryTimes(int)}
+ *
+ */
+ int getMaxRetryTimes();
+
/**
* Gets tmp dir file.
*
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/config/impl/WxMpDefaultConfigImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/config/impl/WxMpDefaultConfigImpl.java
index 0a531835c..0b31ade5c 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/config/impl/WxMpDefaultConfigImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/config/impl/WxMpDefaultConfigImpl.java
@@ -4,8 +4,8 @@ import lombok.Data;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.enums.TicketType;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
-import me.chanjar.weixin.mp.config.WxMpHostConfig;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
+import me.chanjar.weixin.mp.config.WxMpHostConfig;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.io.File;
@@ -37,6 +37,9 @@ public class WxMpDefaultConfigImpl implements WxMpConfigStorage, Serializable {
protected volatile String httpProxyUsername;
protected volatile String httpProxyPassword;
+ protected volatile int retrySleepMillis = 1000;
+ protected volatile int maxRetryTimes = 5;
+
protected volatile String jsapiTicket;
protected volatile long jsapiTicketExpiresTime;
diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java
index 4b496b30d..60304604d 100644
--- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java
+++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java
@@ -139,6 +139,24 @@ public interface WxOpenConfigStorage {
*/
String getHttpProxyPassword();
+ /**
+ * http 请求重试间隔
+ *
+ * {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setRetrySleepMillis(int)}
+ * {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)}
+ *
+ */
+ int getRetrySleepMillis();
+
+ /**
+ * http 请求最大重试次数
+ *
+ * {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setMaxRetryTimes(int)}
+ * {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)}
+ *
+ */
+ int getMaxRetryTimes();
+
/**
* Gets apache http client builder.
*
@@ -210,6 +228,7 @@ public interface WxOpenConfigStorage {
/**
* setAuthorizerRefreshToken(String appId, String authorizerRefreshToken) 方法重载方法
+ *
* @param appId the app id
* @param authorizerRefreshToken the authorizer refresh token
*/
diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java
index b6fc3a8a3..bc194aef7 100644
--- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java
+++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java
@@ -6,6 +6,7 @@ import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
+import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.error.WxRuntimeException;
@@ -14,12 +15,24 @@ import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
-import me.chanjar.weixin.open.api.*;
-import me.chanjar.weixin.open.bean.*;
+import me.chanjar.weixin.open.api.WxOpenComponentService;
+import me.chanjar.weixin.open.api.WxOpenConfigStorage;
+import me.chanjar.weixin.open.api.WxOpenFastMaService;
+import me.chanjar.weixin.open.api.WxOpenMaService;
+import me.chanjar.weixin.open.api.WxOpenMpService;
+import me.chanjar.weixin.open.api.WxOpenService;
+import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken;
+import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken;
+import me.chanjar.weixin.open.bean.WxOpenCreateResult;
+import me.chanjar.weixin.open.bean.WxOpenGetResult;
+import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate;
import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo;
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage;
-import me.chanjar.weixin.open.bean.result.*;
+import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult;
+import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerListResult;
+import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult;
+import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult;
+import me.chanjar.weixin.open.bean.result.WxOpenResult;
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder;
import org.apache.commons.lang3.StringUtils;
@@ -49,8 +62,11 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
synchronized (WX_OPEN_MP_SERVICE_MAP) {
wxMpService = WX_OPEN_MP_SERVICE_MAP.get(appId);
if (wxMpService == null) {
- wxMpService = new WxOpenMpServiceImpl(this, appId, getWxOpenConfigStorage().getWxMpConfigStorage(appId));
-
+ WxOpenConfigStorage storage = this.getWxOpenConfigStorage();
+ wxMpService = new WxOpenMpServiceImpl(this, appId, storage.getWxMpConfigStorage(appId));
+ // 配置重试次数和重试间隔
+ wxMpService.setMaxRetryTimes(storage.getMaxRetryTimes());
+ wxMpService.setRetrySleepMillis(storage.getRetrySleepMillis());
WX_OPEN_MP_SERVICE_MAP.put(appId, wxMpService);
}
}
@@ -65,7 +81,11 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
synchronized (WX_OPEN_MA_SERVICE_MAP) {
wxOpenMaService = WX_OPEN_MA_SERVICE_MAP.get(appId);
if (wxOpenMaService == null) {
- wxOpenMaService = new WxOpenMaServiceImpl(this, appId, getWxOpenConfigStorage().getWxMaConfig(appId));
+ WxOpenConfigStorage storage = this.getWxOpenConfigStorage();
+ wxOpenMaService = new WxOpenMaServiceImpl(this, appId, storage.getWxMaConfig(appId));
+ // 配置重试次数和重试间隔
+ wxOpenMaService.setMaxRetryTimes(storage.getMaxRetryTimes());
+ wxOpenMaService.setRetrySleepMillis(storage.getRetrySleepMillis());
WX_OPEN_MA_SERVICE_MAP.put(appId, wxOpenMaService);
}
}
@@ -80,7 +100,11 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
synchronized (WX_OPEN_FAST_MA_SERVICE_MAP) {
fastMaService = WX_OPEN_FAST_MA_SERVICE_MAP.get(appId);
if (fastMaService == null) {
- fastMaService = new WxOpenFastMaServiceImpl(this, appId, getWxOpenConfigStorage().getWxMaConfig(appId));
+ WxOpenConfigStorage storage = this.getWxOpenConfigStorage();
+ fastMaService = new WxOpenFastMaServiceImpl(this, appId, storage.getWxMaConfig(appId));
+ // 配置重试次数和重试间隔
+ fastMaService.setMaxRetryTimes(storage.getMaxRetryTimes());
+ fastMaService.setRetrySleepMillis(storage.getRetrySleepMillis());
WX_OPEN_FAST_MA_SERVICE_MAP.put(appId, fastMaService);
}
}
@@ -103,7 +127,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
return SHA1.gen(getWxOpenConfigStorage().getComponentToken(), timestamp, nonce)
.equals(signature);
} catch (Exception e) {
- this.log.error("Checking signature failed, and the reason is :" + e.getMessage());
+ log.error("Checking signature failed, and the reason is :" + e.getMessage());
return false;
}
}
diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java
index 6f0f47779..4a01dd4ec 100644
--- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java
+++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java
@@ -3,12 +3,11 @@ package me.chanjar.weixin.open.api.impl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import lombok.Data;
-import lombok.Getter;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.enums.TicketType;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
-import me.chanjar.weixin.mp.config.WxMpHostConfig;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
+import me.chanjar.weixin.mp.config.WxMpHostConfig;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken;
import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken;
@@ -39,6 +38,22 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
private int httpProxyPort;
private String httpProxyUsername;
private String httpProxyPassword;
+ /**
+ * http 请求重试间隔
+ *
+ * {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setRetrySleepMillis(int)}
+ * {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)}
+ *
+ */
+ private int retrySleepMillis = 1000;
+ /**
+ * http 请求最大重试次数
+ *
+ * {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setMaxRetryTimes(int)}
+ * {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)}
+ *
+ */
+ private int maxRetryTimes = 5;
private ApacheHttpClientBuilder apacheHttpClientBuilder;
private Map