1
0
mirror of synced 2025-12-24 11:07:56 +08:00

🎨 添加 Apache HttpComponents Client 5.x 为可选的 http client

This commit is contained in:
altusea
2025-06-09 14:29:35 +08:00
committed by GitHub
parent bf35797b91
commit ccbfa98864
136 changed files with 2689 additions and 492 deletions

View File

@@ -31,6 +31,11 @@
<artifactId>okhttp</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>

View File

@@ -5,25 +5,21 @@ import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
public class ApacheApiSignaturePostRequestExecutor
extends ApiSignaturePostRequestExecutor<CloseableHttpClient, HttpHost> {
private static final Logger logger =
LoggerFactory.getLogger(ApacheApiSignaturePostRequestExecutor.class);
public class ApacheApiSignaturePostRequestExecutor extends ApiSignaturePostRequestExecutor<CloseableHttpClient, HttpHost> {
public ApacheApiSignaturePostRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp) {
super(requestHttp);
@@ -50,8 +46,7 @@ public class ApacheApiSignaturePostRequestExecutor
}
if (postEntity != null) {
StringEntity entity = new StringEntity(postEntity, Consts.UTF_8);
entity.setContentType("application/json; charset=utf-8");
StringEntity entity = new StringEntity(postEntity, ContentType.APPLICATION_JSON.withCharset(StandardCharsets.UTF_8));
httpPost.setEntity(entity);
}

View File

@@ -1,10 +1,6 @@
package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.WxMaApiResponse;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.Map;
import jodd.http.HttpConnectionProvider;
import jodd.http.ProxyInfo;
import me.chanjar.weixin.common.enums.WxType;
@@ -15,10 +11,12 @@ import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.ResponseHandler;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.OkHttpClient;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.Map;
public abstract class ApiSignaturePostRequestExecutor<H, P>
implements RequestExecutor<WxMaApiResponse, WxMaApiResponse> {
@@ -65,13 +63,17 @@ public abstract class ApiSignaturePostRequestExecutor<H, P>
public static ApiSignaturePostRequestExecutor<?, ?> create(RequestHttp<?, ?> requestHttp) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheApiSignaturePostRequestExecutor((RequestHttp<CloseableHttpClient, HttpHost>) requestHttp);
return new ApacheApiSignaturePostRequestExecutor(
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp);
case JODD_HTTP:
return new JoddApiSignaturePostRequestExecutor((RequestHttp<HttpConnectionProvider, ProxyInfo>) requestHttp);
case OK_HTTP:
return new OkHttpApiSignaturePostRequestExecutor((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp);
case HTTP_COMPONENTS:
return new HttpComponentsApiSignaturePostRequestExecutor(
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp);
default:
throw new IllegalArgumentException("非法请求参数");
throw new IllegalArgumentException("不支持的http执行器类型" + requestHttp.getRequestType());
}
}
}

View File

@@ -0,0 +1,63 @@
package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.WxMaApiResponse;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.hc.Utf8ResponseHandler;
import org.apache.hc.client5.http.ClientProtocolException;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.io.entity.StringEntity;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
public class HttpComponentsApiSignaturePostRequestExecutor extends ApiSignaturePostRequestExecutor<CloseableHttpClient, HttpHost> {
public HttpComponentsApiSignaturePostRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp) {
super(requestHttp);
}
@Override
public WxMaApiResponse execute(
String uri, Map<String, String> headers, String postEntity, WxType wxType)
throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
httpPost.setConfig(config);
}
if (headers != null) {
headers.forEach(httpPost::addHeader);
}
if (postEntity != null) {
StringEntity entity = new StringEntity(postEntity, ContentType.APPLICATION_JSON.withCharset(StandardCharsets.UTF_8));
httpPost.setEntity(entity);
}
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
Map<String, String> respHeaders = new HashMap<>();
Header[] rHeaders = response.getHeaders();
if (rHeaders != null) {
for (Header h : rHeaders) {
respHeaders.putIfAbsent(h.getName(), h.getValue());
}
}
return this.handleResponse(wxType, responseContent, respHeaders);
} catch (HttpException httpException) {
throw new ClientProtocolException(httpException.getMessage(), httpException);
}
}
}

