mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
🎨 wx-java-open-spring-boot-starter 增加重试次数配置
This commit is contained in:
parent
0a75b0e902
commit
3eabfedd9c
@ -27,6 +27,10 @@
|
|||||||
wx.open.config-storage.http-proxy-port=
|
wx.open.config-storage.http-proxy-port=
|
||||||
wx.open.config-storage.http-proxy-username=
|
wx.open.config-storage.http-proxy-username=
|
||||||
wx.open.config-storage.http-proxy-password=
|
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`
|
3. 支持自动注入的类型: `WxOpenService, WxOpenMessageRouter, WxOpenComponentService`
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.binarywang.spring.starter.wxjava.open.config;
|
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.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.WxOpenInRedisTemplateConfigStorageConfiguration;
|
||||||
import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInRedissonConfigStorageConfiguration;
|
import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInRedissonConfigStorageConfiguration;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@ -16,7 +16,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
@Import({
|
@Import({
|
||||||
WxOpenInMemoryConfigStorageConfiguration.class,
|
WxOpenInMemoryConfigStorageConfiguration.class,
|
||||||
WxOpenInRedisTemplateConfigStorageConfiguration.class,
|
WxOpenInRedisTemplateConfigStorageConfiguration.class,
|
||||||
WxOpenInRedisConfigStorageConfiguration.class,
|
WxOpenInJedisConfigStorageConfiguration.class,
|
||||||
WxOpenInRedissonConfigStorageConfiguration.class
|
WxOpenInRedissonConfigStorageConfiguration.class
|
||||||
})
|
})
|
||||||
public class WxOpenStorageAutoConfiguration {
|
public class WxOpenStorageAutoConfiguration {
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -27,7 +27,7 @@ import redis.clients.jedis.JedisPoolConfig;
|
|||||||
)
|
)
|
||||||
@ConditionalOnClass({JedisPool.class, JedisPoolConfig.class})
|
@ConditionalOnClass({JedisPool.class, JedisPoolConfig.class})
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class WxOpenInRedisConfigStorageConfiguration {
|
public class WxOpenInJedisConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration {
|
||||||
private final WxOpenProperties properties;
|
private final WxOpenProperties properties;
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
|
|
||||||
@ -35,16 +35,7 @@ public class WxOpenInRedisConfigStorageConfiguration {
|
|||||||
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
|
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
|
||||||
public WxOpenConfigStorage wxOpenConfigStorage() {
|
public WxOpenConfigStorage wxOpenConfigStorage() {
|
||||||
WxOpenInMemoryConfigStorage config = getWxOpenInRedisConfigStorage();
|
WxOpenInMemoryConfigStorage config = getWxOpenInRedisConfigStorage();
|
||||||
|
return this.config(config, 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());
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private WxOpenInRedisConfigStorage getWxOpenInRedisConfigStorage() {
|
private WxOpenInRedisConfigStorage getWxOpenInRedisConfigStorage() {
|
@ -18,22 +18,13 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
matchIfMissing = true, havingValue = "memory"
|
matchIfMissing = true, havingValue = "memory"
|
||||||
)
|
)
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class WxOpenInMemoryConfigStorageConfiguration {
|
public class WxOpenInMemoryConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration {
|
||||||
private final WxOpenProperties properties;
|
private final WxOpenProperties properties;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
|
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
|
||||||
public WxOpenConfigStorage wxOpenConfigStorage() {
|
public WxOpenConfigStorage wxOpenConfigStorage() {
|
||||||
WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage();
|
WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage();
|
||||||
|
return this.config(config, 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());
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|||||||
)
|
)
|
||||||
@ConditionalOnClass(StringRedisTemplate.class)
|
@ConditionalOnClass(StringRedisTemplate.class)
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class WxOpenInRedisTemplateConfigStorageConfiguration {
|
public class WxOpenInRedisTemplateConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration {
|
||||||
private final WxOpenProperties properties;
|
private final WxOpenProperties properties;
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
|
|
||||||
@ -32,16 +32,7 @@ public class WxOpenInRedisTemplateConfigStorageConfiguration {
|
|||||||
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
|
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
|
||||||
public WxOpenConfigStorage wxOpenConfigStorage() {
|
public WxOpenConfigStorage wxOpenConfigStorage() {
|
||||||
WxOpenInMemoryConfigStorage config = getWxOpenInRedisTemplateConfigStorage();
|
WxOpenInMemoryConfigStorage config = getWxOpenInRedisTemplateConfigStorage();
|
||||||
|
return this.config(config, 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());
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private WxOpenInRedisConfigStorage getWxOpenInRedisTemplateConfigStorage() {
|
private WxOpenInRedisConfigStorage getWxOpenInRedisTemplateConfigStorage() {
|
||||||
|
@ -29,7 +29,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
)
|
)
|
||||||
@ConditionalOnClass({Redisson.class, RedissonClient.class})
|
@ConditionalOnClass({Redisson.class, RedissonClient.class})
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class WxOpenInRedissonConfigStorageConfiguration {
|
public class WxOpenInRedissonConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration {
|
||||||
private final WxOpenProperties properties;
|
private final WxOpenProperties properties;
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
|
|
||||||
@ -37,16 +37,7 @@ public class WxOpenInRedissonConfigStorageConfiguration {
|
|||||||
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
|
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
|
||||||
public WxOpenConfigStorage wxOpenConfigStorage() {
|
public WxOpenConfigStorage wxOpenConfigStorage() {
|
||||||
WxOpenInMemoryConfigStorage config = getWxOpenInRedissonConfigStorage();
|
WxOpenInMemoryConfigStorage config = getWxOpenInRedissonConfigStorage();
|
||||||
|
return this.config(config, 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());
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private WxOpenInRedisConfigStorage getWxOpenInRedissonConfigStorage() {
|
private WxOpenInRedisConfigStorage getWxOpenInRedissonConfigStorage() {
|
||||||
|
@ -91,6 +91,23 @@ public class WxOpenProperties {
|
|||||||
*/
|
*/
|
||||||
private String httpProxyPassword;
|
private String httpProxyPassword;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http 请求重试间隔
|
||||||
|
* <pre>
|
||||||
|
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setRetrySleepMillis(int)}
|
||||||
|
* {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)}
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
private int retrySleepMillis = 1000;
|
||||||
|
/**
|
||||||
|
* http 请求最大重试次数
|
||||||
|
* <pre>
|
||||||
|
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setMaxRetryTimes(int)}
|
||||||
|
* {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)}
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
private int maxRetryTimes = 5;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum StorageType {
|
public enum StorageType {
|
||||||
|
@ -205,6 +205,22 @@ public interface WxMaConfig {
|
|||||||
*/
|
*/
|
||||||
String getHttpProxyPassword();
|
String getHttpProxyPassword();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http 请求重试间隔
|
||||||
|
* <pre>
|
||||||
|
* {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)}
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
int getRetrySleepMillis();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http 请求最大重试次数
|
||||||
|
* <pre>
|
||||||
|
* {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)}
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
int getMaxRetryTimes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http client builder
|
* http client builder
|
||||||
*
|
*
|
||||||
|
@ -41,6 +41,10 @@ public class WxMaDefaultConfigImpl implements WxMaConfig {
|
|||||||
private volatile int httpProxyPort;
|
private volatile int httpProxyPort;
|
||||||
private volatile String httpProxyUsername;
|
private volatile String httpProxyUsername;
|
||||||
private volatile String httpProxyPassword;
|
private volatile String httpProxyPassword;
|
||||||
|
|
||||||
|
private volatile int retrySleepMillis = 1000;
|
||||||
|
private volatile int maxRetryTimes = 5;
|
||||||
|
|
||||||
private volatile String jsapiTicket;
|
private volatile String jsapiTicket;
|
||||||
private volatile long jsapiTicketExpiresTime;
|
private volatile long jsapiTicketExpiresTime;
|
||||||
/**
|
/**
|
||||||
@ -257,6 +261,24 @@ public class WxMaDefaultConfigImpl implements WxMaConfig {
|
|||||||
this.httpProxyPassword = httpProxyPassword;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return WxMaGsonBuilder.create().toJson(this);
|
return WxMaGsonBuilder.create().toJson(this);
|
||||||
|
@ -172,6 +172,22 @@ public interface WxMpConfigStorage {
|
|||||||
*/
|
*/
|
||||||
String getHttpProxyPassword();
|
String getHttpProxyPassword();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http 请求重试间隔
|
||||||
|
* <pre>
|
||||||
|
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setRetrySleepMillis(int)}
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
int getRetrySleepMillis();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http 请求最大重试次数
|
||||||
|
* <pre>
|
||||||
|
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setMaxRetryTimes(int)}
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
int getMaxRetryTimes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets tmp dir file.
|
* Gets tmp dir file.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,8 @@ import lombok.Data;
|
|||||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||||
import me.chanjar.weixin.common.enums.TicketType;
|
import me.chanjar.weixin.common.enums.TicketType;
|
||||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
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.WxMpConfigStorage;
|
||||||
|
import me.chanjar.weixin.mp.config.WxMpHostConfig;
|
||||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -37,6 +37,9 @@ public class WxMpDefaultConfigImpl implements WxMpConfigStorage, Serializable {
|
|||||||
protected volatile String httpProxyUsername;
|
protected volatile String httpProxyUsername;
|
||||||
protected volatile String httpProxyPassword;
|
protected volatile String httpProxyPassword;
|
||||||
|
|
||||||
|
protected volatile int retrySleepMillis = 1000;
|
||||||
|
protected volatile int maxRetryTimes = 5;
|
||||||
|
|
||||||
protected volatile String jsapiTicket;
|
protected volatile String jsapiTicket;
|
||||||
protected volatile long jsapiTicketExpiresTime;
|
protected volatile long jsapiTicketExpiresTime;
|
||||||
|
|
||||||
|
@ -139,6 +139,24 @@ public interface WxOpenConfigStorage {
|
|||||||
*/
|
*/
|
||||||
String getHttpProxyPassword();
|
String getHttpProxyPassword();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http 请求重试间隔
|
||||||
|
* <pre>
|
||||||
|
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setRetrySleepMillis(int)}
|
||||||
|
* {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)}
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
int getRetrySleepMillis();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http 请求最大重试次数
|
||||||
|
* <pre>
|
||||||
|
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setMaxRetryTimes(int)}
|
||||||
|
* {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)}
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
int getMaxRetryTimes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets apache http client builder.
|
* Gets apache http client builder.
|
||||||
*
|
*
|
||||||
@ -210,6 +228,7 @@ public interface WxOpenConfigStorage {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setAuthorizerRefreshToken(String appId, String authorizerRefreshToken) 方法重载方法
|
* setAuthorizerRefreshToken(String appId, String authorizerRefreshToken) 方法重载方法
|
||||||
|
*
|
||||||
* @param appId the app id
|
* @param appId the app id
|
||||||
* @param authorizerRefreshToken the authorizer refresh token
|
* @param authorizerRefreshToken the authorizer refresh token
|
||||||
*/
|
*/
|
||||||
|
@ -6,6 +6,7 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import me.chanjar.weixin.common.api.WxConsts;
|
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.WxError;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
import me.chanjar.weixin.common.error.WxRuntimeException;
|
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.GsonParser;
|
||||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
|
import me.chanjar.weixin.open.api.WxOpenComponentService;
|
||||||
import me.chanjar.weixin.open.api.*;
|
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
|
||||||
import me.chanjar.weixin.open.bean.*;
|
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.auth.WxOpenAuthorizationInfo;
|
||||||
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage;
|
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 me.chanjar.weixin.open.util.json.WxOpenGsonBuilder;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@ -49,8 +62,11 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
|
|||||||
synchronized (WX_OPEN_MP_SERVICE_MAP) {
|
synchronized (WX_OPEN_MP_SERVICE_MAP) {
|
||||||
wxMpService = WX_OPEN_MP_SERVICE_MAP.get(appId);
|
wxMpService = WX_OPEN_MP_SERVICE_MAP.get(appId);
|
||||||
if (wxMpService == null) {
|
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);
|
WX_OPEN_MP_SERVICE_MAP.put(appId, wxMpService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,7 +81,11 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
|
|||||||
synchronized (WX_OPEN_MA_SERVICE_MAP) {
|
synchronized (WX_OPEN_MA_SERVICE_MAP) {
|
||||||
wxOpenMaService = WX_OPEN_MA_SERVICE_MAP.get(appId);
|
wxOpenMaService = WX_OPEN_MA_SERVICE_MAP.get(appId);
|
||||||
if (wxOpenMaService == null) {
|
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);
|
WX_OPEN_MA_SERVICE_MAP.put(appId, wxOpenMaService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +100,11 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
|
|||||||
synchronized (WX_OPEN_FAST_MA_SERVICE_MAP) {
|
synchronized (WX_OPEN_FAST_MA_SERVICE_MAP) {
|
||||||
fastMaService = WX_OPEN_FAST_MA_SERVICE_MAP.get(appId);
|
fastMaService = WX_OPEN_FAST_MA_SERVICE_MAP.get(appId);
|
||||||
if (fastMaService == null) {
|
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);
|
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)
|
return SHA1.gen(getWxOpenConfigStorage().getComponentToken(), timestamp, nonce)
|
||||||
.equals(signature);
|
.equals(signature);
|
||||||
} catch (Exception e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,11 @@ package me.chanjar.weixin.open.api.impl;
|
|||||||
|
|
||||||
import cn.binarywang.wx.miniapp.config.WxMaConfig;
|
import cn.binarywang.wx.miniapp.config.WxMaConfig;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
|
||||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||||
import me.chanjar.weixin.common.enums.TicketType;
|
import me.chanjar.weixin.common.enums.TicketType;
|
||||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
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.WxMpConfigStorage;
|
||||||
|
import me.chanjar.weixin.mp.config.WxMpHostConfig;
|
||||||
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
|
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
|
||||||
import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken;
|
import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken;
|
||||||
import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken;
|
import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken;
|
||||||
@ -39,6 +38,22 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
|
|||||||
private int httpProxyPort;
|
private int httpProxyPort;
|
||||||
private String httpProxyUsername;
|
private String httpProxyUsername;
|
||||||
private String httpProxyPassword;
|
private String httpProxyPassword;
|
||||||
|
/**
|
||||||
|
* http 请求重试间隔
|
||||||
|
* <pre>
|
||||||
|
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setRetrySleepMillis(int)}
|
||||||
|
* {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)}
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
private int retrySleepMillis = 1000;
|
||||||
|
/**
|
||||||
|
* http 请求最大重试次数
|
||||||
|
* <pre>
|
||||||
|
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setMaxRetryTimes(int)}
|
||||||
|
* {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)}
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
private int maxRetryTimes = 5;
|
||||||
private ApacheHttpClientBuilder apacheHttpClientBuilder;
|
private ApacheHttpClientBuilder apacheHttpClientBuilder;
|
||||||
|
|
||||||
private Map<String, Token> authorizerRefreshTokens = new ConcurrentHashMap<>();
|
private Map<String, Token> authorizerRefreshTokens = new ConcurrentHashMap<>();
|
||||||
@ -511,6 +526,16 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
|
|||||||
return this.wxOpenConfigStorage.getHttpProxyPassword();
|
return this.wxOpenConfigStorage.getHttpProxyPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRetrySleepMillis() {
|
||||||
|
return this.wxOpenConfigStorage.getRetrySleepMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxRetryTimes() {
|
||||||
|
return this.wxOpenConfigStorage.getMaxRetryTimes();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return WxOpenGsonBuilder.create().toJson(this);
|
return WxOpenGsonBuilder.create().toJson(this);
|
||||||
|
Loading…
Reference in New Issue
Block a user