Skip to content

Commit 2c5a339

Browse files
authored
🎨 #3834 【基础架构】小程序和开放平台两个模块补充了 Apache HttpClient 5.x 实现,同时并将多个模块的默认服务实现迁移至 Apache HttpClient 5.x 客户端
1 parent e572ddf commit 2c5a339

File tree

21 files changed

+233
-22
lines changed

21 files changed

+233
-22
lines changed

docs/HTTPCLIENT_UPGRADE_GUIDE.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@
2828
| weixin-java-cp(企业微信) | ⚠️ 视集成方式而定 | 参考对应 starter 配置 |
2929
| weixin-java-channel(视频号) | ✅ 是 | HttpComponents (5.x) |
3030
| weixin-java-qidian(企点) | ✅ 是 | HttpComponents (5.x) |
31-
| weixin-java-miniapp(小程序) | ✅ 是 | HttpClient (4.x) |
31+
| weixin-java-miniapp(小程序) | ✅ 是 | HttpComponents (5.x) |
3232
| weixin-java-pay(支付) | ✅ 是 | HttpComponents (5.x) |
3333
| weixin-java-open(开放平台) | ✅ 是 | HttpComponents (5.x) |
3434

3535
**注意**
36-
- **weixin-java-miniapp 模块**已在核心 SDK 中提供 HttpClient 5.x(`HttpComponents`)支持,但默认仍使用 HttpClient 4.x(`HttpClient`)。如需启用 HttpClient 5.x,可通过配置 `http-client-type=HttpComponents` 显式指定。
3736
- **weixin-java-cp 模块**的支持情况取决于具体使用的 Starter 版本,请参考对应模块文档。
3837

3938
## 对现有项目的影响
@@ -97,9 +96,6 @@ A: 不会。项目保持完全向后兼容,HttpClient 4.x 的所有实现都
9796
### Q: 我需要修改代码吗?
9897
A: 大多数情况下不需要。如果希望继续使用 HttpClient 4.x,只需在配置中指定 `http-client-type=HttpClient` 即可。
9998

100-
### Q: MiniApp 模块支持 HttpClient 5.x 吗?
101-
A: 支持。MiniApp 模块在核心 SDK 中已经提供了基于 HttpClient 5.x(`HttpComponents`)的支持,但默认仍会使用 HttpClient 4.x(`HttpClient`)以保持向后兼容。如果你使用的是框架集成(例如 Spring Boot Starter 或 Solon Plugin),可以通过显式配置 `http-client-type=HttpComponents` 来启用 HttpClient 5.x。
102-
10399
### Q: 我可以在同一个项目中同时使用两个版本吗?
104100
A: 可以。不同的模块可以配置使用不同的 HTTP 客户端。例如,MP 模块使用 HttpClient 5.x,MiniApp 模块默认使用 HttpClient 4.x,但也可以按需配置为 HttpClient 5.x。
105101

solon-plugins/wx-java-channel-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/channel/properties/WxChannelMultiProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static class ConfigStorage implements Serializable {
5555
/**
5656
* http客户端类型.
5757
*/
58-
private HttpClientType httpClientType = HttpClientType.HTTP_CLIENT;
58+
private HttpClientType httpClientType = HttpClientType.HTTP_COMPONENTS;
5959

6060
/**
6161
* http代理主机.

solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/properties/WxCpMultiProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static class ConfigStorage implements Serializable {
5252
/**
5353
* http客户端类型.
5454
*/
55-
private HttpClientType httpClientType = HttpClientType.HTTP_CLIENT;
55+
private HttpClientType httpClientType = HttpClientType.HTTP_COMPONENTS;
5656

5757
/**
5858
* http代理主机

solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/configuration/services/AbstractWxMaConfiguration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cn.binarywang.wx.miniapp.api.WxMaService;
44
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceHttpClientImpl;
5+
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceHttpComponentsImpl;
56
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
67
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceJoddHttpImpl;
78
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceOkHttpImpl;
@@ -89,6 +90,9 @@ public WxMaService wxMaService(WxMaConfig wxMaConfig, WxMaMultiProperties wxMaMu
8990
case HTTP_CLIENT:
9091
wxMaService = new WxMaServiceHttpClientImpl();
9192
break;
93+
case HTTP_COMPONENTS:
94+
wxMaService = new WxMaServiceHttpComponentsImpl();
95+
break;
9296
default:
9397
wxMaService = new WxMaServiceImpl();
9498
break;

solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/properties/WxMaMultiProperties.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static class ConfigStorage implements Serializable {
7777
/**
7878
* http客户端类型.
7979
*/
80-
private HttpClientType httpClientType = HttpClientType.HTTP_CLIENT;
80+
private HttpClientType httpClientType = HttpClientType.HTTP_COMPONENTS;
8181

8282
/**
8383
* http代理主机.
@@ -149,6 +149,10 @@ public enum HttpClientType {
149149
/**
150150
* JoddHttp
151151
*/
152-
JODD_HTTP
152+
JODD_HTTP,
153+
/**
154+
* HttpComponents
155+
*/
156+
HTTP_COMPONENTS
153157
}
154158
}

