mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
#567 微信开放平台增加 HTTP proxy 机制
* 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀; * 微信开放平台:增加小程序代码模板库管理 * 小程序:增加代码管理相关 API * 小程序:增加修改服务器地址、成员管理 API * 小程序:增加数据分析相关 API * 微信开放平台:增加 HTTP proxy 机制
This commit is contained in:
parent
3c2249eae8
commit
04ec788d07
@ -38,6 +38,14 @@ public interface WxOpenConfigStorage {
|
||||
|
||||
void updateComponentAccessTokent(WxOpenComponentAccessToken componentAccessToken);
|
||||
|
||||
String getHttpProxyHost();
|
||||
|
||||
int getHttpProxyPort();
|
||||
|
||||
String getHttpProxyUsername();
|
||||
|
||||
String getHttpProxyPassword();
|
||||
|
||||
WxMpConfigStorage getWxMpConfigStorage(String appId);
|
||||
|
||||
WxMaConfig getWxMaConfig(String appId);
|
||||
@ -117,5 +125,4 @@ public interface WxOpenConfigStorage {
|
||||
* @param expiresInSeconds 过期时间,以秒为单位
|
||||
*/
|
||||
void updateCardApiTicket(String appId, String cardApiTicket, int expiresInSeconds);
|
||||
|
||||
}
|
||||
|
@ -30,6 +30,11 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
|
||||
private String componentAccessToken;
|
||||
private long componentExpiresTime;
|
||||
|
||||
private String httpProxyHost;
|
||||
private int httpProxyPort;
|
||||
private String httpProxyUsername;
|
||||
private String httpProxyPassword;
|
||||
|
||||
private Map<String, Token> authorizerRefreshTokens = new Hashtable<>();
|
||||
private Map<String, Token> authorizerAccessTokens = new Hashtable<>();
|
||||
private Map<String, Token> jsapiTickets = new Hashtable<>();
|
||||
@ -105,6 +110,42 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
|
||||
updateComponentAccessTokent(componentAccessToken.getComponentAccessToken(), componentAccessToken.getExpiresIn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHttpProxyHost() {
|
||||
return httpProxyHost;
|
||||
}
|
||||
|
||||
public void setHttpProxyHost(String httpProxyHost) {
|
||||
this.httpProxyHost = httpProxyHost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHttpProxyPort() {
|
||||
return httpProxyPort;
|
||||
}
|
||||
|
||||
public void setHttpProxyPort(int httpProxyPort) {
|
||||
this.httpProxyPort = httpProxyPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHttpProxyUsername() {
|
||||
return httpProxyUsername;
|
||||
}
|
||||
|
||||
public void setHttpProxyUsername(String httpProxyUsername) {
|
||||
this.httpProxyUsername = httpProxyUsername;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHttpProxyPassword() {
|
||||
return httpProxyPassword;
|
||||
}
|
||||
|
||||
public void setHttpProxyPassword(String httpProxyPassword) {
|
||||
this.httpProxyPassword = httpProxyPassword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpConfigStorage getWxMpConfigStorage(String appId) {
|
||||
return new WxOpenInnerConfigStorage(this, appId);
|
||||
@ -377,22 +418,22 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
|
||||
|
||||
@Override
|
||||
public String getHttpProxyHost() {
|
||||
return null;
|
||||
return this.wxOpenConfigStorage.getHttpProxyHost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHttpProxyPort() {
|
||||
return 0;
|
||||
return this.wxOpenConfigStorage.getHttpProxyPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHttpProxyUsername() {
|
||||
return null;
|
||||
return this.wxOpenConfigStorage.getHttpProxyUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHttpProxyPassword() {
|
||||
return null;
|
||||
return this.wxOpenConfigStorage.getHttpProxyPassword();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,8 +33,14 @@ public abstract class WxOpenServiceAbstractImpl<H, P> implements WxOpenService,
|
||||
@Override
|
||||
public void setWxOpenConfigStorage(WxOpenConfigStorage wxOpenConfigStorage) {
|
||||
this.wxOpenConfigStorage = wxOpenConfigStorage;
|
||||
this.initHttp();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 RequestHttp
|
||||
*/
|
||||
public abstract void initHttp();
|
||||
|
||||
protected synchronized <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
|
||||
try {
|
||||
T result = executor.execute(uri, data);
|
||||
|
@ -5,6 +5,7 @@ import me.chanjar.weixin.common.util.http.HttpType;
|
||||
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
@ -14,8 +15,21 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
public class WxOpenServiceApacheHttpClientImpl extends WxOpenServiceAbstractImpl<CloseableHttpClient, HttpHost> {
|
||||
private CloseableHttpClient httpClient = DefaultApacheHttpClientBuilder.get().build();
|
||||
private HttpHost httpProxy = null;
|
||||
private CloseableHttpClient httpClient;
|
||||
private HttpHost httpProxy;
|
||||
|
||||
@Override
|
||||
public void initHttp() {
|
||||
WxOpenConfigStorage configStorage = this.getWxOpenConfigStorage();
|
||||
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
|
||||
this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort());
|
||||
}
|
||||
this.httpClient = DefaultApacheHttpClientBuilder.get()
|
||||
.httpProxyHost(configStorage.getHttpProxyHost())
|
||||
.httpProxyPort(configStorage.getHttpProxyPort())
|
||||
.httpProxyUsername(configStorage.getHttpProxyUsername())
|
||||
.httpProxyPassword(configStorage.getHttpProxyPassword()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloseableHttpClient getRequestHttpClient() {
|
||||
@ -41,5 +55,4 @@ public class WxOpenServiceApacheHttpClientImpl extends WxOpenServiceAbstractImpl
|
||||
public String post(String url, String postData) throws WxErrorException {
|
||||
return execute(SimplePostRequestExecutor.create(this), url, postData);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user