mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 10:38:42 +08:00 
			
		
		
		
	#644 WxOpenConfigStorage增加setApacheHttpClientBuilder()方法,方便用户修改http请求相关参数
This commit is contained in:
		| @ -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); | ||||
|  | ||||
| @ -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(); | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -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(); | ||||
|     ApacheHttpClientBuilder apacheHttpClientBuilder = configStorage.getApacheHttpClientBuilder(); | ||||
|     if (null == apacheHttpClientBuilder) { | ||||
|       apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get(); | ||||
|     } | ||||
|  | ||||
|     apacheHttpClientBuilder.httpProxyHost(configStorage.getHttpProxyHost()) | ||||
|       .httpProxyPort(configStorage.getHttpProxyPort()) | ||||
|       .httpProxyUsername(configStorage.getHttpProxyUsername()) | ||||
|       .httpProxyPassword(configStorage.getHttpProxyPassword()); | ||||
|  | ||||
|     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(); | ||||
|  | ||||
|     this.httpClient = apacheHttpClientBuilder.build(); | ||||
|  | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 007gzs
					007gzs