Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import me.chanjar.weixin.open.api.WxOpenService;
import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage;
import me.chanjar.weixin.open.api.impl.WxOpenServiceImpl;
import me.chanjar.weixin.open.api.impl.WxOpenServiceApacheHttpClientImpl;
import me.chanjar.weixin.open.api.impl.WxOpenServiceHttpComponentsImpl;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
Expand Down Expand Up @@ -73,7 +74,13 @@ protected WxOpenMultiServices wxOpenMultiServices(WxOpenMultiProperties wxOpenMu
protected abstract WxOpenInMemoryConfigStorage wxOpenConfigStorage(WxOpenMultiProperties wxOpenMultiProperties);

public WxOpenService wxOpenService(WxOpenConfigStorage configStorage, WxOpenMultiProperties wxOpenMultiProperties) {
WxOpenService wxOpenService = new WxOpenServiceImpl();
WxOpenMultiProperties.HttpClientType httpClientType = wxOpenMultiProperties.getConfigStorage().getHttpClientType();
WxOpenService wxOpenService;
if (httpClientType == WxOpenMultiProperties.HttpClientType.APACHE_HTTP) {
wxOpenService = new WxOpenServiceApacheHttpClientImpl();
Comment on lines 76 to +80
} else {
wxOpenService = new WxOpenServiceHttpComponentsImpl();

@augmentcode augmentcode Bot Jul 1, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractWxOpenConfiguration.java:82 这里默认从返回 WxOpenServiceImpl 改为 WxOpenServiceHttpComponentsImpl,可能影响依赖具体实现类型(强转/instanceof/按类注入)的用户代码。即使当前 WxOpenServiceImpl 只是别名类,这种实现类型变化仍有兼容性风险。

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

}
wxOpenService.setWxOpenConfigStorage(configStorage);
return wxOpenService;
}
Expand Down Expand Up @@ -137,17 +144,19 @@ private void configHttp(WxOpenInMemoryConfigStorage config, WxOpenMultiPropertie
config.setRetrySleepMillis(retrySleepMillis);
config.setMaxRetryTimes(maxRetryTimes);

// 设置自定义的HttpClient超时配置
ApacheHttpClientBuilder clientBuilder = config.getApacheHttpClientBuilder();
if (clientBuilder == null) {
clientBuilder = DefaultApacheHttpClientBuilder.get();
}
if (clientBuilder instanceof DefaultApacheHttpClientBuilder) {
DefaultApacheHttpClientBuilder defaultBuilder = (DefaultApacheHttpClientBuilder) clientBuilder;
defaultBuilder.setConnectionTimeout(storage.getConnectionTimeout());
defaultBuilder.setSoTimeout(storage.getSoTimeout());
defaultBuilder.setConnectionRequestTimeout(storage.getConnectionRequestTimeout());
config.setApacheHttpClientBuilder(defaultBuilder);
// 仅在使用 Apache HttpClient 4.x 时配置 ApacheHttpClientBuilder 超时参数
if (storage.getHttpClientType() == WxOpenMultiProperties.HttpClientType.APACHE_HTTP) {
ApacheHttpClientBuilder clientBuilder = config.getApacheHttpClientBuilder();
if (clientBuilder == null) {
clientBuilder = DefaultApacheHttpClientBuilder.get();
}
if (clientBuilder instanceof DefaultApacheHttpClientBuilder) {
DefaultApacheHttpClientBuilder defaultBuilder = (DefaultApacheHttpClientBuilder) clientBuilder;
defaultBuilder.setConnectionTimeout(storage.getConnectionTimeout());
defaultBuilder.setSoTimeout(storage.getSoTimeout());
defaultBuilder.setConnectionRequestTimeout(storage.getConnectionRequestTimeout());
config.setApacheHttpClientBuilder(defaultBuilder);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public static class ConfigStorage implements Serializable {
*/
private StorageType type = StorageType.memory;

/**
* http客户端类型.
*/
private HttpClientType httpClientType = HttpClientType.HTTP_COMPONENTS;

/**
* 指定key前缀.
*/
Expand Down Expand Up @@ -122,4 +127,15 @@ public enum StorageType {
redistemplate
}

public enum HttpClientType {
/**
* Apache HttpClient 4.x
*/
APACHE_HTTP,
/**
* Apache HttpClient 5.x (HttpComponents)
*/
HTTP_COMPONENTS
}

}