View File

@@ -0,0 +1,70 @@
package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.AbstractWxMaQrcodeWrapper;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.hc.InputStreamResponseHandler;
import me.chanjar.weixin.common.util.http.hc.Utf8ResponseHandler;
import org.apache.commons.io.IOUtils;
import org.apache.hc.client5.http.ClientProtocolException;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.io.entity.StringEntity;
import java.io.IOException;
import java.io.InputStream;
/**
* @author altusea
*/
public class HttpComponentsQrcodeBytesRequestExecutor extends QrcodeBytesRequestExecutor<CloseableHttpClient, HttpHost> {
public HttpComponentsQrcodeBytesRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp) {
super(requestHttp);
}
/**
* 执行http请求.
*
* @param uri uri
* @param qrcodeWrapper 数据
* @param wxType 微信模块类型
* @return 响应结果
* @throws WxErrorException 自定义异常
* @throws IOException io异常
*/
@Override
public byte[] execute(String uri, AbstractWxMaQrcodeWrapper qrcodeWrapper, WxType wxType) throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
httpPost.setConfig(
RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build()
);
}
httpPost.setEntity(new StringEntity(qrcodeWrapper.toJson()));
try (final CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost);
final InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response)) {
Header[] contentTypeHeader = response.getHeaders("Content-Type");
if (contentTypeHeader != null && contentTypeHeader.length > 0
&& ContentType.APPLICATION_JSON.getMimeType()
.equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
throw new WxErrorException(WxError.fromJson(responseContent, wxType));
}
return IOUtils.toByteArray(inputStream);
} catch (HttpException httpException) {
throw new ClientProtocolException(httpException.getMessage(), httpException);
}
}
}

View File

@@ -0,0 +1,79 @@
package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.AbstractWxMaQrcodeWrapper;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.hc.InputStreamResponseHandler;
import me.chanjar.weixin.common.util.http.hc.Utf8ResponseHandler;
import org.apache.commons.lang3.StringUtils;
import org.apache.hc.client5.http.ClientProtocolException;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.io.entity.StringEntity;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.UUID;
/**
* @author altusea
*/
public class HttpComponentsQrcodeFileRequestExecutor extends QrcodeRequestExecutor<CloseableHttpClient, HttpHost> {
private final String filePath;
public HttpComponentsQrcodeFileRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp, String filePath) {
super(requestHttp);
this.filePath = filePath;
}
/**
* 执行http请求.
*
* @param uri uri
* @param qrcodeWrapper 数据
* @param wxType 微信模块类型
* @return 响应结果
* @throws WxErrorException 自定义异常
* @throws IOException io异常
*/
@Override
public File execute(String uri, AbstractWxMaQrcodeWrapper qrcodeWrapper, WxType wxType) throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
httpPost.setConfig(
RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build()
);
}
httpPost.setEntity(new StringEntity(qrcodeWrapper.toJson(), ContentType.APPLICATION_JSON));
try (final CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost);
final InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response)) {
Header[] contentTypeHeader = response.getHeaders("Content-Type");
if (contentTypeHeader != null && contentTypeHeader.length > 0
&& ContentType.APPLICATION_JSON.getMimeType()
.equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
throw new WxErrorException(WxError.fromJson(responseContent, wxType));
}
if (StringUtils.isBlank(filePath)) {
return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
}
return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg", Paths.get(filePath).toFile());
} catch (HttpException httpException) {
throw new ClientProtocolException(httpException.getMessage(), httpException);
}
}
}

View File