solon-plugins/wx-java-miniapp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/config/WxMaServiceAutoConfiguration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cn.binarywang.wx.miniapp.api.WxMaService;
44
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceHttpClientImpl;
5+
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceHttpComponentsImpl;
56
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
67
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceJoddHttpImpl;
78
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceOkHttpImpl;
@@ -44,6 +45,9 @@ public WxMaService wxMaService(WxMaConfig wxMaConfig) {
4445
case HttpClient:
4546
wxMaService = new WxMaServiceHttpClientImpl();
4647
break;
48+
case HttpComponents:
49+
wxMaService = new WxMaServiceHttpComponentsImpl();
50+
break;
4751
default:
4852
wxMaService = new WxMaServiceImpl();
4953
break;

solon-plugins/wx-java-miniapp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/properties/WxMaProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static class ConfigStorage {
7676
/**
7777
* http客户端类型.
7878
*/
79-
private HttpClientType httpClientType = HttpClientType.HttpClient;
79+
private HttpClientType httpClientType = HttpClientType.HttpComponents;
8080

8181
/**
8282
* http代理主机.

solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/configuration/services/AbstractWxMpConfiguration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import lombok.extern.slf4j.Slf4j;
99
import me.chanjar.weixin.mp.api.WxMpService;
1010
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
11+
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpComponentsImpl;
1112
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
1213
import me.chanjar.weixin.mp.api.impl.WxMpServiceJoddHttpImpl;
1314
import me.chanjar.weixin.mp.api.impl.WxMpServiceOkHttpImpl;
@@ -91,6 +92,9 @@ public WxMpService wxMpService(WxMpConfigStorage configStorage, WxMpMultiPropert
9192
case HTTP_CLIENT:
9293
wxMpService = new WxMpServiceHttpClientImpl();
9394
break;
95+
case HTTP_COMPONENTS:
96+
wxMpService = new WxMpServiceHttpComponentsImpl();
97+
break;
9498
default:
9599
wxMpService = new WxMpServiceImpl();
96100
break;

solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/properties/WxMpMultiProperties.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static class ConfigStorage implements Serializable {
7777
/**
7878
* http客户端类型.
7979
*/
80-
private HttpClientType httpClientType = HttpClientType.HTTP_CLIENT;
80+
private HttpClientType httpClientType = HttpClientType.HTTP_COMPONENTS;
8181

8282
/**
8383
* http代理主机.
@@ -149,6 +149,10 @@ public enum HttpClientType {
149149
/**
150150
* JoddHttp
151151
*/
152-
JODD_HTTP
152+
JODD_HTTP,
153+
/**
154+
* HttpComponents
155+
*/
156+
HTTP_COMPONENTS
153157
}
154158
}

solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/config/WxMpServiceAutoConfiguration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.binarywang.solon.wxjava.mp.properties.WxMpProperties;
55
import me.chanjar.weixin.mp.api.WxMpService;
66
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
7+
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpComponentsImpl;
78
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
89
import me.chanjar.weixin.mp.api.impl.WxMpServiceJoddHttpImpl;
910
import me.chanjar.weixin.mp.api.impl.WxMpServiceOkHttpImpl;
@@ -35,6 +36,9 @@ public WxMpService wxMpService(WxMpConfigStorage configStorage, WxMpProperties w
3536
case HttpClient:
3637
wxMpService = newWxMpServiceHttpClientImpl();
3738
break;
39+
case HttpComponents:
40+
wxMpService = newWxMpServiceHttpComponentsImpl();
41+
break;
3842
default:
3943
wxMpService = newWxMpServiceImpl();
4044
break;
@@ -60,4 +64,8 @@ private WxMpService newWxMpServiceJoddHttpImpl() {
6064
return new WxMpServiceJoddHttpImpl();
6165
}
6266

67+
private WxMpService newWxMpServiceHttpComponentsImpl() {
68+
return new WxMpServiceHttpComponentsImpl();
69+
}
70+
6371
}

0 commit comments

Comments
 (0)