mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-01-23 05:12:03 +08:00
🎨 #3834 【基础架构】小程序和开放平台两个模块补充了 Apache HttpClient 5.x 实现,同时并将多个模块的默认服务实现迁移至 Apache HttpClient 5.x 客户端
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package me.chanjar.weixin.open.api.impl;
|
||||
|
||||
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadResult;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.HttpClientType;
|
||||
import me.chanjar.weixin.common.util.http.MinishopUploadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.hc.DefaultHttpComponentsClientBuilder;
|
||||
import me.chanjar.weixin.common.util.http.hc.HttpComponentsClientBuilder;
|
||||
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* httpclient 5 实现
|
||||
*
|
||||
* @author <a href="https://github.com/buaazyl">zhangyl</a>
|
||||
*/
|
||||
public class WxOpenServiceHttpComponentsImpl extends WxOpenServiceAbstractImpl<CloseableHttpClient, HttpHost> {
|
||||
private CloseableHttpClient httpClient;
|
||||
private HttpHost httpProxy;
|
||||
|
||||
@Override
|
||||
public void initHttp() {
|
||||
WxOpenConfigStorage configStorage = this.getWxOpenConfigStorage();
|
||||
HttpComponentsClientBuilder apacheHttpClientBuilder = DefaultHttpComponentsClientBuilder.get();
|
||||
|
||||
apacheHttpClientBuilder.httpProxyHost(configStorage.getHttpProxyHost())
|
||||
.httpProxyPort(configStorage.getHttpProxyPort())
|
||||
.httpProxyUsername(configStorage.getHttpProxyUsername())
|
||||
.httpProxyPassword(configStorage.getHttpProxyPassword() == null ? null :
|
||||
configStorage.getHttpProxyPassword().toCharArray());
|
||||
|
||||
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
|
||||
this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort());
|
||||
}
|
||||
|
||||
this.httpClient = apacheHttpClientBuilder.build();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloseableHttpClient getRequestHttpClient() {
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHost getRequestHttpProxy() {
|
||||
return httpProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpClientType getRequestType() {
|
||||
return HttpClientType.HTTP_COMPONENTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String url, String queryParam) throws WxErrorException {
|
||||
return execute(SimpleGetRequestExecutor.create(this), url, queryParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String post(String url, String postData) throws WxErrorException {
|
||||
return execute(SimplePostRequestExecutor.create(this), url, postData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMinishopImageUploadResult uploadMinishopMediaFile(String url, File file) throws WxErrorException {
|
||||
return execute(MinishopUploadRequestExecutor.create(this), url, file);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,6 @@ package me.chanjar.weixin.open.api.impl;
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
public class WxOpenServiceImpl extends WxOpenServiceApacheHttpClientImpl {
|
||||
public class WxOpenServiceImpl extends WxOpenServiceHttpComponentsImpl {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user