@@ -0,0 +1,51 @@
package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.WxMaUploadAuthMaterialResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.hc.Utf8ResponseHandler;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.entity.mime.HttpMultipartMode;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpHost;
import java.io.File;
import java.io.IOException;
/**
* @author altusea
*/
public class HttpComponentsUploadAuthMaterialRequestExecutor extends UploadAuthMaterialRequestExecutor<CloseableHttpClient, HttpHost> {
public HttpComponentsUploadAuthMaterialRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp) {
super(requestHttp);
}
@Override
public WxMaUploadAuthMaterialResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
httpPost.setConfig(config);
}
if (file != null) {
HttpEntity entity = MultipartEntityBuilder
.create()
.addBinaryBody("media", file)
.setMode(HttpMultipartMode.EXTENDED)
.build();
httpPost.setEntity(entity);
}
String responseContent = requestHttp.getRequestHttpClient().execute(httpPost, Utf8ResponseHandler.INSTANCE);
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaUploadAuthMaterialResult.fromJson(responseContent);
}
}

View File

@@ -0,0 +1,59 @@
package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.vod.WxMaVodSingleFileUploadResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.hc.Utf8ResponseHandler;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.entity.mime.HttpMultipartMode;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.core5.http.HttpHost;
import java.io.File;
import java.io.IOException;
public class HttpComponentsVodSingleUploadRequestExecutor extends VodSingleUploadRequestExecutor<CloseableHttpClient, HttpHost> {
public HttpComponentsVodSingleUploadRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp, String mediaName, String mediaType, String coverType, File coverData, String sourceContext) {
super(requestHttp, mediaName, mediaType, coverType, coverData, sourceContext);
}
@Override
public WxMaVodSingleFileUploadResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
httpPost.setConfig(config);
}
if (file != null) {
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder
.create()
.setMode(HttpMultipartMode.EXTENDED)
.addTextBody("media_name", mediaName)
.addTextBody("media_type", mediaType)
.addBinaryBody("media_data", file);
if (coverType != null) {
entityBuilder.addTextBody("cover_type", coverType);
}
if (coverData != null) {
entityBuilder.addBinaryBody("cover_data", coverData);
}
if (sourceContext != null) {
entityBuilder.addTextBody("source_context", sourceContext);
}
httpPost.setEntity(entityBuilder.build());
}
String responseContent = requestHttp.getRequestHttpClient().execute(httpPost, Utf8ResponseHandler.INSTANCE);
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaVodSingleFileUploadResult.fromJson(responseContent);
}
}

View File

@@ -0,0 +1,52 @@
package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.vod.WxMaVodUploadPartResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.hc.Utf8ResponseHandler;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.entity.mime.HttpMultipartMode;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.core5.http.HttpHost;
import java.io.File;
import java.io.IOException;
public class HttpComponentsVodUploadPartRequestExecutor extends VodUploadPartRequestExecutor<CloseableHttpClient, HttpHost> {
public HttpComponentsVodUploadPartRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp, String uploadId, Integer partNumber, Integer resourceType) {
super(requestHttp, uploadId, partNumber, resourceType);
}
@Override
public WxMaVodUploadPartResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
httpPost.setConfig(config);
}
if (file != null) {
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder
.create()
.setMode(HttpMultipartMode.EXTENDED)
.addTextBody("upload_id", uploadId)
.addTextBody("part_number", String.valueOf(partNumber))
.addTextBody("resource_type", String.valueOf(resourceType))
.addBinaryBody("data", file);
httpPost.setEntity(entityBuilder.build());
}
String responseContent = requestHttp.getRequestHttpClient().execute(httpPost, Utf8ResponseHandler.INSTANCE);
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaVodUploadPartResult.fromJson(responseContent);
}
}

View File

