Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1bf4dfa
fix unit test
altusea Jun 3, 2025
0d18b6d
rename WxCpServiceApacheHttpClient5Impl to WxCpServiceHttpClient5Impl
altusea Jun 3, 2025
56bf115
新增 WxChannelServiceHttpClient5Impl 类
altusea Jun 3, 2025
ea9e1ba
新增 WxMpServiceHttpClient5Impl 类
altusea Jun 3, 2025
878cffb
新增 WxCpCgServiceHttpClient5Impl 类
altusea Jun 3, 2025
52c6461
新增 CommonUploadMultiRequestExecutorHttpClient5Impl 类
altusea Jun 3, 2025
76c7076
将 okhttp 依赖版本从 4.5.0 升级到 4.12.0
altusea Jun 3, 2025
8e63b26
新增 WxCpTpServiceHttpClient5Impl 类
altusea Jun 3, 2025
d6d2473
新增 QrCodeHttpClient5RequestExecutor 类
altusea Jun 3, 2025
2dac570
新增 WxQidianServiceHttpClient5Impl 类
altusea Jun 3, 2025
ecd2f55
新增 WxPayServiceHttpClient5Impl 类
altusea Jun 3, 2025
2b5a2b1
修正 serialVersionUID 类型并优化部分代码结构
altusea Jun 3, 2025
516ccc2
升级 Bouncy Castle 依赖版本至 1.80
altusea Jun 3, 2025
9e3cf45
升级 Jackson 依赖版本到 2.18.4
altusea Jun 3, 2025
1acdb16
使用 JsonParser 的静态方法替代实例方法
altusea Jun 4, 2025
99b0e1a
新增 HttpClient5QrcodeBytesRequestExecutor 类
altusea Jun 4, 2025
88b8706
新增 HttpClient5UploadAuthMaterialRequestExecutor 类
altusea Jun 4, 2025
0b4523c
新增 HttpClient5QrcodeFileRequestExecutor 类
altusea Jun 4, 2025
44d8dc0
新增 HttpClient5ApiSignaturePostRequestExecutor 类
altusea Jun 4, 2025
1bab58b
Merge remote-tracking branch 'origin/develop' into more_httpclient5
altusea Jun 6, 2025
96a60a4
Merge remote-tracking branch 'origin/develop' into more_httpclient5
altusea Jun 6, 2025
216bf5a
fix unit test
altusea Jun 6, 2025
3b354cf
新增 MaterialVideoInfoHttpClient5RequestExecutor 类
altusea Jun 6, 2025
f9c45bb
新增 MaterialUploadHttpClient5RequestExecutor 类
altusea Jun 6, 2025
1e6d2a3
新增 MaterialDeleteHttpClient5RequestExecutor 类
altusea Jun 6, 2025
6460cee
新增 MaterialNewsInfoHttpClient5RequestExecutor 类
altusea Jun 6, 2025
ca16c39
新增 MaterialVoiceAndImageDownloadHttpClient5RequestExecutor 类
altusea Jun 6, 2025
83200d7
新增 MediaImgUploadHttpClient5RequestExecutor 类
altusea Jun 6, 2025
e505c48
新增 VoiceUploadHttpClient5RequestExecutor 类
altusea Jun 6, 2025
fb2906f
新增 CommonUploadRequestExecutorHttpClient5Impl 和 MaQrCodeHttpClient5Re…
altusea Jun 7, 2025
7eda22e
重命名
altusea Jun 7, 2025
1753f1f
add
altusea Jun 7, 2025
c74ce60
polish
altusea Jun 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.5.0</version>
<version>4.12.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -212,7 +212,7 @@
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.18.1</version>
<version>2.18.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -333,7 +333,7 @@
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>1.78.1</version>
<version>1.80</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.channel.api.WxChannelService;
import me.chanjar.weixin.channel.api.impl.WxChannelServiceHttpComponentsImpl;
import me.chanjar.weixin.channel.api.impl.WxChannelServiceHttpClientImpl;
import me.chanjar.weixin.channel.api.impl.WxChannelServiceImpl;
import me.chanjar.weixin.channel.config.WxChannelConfig;
Expand Down Expand Up @@ -84,6 +85,9 @@ public WxChannelService wxChannelService(WxChannelConfig wxChannelConfig, WxChan
case HTTP_CLIENT:
wxChannelService = new WxChannelServiceHttpClientImpl();
break;
case HTTP_COMPONENTS:
wxChannelService = new WxChannelServiceHttpComponentsImpl();
break;
default:
wxChannelService = new WxChannelServiceImpl();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public enum HttpClientType {
* HttpClient
*/
HTTP_CLIENT,
/**
* HttpComponents
*/
HTTP_COMPONENTS
// WxChannelServiceOkHttpImpl 实现经测试无法正常完成业务固暂不支持OK_HTTP方式
// /**
// * OkHttp.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceApacheHttpClientImpl;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.api.impl.WxCpServiceJoddHttpImpl;
import me.chanjar.weixin.cp.api.impl.WxCpServiceOkHttpImpl;
import me.chanjar.weixin.cp.api.impl.*;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -96,6 +93,9 @@ private WxCpService wxCpService(WxCpConfigStorage wxCpConfigStorage, WxCpMultiPr
case HTTP_CLIENT:
wxCpService = new WxCpServiceApacheHttpClientImpl();
break;
case HTTP_COMPONENTS:
wxCpService = new WxCpServiceHttpComponentsImpl();
break;
default:
wxCpService = new WxCpServiceImpl();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public enum HttpClientType {
* HttpClient
*/
HTTP_CLIENT,
/**
* HttpComponents
*/
HTTP_COMPONENTS,
/**
* OkHttp
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.api.impl.WxMpServiceJoddHttpImpl;
import me.chanjar.weixin.mp.api.impl.WxMpServiceOkHttpImpl;
import me.chanjar.weixin.mp.api.impl.*;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.WxMpHostConfig;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
Expand Down Expand Up @@ -91,6 +88,9 @@ public WxMpService wxMpService(WxMpConfigStorage configStorage, WxMpMultiPropert
case HTTP_CLIENT:
wxMpService = new WxMpServiceHttpClientImpl();
break;
case HTTP_COMPONENTS:
wxMpService = new WxMpServiceHttpComponentsImpl();
break;
default:
wxMpService = new WxMpServiceImpl();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ public enum HttpClientType {
* HttpClient
*/
HTTP_CLIENT,
/**
* HttpComponents
*/
HTTP_COMPONENTS,
/**
* OkHttp
*/
Expand Down
7 changes: 6 additions & 1 deletion weixin-java-channel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<description>微信视频号/微信小店 Java SDK</description>

<properties>
<jackson.version>2.18.1</jackson.version>
<jackson.version>2.18.4</jackson.version>
</properties>

<dependencies>
Expand All @@ -29,6 +29,11 @@
<artifactId>jodd-http</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,27 @@ public ChannelImageInfo uploadImg(int respType, String imgUrl) throws WxErrorExc
public ChannelImageInfo uploadImg(int respType, File file, int height, int width) throws WxErrorException {
String url = IMG_UPLOAD_URL + "?upload_type=0&resp_type=" + respType + "&height=" + height + "&width=" + width;
RequestExecutor<String, File> executor = ChannelFileUploadRequestExecutor.create(shopService);
String resJson = (String) shopService.execute(executor, url, file);
String resJson = shopService.execute(executor, url, file);
UploadImageResponse response = ResponseUtils.decode(resJson, UploadImageResponse.class);
return response.getImgInfo();
}

@Override
public QualificationFileResponse uploadQualificationFile(File file) throws WxErrorException {
RequestExecutor<String, File> executor = ChannelFileUploadRequestExecutor.create(shopService);
String resJson = (String) shopService.execute(executor, UPLOAD_QUALIFICATION_FILE, file);
String resJson = shopService.execute(executor, UPLOAD_QUALIFICATION_FILE, file);
return ResponseUtils.decode(resJson, QualificationFileResponse.class);
}

@Override
public ChannelImageResponse getImg(String mediaId) throws WxErrorException {
String appId = shopService.getConfig().getAppid();
ChannelImageResponse rs = null;
ChannelImageResponse rs;
try {
String url = GET_IMG_URL + "?media_id=" + mediaId;
RequestExecutor<ChannelImageResponse, String> executor = ChannelMediaDownloadRequestExecutor.create(shopService,
Files.createTempDirectory("wxjava-channel-" + appId).toFile());
rs = (ChannelImageResponse) shopService.execute(executor, url, null);
rs = shopService.execute(executor, url, null);
} catch (IOException e) {
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package me.chanjar.weixin.channel.api.impl;

import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.channel.bean.token.StableTokenParam;
import me.chanjar.weixin.channel.config.WxChannelConfig;
import me.chanjar.weixin.channel.util.JsonUtils;
import me.chanjar.weixin.common.util.http.HttpClientType;
import me.chanjar.weixin.common.util.http.apache.ApacheBasicResponseHandler;
import me.chanjar.weixin.common.util.http.hc.BasicResponseHandler;
import me.chanjar.weixin.common.util.http.hc.DefaultHttpComponentsClientBuilder;
import me.chanjar.weixin.common.util.http.hc.HttpComponentsClientBuilder;
import org.apache.commons.lang3.StringUtils;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.classic.methods.HttpGet;
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.core5.http.ContentType;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.io.entity.StringEntity;

import java.io.IOException;

import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.GET_ACCESS_TOKEN_URL;
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.GET_STABLE_ACCESS_TOKEN_URL;

/**
* @author altusea
*/
@Slf4j
public class WxChannelServiceHttpComponentsImpl extends BaseWxChannelServiceImpl<HttpClient, HttpHost> {

private CloseableHttpClient httpClient;
private HttpHost httpProxy;

@Override
public void initHttp() {
WxChannelConfig config = this.getConfig();
HttpComponentsClientBuilder apacheHttpClientBuilder = DefaultHttpComponentsClientBuilder.get();

apacheHttpClientBuilder.httpProxyHost(config.getHttpProxyHost())
.httpProxyPort(config.getHttpProxyPort())
.httpProxyUsername(config.getHttpProxyUsername())
.httpProxyPassword(config.getHttpProxyPassword().toCharArray());

if (config.getHttpProxyHost() != null && config.getHttpProxyPort() > 0) {
this.httpProxy = new HttpHost(config.getHttpProxyHost(), config.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
protected String doGetAccessTokenRequest() throws IOException {
WxChannelConfig config = this.getConfig();
String url = StringUtils.isNotEmpty(config.getAccessTokenUrl()) ? config.getAccessTokenUrl() :
StringUtils.isNotEmpty(config.getApiHostUrl()) ?
GET_ACCESS_TOKEN_URL.replace("https://api.weixin.qq.com", config.getApiHostUrl()) : GET_ACCESS_TOKEN_URL;

url = String.format(url, config.getAppid(), config.getSecret());

HttpGet httpGet = new HttpGet(url);
if (this.getRequestHttpProxy() != null) {
RequestConfig requestConfig = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build();
httpGet.setConfig(requestConfig);
}
return getRequestHttpClient().execute(httpGet, BasicResponseHandler.INSTANCE);
}

/**
* 获取稳定版接口调用凭据
*
* @param forceRefresh false 为普通模式, true为强制刷新模式
* @return 返回json的字符串
* @throws IOException the io exception
*/
@Override
protected String doGetStableAccessTokenRequest(boolean forceRefresh) throws IOException {
WxChannelConfig config = this.getConfig();
String url = GET_STABLE_ACCESS_TOKEN_URL;

HttpPost httpPost = new HttpPost(url);
if (this.getRequestHttpProxy() != null) {
RequestConfig requestConfig = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build();
httpPost.setConfig(requestConfig);
}
StableTokenParam requestParam = new StableTokenParam();
requestParam.setAppId(config.getAppid());
requestParam.setSecret(config.getSecret());
requestParam.setGrantType("client_credential");
requestParam.setForceRefresh(forceRefresh);
String requestJson = JsonUtils.encode(requestParam);
assert requestJson != null;

httpPost.setEntity(new StringEntity(requestJson, ContentType.APPLICATION_JSON));
return getRequestHttpClient().execute(httpPost, BasicResponseHandler.INSTANCE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package me.chanjar.weixin.channel.executor;

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.ResponseHandler;
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;

import java.io.File;
import java.io.IOException;

public class ApacheHttpChannelFileUploadRequestExecutor extends ChannelFileUploadRequestExecutor<CloseableHttpClient, HttpHost> {
public ApacheHttpChannelFileUploadRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp) {
super(requestHttp);
}

@Override
public String 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.RFC6532)
.build();
httpPost.setEntity(entity);
}
return requestHttp.getRequestHttpClient().execute(httpPost, Utf8ResponseHandler.INSTANCE);
}

@Override
public void execute(String uri, File data, ResponseHandler<String> handler, WxType wxType)
throws WxErrorException, IOException {
handler.handle(this.execute(uri, data, wxType));
}
}
Loading