@@ -1,6 +1,7 @@ | |||||
package me.chanjar.weixin.open.api; | package me.chanjar.weixin.open.api; | ||||
import cn.binarywang.wx.miniapp.config.WxMaConfig; | 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.mp.api.WxMpConfigStorage; | ||||
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; | ||||
@@ -46,6 +47,8 @@ public interface WxOpenConfigStorage { | |||||
String getHttpProxyPassword(); | String getHttpProxyPassword(); | ||||
ApacheHttpClientBuilder getApacheHttpClientBuilder(); | |||||
WxMpConfigStorage getWxMpConfigStorage(String appId); | WxMpConfigStorage getWxMpConfigStorage(String appId); | ||||
WxMaConfig getWxMaConfig(String appId); | WxMaConfig getWxMaConfig(String appId); | ||||
@@ -34,6 +34,7 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage { | |||||
private int httpProxyPort; | private int httpProxyPort; | ||||
private String httpProxyUsername; | private String httpProxyUsername; | ||||
private String httpProxyPassword; | private String httpProxyPassword; | ||||
private ApacheHttpClientBuilder apacheHttpClientBuilder; | |||||
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<>(); | ||||
@@ -146,6 +147,15 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage { | |||||
this.httpProxyPassword = httpProxyPassword; | this.httpProxyPassword = httpProxyPassword; | ||||
} | } | ||||
@Override | |||||
public ApacheHttpClientBuilder getApacheHttpClientBuilder() { | |||||
return apacheHttpClientBuilder; | |||||
} | |||||
public ApacheHttpClientBuilder setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) { | |||||
return this.apacheHttpClientBuilder = apacheHttpClientBuilder; | |||||
} | |||||
@Override | @Override | ||||
public WxMpConfigStorage getWxMpConfigStorage(String appId) { | public WxMpConfigStorage getWxMpConfigStorage(String appId) { | ||||
return new WxOpenInnerConfigStorage(this, appId); | return new WxOpenInnerConfigStorage(this, appId); | ||||
@@ -448,7 +458,7 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage { | |||||
@Override | @Override | ||||
public ApacheHttpClientBuilder getApacheHttpClientBuilder() { | public ApacheHttpClientBuilder getApacheHttpClientBuilder() { | ||||
return null; | |||||
return wxOpenConfigStorage.getApacheHttpClientBuilder(); | |||||
} | } | ||||
@@ -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.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.ApacheHttpClientBuilder; | |||||
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; | import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; | ||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage; | |||||
import me.chanjar.weixin.open.api.WxOpenConfigStorage; | 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; | ||||
@@ -21,14 +23,22 @@ public class WxOpenServiceApacheHttpClientImpl extends WxOpenServiceAbstractImpl | |||||
@Override | @Override | ||||
public void initHttp() { | public void initHttp() { | ||||
WxOpenConfigStorage configStorage = this.getWxOpenConfigStorage(); | 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()) | .httpProxyPort(configStorage.getHttpProxyPort()) | ||||
.httpProxyUsername(configStorage.getHttpProxyUsername()) | .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 | @Override | ||||