瀏覽代碼

#644 WxOpenConfigStorage增加setApacheHttpClientBuilder()方法,方便用户修改http请求相关参数

master
007gzs 6 年之前
committed by Binary Wang
父節點
當前提交
82e2371847
共有 3 個文件被更改,包括 29 次插入6 次删除
  1. +3
    -0
      weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java
  2. +11
    -1
      weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java
  3. +15
    -5
      weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceApacheHttpClientImpl.java

+ 3
- 0
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java 查看文件

@@ -1,6 +1,7 @@
package me.chanjar.weixin.open.api;

import cn.binarywang.wx.miniapp.config.WxMaConfig;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken;
import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken;
@@ -46,6 +47,8 @@ public interface WxOpenConfigStorage {

String getHttpProxyPassword();

ApacheHttpClientBuilder getApacheHttpClientBuilder();

WxMpConfigStorage getWxMpConfigStorage(String appId);

WxMaConfig getWxMaConfig(String appId);


+ 11
- 1
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java 查看文件

@@ -34,6 +34,7 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
private int httpProxyPort;
private String httpProxyUsername;
private String httpProxyPassword;
private ApacheHttpClientBuilder apacheHttpClientBuilder;

private Map<String, Token> authorizerRefreshTokens = new Hashtable<>();
private Map<String, Token> authorizerAccessTokens = new Hashtable<>();
@@ -146,6 +147,15 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
this.httpProxyPassword = httpProxyPassword;
}

@Override
public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return apacheHttpClientBuilder;
}

public ApacheHttpClientBuilder setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
return this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}

@Override
public WxMpConfigStorage getWxMpConfigStorage(String appId) {
return new WxOpenInnerConfigStorage(this, appId);
@@ -448,7 +458,7 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {

@Override
public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return null;
return wxOpenConfigStorage.getApacheHttpClientBuilder();
}




+ 15
- 5
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceApacheHttpClientImpl.java 查看文件

@@ -4,7 +4,9 @@ import me.chanjar.weixin.common.error.WxErrorException;
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.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -21,14 +23,22 @@ public class WxOpenServiceApacheHttpClientImpl extends WxOpenServiceAbstractImpl
@Override
public void initHttp() {
WxOpenConfigStorage configStorage = this.getWxOpenConfigStorage();
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort());
ApacheHttpClientBuilder apacheHttpClientBuilder = configStorage.getApacheHttpClientBuilder();
if (null == apacheHttpClientBuilder) {
apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
}
this.httpClient = DefaultApacheHttpClientBuilder.get()
.httpProxyHost(configStorage.getHttpProxyHost())
apacheHttpClientBuilder.httpProxyHost(configStorage.getHttpProxyHost())
.httpProxyPort(configStorage.getHttpProxyPort())
.httpProxyUsername(configStorage.getHttpProxyUsername())
.httpProxyPassword(configStorage.getHttpProxyPassword()).build();
.httpProxyPassword(configStorage.getHttpProxyPassword());

if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort());
}

this.httpClient = apacheHttpClientBuilder.build();

}

@Override


Loading…
取消
儲存