mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 16:18:51 +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);
|
void updateComponentAccessTokent(WxOpenComponentAccessToken componentAccessToken);
|
||||||
|
|
||||||
|
String getHttpProxyHost();
|
||||||
|
|
||||||
|
int getHttpProxyPort();
|
||||||
|
|
||||||
|
String getHttpProxyUsername();
|
||||||
|
|
||||||
|
String getHttpProxyPassword();
|
||||||
|
|
||||||
WxMpConfigStorage getWxMpConfigStorage(String appId);
|
WxMpConfigStorage getWxMpConfigStorage(String appId);
|
||||||
|
|
||||||
WxMaConfig getWxMaConfig(String appId);
|
WxMaConfig getWxMaConfig(String appId);
|
||||||
@ -117,5 +125,4 @@ public interface WxOpenConfigStorage {
|
|||||||
* @param expiresInSeconds 过期时间,以秒为单位
|
* @param expiresInSeconds 过期时间,以秒为单位
|
||||||
*/
|
*/
|
||||||
void updateCardApiTicket(String appId, String cardApiTicket, int expiresInSeconds);
|
void updateCardApiTicket(String appId, String cardApiTicket, int expiresInSeconds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,11 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
|
|||||||
private String componentAccessToken;
|
private String componentAccessToken;
|
||||||
private long componentExpiresTime;
|
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> authorizerRefreshTokens = new Hashtable<>();
|
||||||
private Map<String, Token> authorizerAccessTokens = new Hashtable<>();
|
private Map<String, Token> authorizerAccessTokens = new Hashtable<>();
|
||||||
private Map<String, Token> jsapiTickets = new Hashtable<>();
|
private Map<String, Token> jsapiTickets = new Hashtable<>();
|
||||||
@ -105,6 +110,42 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
|
|||||||
updateComponentAccessTokent(componentAccessToken.getComponentAccessToken(), componentAccessToken.getExpiresIn());
|
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
|
@Override
|
||||||
public WxMpConfigStorage getWxMpConfigStorage(String appId) {
|
public WxMpConfigStorage getWxMpConfigStorage(String appId) {
|
||||||
return new WxOpenInnerConfigStorage(this, appId);
|
return new WxOpenInnerConfigStorage(this, appId);
|
||||||
@ -377,22 +418,22 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHttpProxyHost() {
|
public String getHttpProxyHost() {
|
||||||
return null;
|
return this.wxOpenConfigStorage.getHttpProxyHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHttpProxyPort() {
|
public int getHttpProxyPort() {
|
||||||
return 0;
|
return this.wxOpenConfigStorage.getHttpProxyPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHttpProxyUsername() {
|
public String getHttpProxyUsername() {
|
||||||
return null;
|
return this.wxOpenConfigStorage.getHttpProxyUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHttpProxyPassword() {
|
public String getHttpProxyPassword() {
|
||||||
return null;
|
return this.wxOpenConfigStorage.getHttpProxyPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,8 +33,14 @@ public abstract class WxOpenServiceAbstractImpl<H, P> implements WxOpenService,
|
|||||||
@Override
|
@Override
|
||||||
public void setWxOpenConfigStorage(WxOpenConfigStorage wxOpenConfigStorage) {
|
public void setWxOpenConfigStorage(WxOpenConfigStorage wxOpenConfigStorage) {
|
||||||
this.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 {
|
protected synchronized <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
|
||||||
try {
|
try {
|
||||||
T result = executor.execute(uri, data);
|
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.SimpleGetRequestExecutor;
|
||||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||||
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
|
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.HttpHost;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
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>
|
* @author <a href="https://github.com/007gzs">007</a>
|
||||||
*/
|
*/
|
||||||
public class WxOpenServiceApacheHttpClientImpl extends WxOpenServiceAbstractImpl<CloseableHttpClient, HttpHost> {
|
public class WxOpenServiceApacheHttpClientImpl extends WxOpenServiceAbstractImpl<CloseableHttpClient, HttpHost> {
|
||||||
private CloseableHttpClient httpClient = DefaultApacheHttpClientBuilder.get().build();
|
private CloseableHttpClient httpClient;
|
||||||
private HttpHost httpProxy = null;
|
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
|
@Override
|
||||||
public CloseableHttpClient getRequestHttpClient() {
|
public CloseableHttpClient getRequestHttpClient() {
|
||||||
@ -41,5 +55,4 @@ public class WxOpenServiceApacheHttpClientImpl extends WxOpenServiceAbstractImpl
|
|||||||
public String post(String url, String postData) throws WxErrorException {
|
public String post(String url, String postData) throws WxErrorException {
|
||||||
return execute(SimplePostRequestExecutor.create(this), url, postData);
|
return execute(SimplePostRequestExecutor.create(this), url, postData);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user