Browse Source

#567 微信开放平台增加 HTTP proxy 机制

* 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀;

* 微信开放平台:增加小程序代码模板库管理

* 小程序:增加代码管理相关 API

* 小程序:增加修改服务器地址、成员管理 API

* 小程序:增加数据分析相关 API

* 微信开放平台:增加 HTTP proxy 机制
master
Charming 7 years ago
committed by Binary Wang
parent
commit
04ec788d07
4 changed files with 75 additions and 8 deletions
  1. +8
    -1
      weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java
  2. +45
    -4
      weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java
  3. +6
    -0
      weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceAbstractImpl.java
  4. +16
    -3
      weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceApacheHttpClientImpl.java

+ 8
- 1
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java View File

@@ -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);

}

+ 45
- 4
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java View File

@@ -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


+ 6
- 0
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceAbstractImpl.java View File

@@ -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);


+ 16
- 3
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceApacheHttpClientImpl.java View File

@@ -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…
Cancel
Save