@@ -8,8 +8,6 @@ import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.ResponseHandler;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.OkHttpClient;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.IOException;
@@ -33,13 +31,15 @@ public abstract class QrcodeBytesRequestExecutor<H, P> implements RequestExecuto
public static RequestExecutor<byte[], AbstractWxMaQrcodeWrapper> create(RequestHttp<?, ?> requestHttp) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheQrcodeBytesRequestExecutor((RequestHttp<CloseableHttpClient, HttpHost>) requestHttp);
case JODD_HTTP:
return null;
return new ApacheQrcodeBytesRequestExecutor(
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp);
case OK_HTTP:
return new OkHttpQrcodeBytesRequestExecutor((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp);
case HTTP_COMPONENTS:
return new HttpComponentsQrcodeBytesRequestExecutor(
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp);
default:
return null;
throw new IllegalArgumentException("不支持的http执行器类型" + requestHttp.getRequestType());
}
}
}

View File

@@ -33,12 +33,15 @@ public abstract class QrcodeRequestExecutor<H, P> implements RequestExecutor<Fil
public static RequestExecutor<File, AbstractWxMaQrcodeWrapper> create(RequestHttp<?, ?> requestHttp, String path) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheQrcodeFileRequestExecutor((RequestHttp<CloseableHttpClient, HttpHost>) requestHttp, path);
return new ApacheQrcodeFileRequestExecutor(
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp, path);
case OK_HTTP:
return new OkHttpQrcodeFileRequestExecutor((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp, path);
case JODD_HTTP:
case HTTP_COMPONENTS:
return new HttpComponentsQrcodeFileRequestExecutor(
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp, path);
default:
return null;
throw new IllegalArgumentException("不支持的http执行器类型" + requestHttp.getRequestType());
}
}
@@ -47,12 +50,13 @@ public abstract class QrcodeRequestExecutor<H, P> implements RequestExecutor<Fil
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheQrcodeFileRequestExecutor((RequestHttp<CloseableHttpClient, HttpHost>) requestHttp, null);
case JODD_HTTP:
return null;
case OK_HTTP:
return new OkHttpQrcodeFileRequestExecutor((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp, null);
case HTTP_COMPONENTS:
return new HttpComponentsQrcodeFileRequestExecutor(
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp, null);
default:
return null;
throw new IllegalArgumentException("不支持的http执行器类型" + requestHttp.getRequestType());
}
}
}

View File

@@ -10,8 +10,6 @@ import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.ResponseHandler;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.OkHttpClient;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.File;
import java.io.IOException;
@@ -25,28 +23,32 @@ import java.io.IOException;
* @since 2024/01/07
*/
public abstract class UploadAuthMaterialRequestExecutor<H, P> implements RequestExecutor<WxMaUploadAuthMaterialResult, File> {
protected RequestHttp<H, P> requestHttp;
protected RequestHttp<H, P> requestHttp;
public UploadAuthMaterialRequestExecutor(RequestHttp<H, P> requestHttp) {
this.requestHttp = requestHttp;
}
public UploadAuthMaterialRequestExecutor(RequestHttp<H, P> requestHttp) {
this.requestHttp = requestHttp;
}
@Override
public void execute(String uri, File data, ResponseHandler<WxMaUploadAuthMaterialResult> handler, WxType wxType) throws WxErrorException, IOException {
handler.handle(this.execute(uri, data, wxType));
}
@Override
public void execute(String uri, File data, ResponseHandler<WxMaUploadAuthMaterialResult> handler, WxType wxType) throws WxErrorException, IOException {
handler.handle(this.execute(uri, data, wxType));
}
@SuppressWarnings("unchecked")
public static RequestExecutor<WxMaUploadAuthMaterialResult, File> create(RequestHttp<?, ?> requestHttp) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheUploadAuthMaterialRequestExecutor((RequestHttp<CloseableHttpClient, HttpHost>) requestHttp);
case JODD_HTTP:
return new JoddHttpUploadAuthMaterialRequestExecutor((RequestHttp<HttpConnectionProvider, ProxyInfo>) requestHttp);
case OK_HTTP:
return new OkHttpUploadAuthMaterialRequestExecutor((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp);
default:
return null;
}
@SuppressWarnings("unchecked")
public static RequestExecutor<WxMaUploadAuthMaterialResult, File> create(RequestHttp<?, ?> requestHttp) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheUploadAuthMaterialRequestExecutor(
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp);
case JODD_HTTP:
return new JoddHttpUploadAuthMaterialRequestExecutor((RequestHttp<HttpConnectionProvider, ProxyInfo>) requestHttp);
case OK_HTTP:
return new OkHttpUploadAuthMaterialRequestExecutor((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp);
case HTTP_COMPONENTS:
return new HttpComponentsUploadAuthMaterialRequestExecutor(
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp);
default:
throw new IllegalArgumentException("不支持的http执行器类型" + requestHttp.getRequestType());
}
}
}

View File

@@ -10,8 +10,6 @@ import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.ResponseHandler;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.OkHttpClient;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.File;
import java.io.IOException;
@@ -43,16 +41,24 @@ public abstract class VodSingleUploadRequestExecutor<H, P> implements RequestExe
}
@SuppressWarnings("unchecked")
public static RequestExecutor<WxMaVodSingleFileUploadResult, File> create(RequestHttp<?, ?> requestHttp, String mediaName, String mediaType, String coverType, File coverData, String sourceContext) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheVodSingleUploadRequestExecutor((RequestHttp<CloseableHttpClient, HttpHost>) requestHttp, mediaName, mediaType, coverType, coverData, sourceContext);
return new ApacheVodSingleUploadRequestExecutor(
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp,
mediaName, mediaType, coverType, coverData, sourceContext);
case JODD_HTTP:
return new JoddHttpVodSingleUploadRequestExecutor((RequestHttp<HttpConnectionProvider, ProxyInfo>) requestHttp, mediaName, mediaType, coverType, coverData, sourceContext);
case OK_HTTP:
return new OkHttpVodSingleUploadRequestExecutor((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp, mediaName, mediaType, coverType, coverData, sourceContext);
return new OkHttpVodSingleUploadRequestExecutor(
(RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp, mediaName, mediaType, coverType, coverData, sourceContext);
case HTTP_COMPONENTS:
return new HttpComponentsVodSingleUploadRequestExecutor(
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp,
mediaName, mediaType, coverType, coverData, sourceContext);
default:
return null;
throw new IllegalArgumentException("不支持的http执行器类型" + requestHttp.getRequestType());
}
}
@@ -61,5 +67,4 @@ public abstract class VodSingleUploadRequestExecutor<H, P> implements RequestExe
handler.handle(this.execute(uri, data, wxType));
}
}

View File

@@ -10,8 +10,6 @@ import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.ResponseHandler;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.OkHttpClient;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.File;
import java.io.IOException;
@@ -33,16 +31,23 @@ public abstract class VodUploadPartRequestExecutor<H, P> implements RequestExecu
}
@SuppressWarnings("unchecked")
public static RequestExecutor<WxMaVodUploadPartResult, File> create(RequestHttp<?, ?> requestHttp, String uploadId, Integer partNumber, Integer resourceType) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheVodUploadPartRequestExecutor((RequestHttp<CloseableHttpClient, HttpHost>) requestHttp, uploadId, partNumber, resourceType);
return new ApacheVodUploadPartRequestExecutor(
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp,
uploadId, partNumber, resourceType);
case JODD_HTTP:
return new JoddHttpVodUploadPartRequestExecutor((RequestHttp<HttpConnectionProvider, ProxyInfo>) requestHttp, uploadId, partNumber, resourceType);
case OK_HTTP:
return new OkHttpVodUploadPartRequestExecutor((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp, uploadId, partNumber, resourceType);
case HTTP_COMPONENTS:
return new HttpComponentsVodUploadPartRequestExecutor(
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp,
uploadId, partNumber, resourceType);
default:
return null;
throw new IllegalArgumentException("不支持的http执行器类型" + requestHttp.getRequestType());
}
}
@@ -51,5 +56,4 @@ public abstract class VodUploadPartRequestExecutor<H, P> implements RequestExecu
handler.handle(this.execute(uri, data, wxType));
}
}