mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
Compare commits
60 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfe1f6dc95 | ||
|
|
c0edd9fd16 | ||
|
|
1788d9071e | ||
|
|
e6a844ab70 | ||
|
|
6fc17201e1 | ||
|
|
ad19f653c7 | ||
|
|
7018dceb1c | ||
|
|
399f3648c0 | ||
|
|
88bdd4a36e | ||
|
|
213cf6fd67 | ||
|
|
c8d84da2ab | ||
|
|
118839a49d | ||
|
|
8447caa75f | ||
|
|
1eefd11e03 | ||
|
|
781798345e | ||
|
|
0424d75882 | ||
|
|
e61ad44d27 | ||
|
|
dc46d9de75 | ||
|
|
bc6fb7b58e | ||
|
|
983e4f1e66 | ||
|
|
7ffc1b3719 | ||
|
|
8bb4a21598 | ||
|
|
a881de59a5 | ||
|
|
14f8c8ebc2 | ||
|
|
875c35e745 | ||
|
|
262a02b606 | ||
|
|
3a1d8075fc | ||
|
|
2e952c76c8 | ||
|
|
e5ef34553d | ||
|
|
4cdd056a3e | ||
|
|
57a6ef1179 | ||
|
|
4754a562ca | ||
|
|
62f89987c0 | ||
|
|
990dbba06b | ||
|
|
d85e04a72a | ||
|
|
aacfa947be | ||
|
|
3e4ee57e1c | ||
|
|
d4cf48d059 | ||
|
|
696ce8621e | ||
|
|
8c8139533d | ||
|
|
84c69d4900 | ||
|
|
d52e225626 | ||
|
|
686dff6436 | ||
|
|
92431aabd9 | ||
|
|
29bc950f92 | ||
|
|
5c74c1d930 | ||
|
|
52d0b2fc1c | ||
|
|
5b816242a4 | ||
|
|
a45f0ac048 | ||
|
|
4731479b93 | ||
|
|
cc344f105e | ||
|
|
172b96444f | ||
|
|
b3b8c273c7 | ||
|
|
b6d489e9c8 | ||
|
|
72266c3aeb | ||
|
|
ccbfa98864 | ||
|
|
bf35797b91 | ||
|
|
41081561b5 | ||
|
|
8878f06c1e | ||
|
|
22d288f6cd |
198
.github/copilot-instructions.md
vendored
Normal file
198
.github/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
# WxJava - WeChat Java SDK Development Instructions
|
||||
|
||||
WxJava is a comprehensive WeChat Java SDK supporting multiple WeChat platforms including Official Accounts (公众号), Mini Programs (小程序), WeChat Pay (微信支付), Enterprise WeChat (企业微信), Open Platform (开放平台), and Channel/Video (视频号). This is a Maven multi-module project with Spring Boot and Solon framework integrations.
|
||||
|
||||
**ALWAYS reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the information here.**
|
||||
|
||||
## Working Effectively
|
||||
|
||||
### Prerequisites and Environment Setup
|
||||
- **Java Requirements**: JDK 8+ required (project uses Java 8 as minimum target)
|
||||
- **Maven**: Maven 3.6+ recommended (Maven 3.9.11 validated)
|
||||
- **IDE**: IntelliJ IDEA recommended (project optimized for IDEA)
|
||||
|
||||
### Bootstrap, Build, and Validate
|
||||
Execute these commands in sequence after cloning:
|
||||
|
||||
```bash
|
||||
# 1. Basic compilation (NEVER CANCEL - takes 4-5 minutes)
|
||||
mvn clean compile -DskipTests=true --no-transfer-progress
|
||||
# Timeout: Set 8+ minutes. Actual time: ~4 minutes
|
||||
|
||||
# 2. Full package build (NEVER CANCEL - takes 2-3 minutes)
|
||||
mvn clean package -DskipTests=true --no-transfer-progress
|
||||
# Timeout: Set 5+ minutes. Actual time: ~2 minutes
|
||||
|
||||
# 3. Code quality validation (NEVER CANCEL - takes 45-60 seconds)
|
||||
mvn checkstyle:check --no-transfer-progress
|
||||
# Timeout: Set 3+ minutes. Actual time: ~50 seconds
|
||||
```
|
||||
|
||||
**CRITICAL TIMING NOTES:**
|
||||
- **NEVER CANCEL** any Maven build command
|
||||
- Compilation phase takes longest (~4 minutes) due to 34 modules
|
||||
- Full builds are faster on subsequent runs due to incremental compilation
|
||||
- Always use `--no-transfer-progress` to reduce log noise
|
||||
|
||||
### Testing Structure
|
||||
- **Test Framework**: TestNG (not JUnit)
|
||||
- **Test Files**: 298 test files across all modules
|
||||
- **Default Behavior**: Tests are DISABLED by default in pom.xml (`<skip>true</skip>`)
|
||||
- **Test Configuration**: Tests require external WeChat API credentials via test-config.xml files
|
||||
- **DO NOT** attempt to run tests without proper WeChat API credentials as they will fail
|
||||
|
||||
## Project Structure and Navigation
|
||||
|
||||
### Core SDK Modules (Main Development Areas)
|
||||
- `weixin-java-common/` - Common utilities and base classes (most important)
|
||||
- `weixin-java-mp/` - WeChat Official Account SDK (公众号)
|
||||
- `weixin-java-pay/` - WeChat Pay SDK (微信支付)
|
||||
- `weixin-java-miniapp/` - Mini Program SDK (小程序)
|
||||
- `weixin-java-cp/` - Enterprise WeChat SDK (企业微信)
|
||||
- `weixin-java-open/` - Open Platform SDK (开放平台)
|
||||
- `weixin-java-channel/` - Channel/Video SDK (视频号)
|
||||
- `weixin-java-qidian/` - Qidian SDK (企点)
|
||||
|
||||
### Framework Integration Modules
|
||||
- `spring-boot-starters/` - Spring Boot auto-configuration starters
|
||||
- `solon-plugins/` - Solon framework plugins
|
||||
- `weixin-graal/` - GraalVM native image support
|
||||
|
||||
### Configuration and Quality
|
||||
- `quality-checks/google_checks.xml` - Checkstyle configuration
|
||||
- `.editorconfig` - Code formatting rules (2 spaces = 1 tab)
|
||||
- `pom.xml` - Root Maven configuration
|
||||
|
||||
## Development Workflow
|
||||
|
||||
### Making Code Changes
|
||||
1. **Always build first** to establish clean baseline:
|
||||
```bash
|
||||
mvn clean compile --no-transfer-progress
|
||||
```
|
||||
|
||||
2. **Follow code style** (enforced by checkstyle):
|
||||
- Use 2 spaces for indentation (not tabs)
|
||||
- Follow Google Java Style Guide
|
||||
- Install EditorConfig plugin in your IDE
|
||||
|
||||
3. **Validate changes incrementally**:
|
||||
```bash
|
||||
# After each change:
|
||||
mvn compile --no-transfer-progress
|
||||
mvn checkstyle:check --no-transfer-progress
|
||||
```
|
||||
|
||||
### Before Submitting Changes
|
||||
**ALWAYS run these validation steps in sequence:**
|
||||
|
||||
1. **Code Style Validation**:
|
||||
```bash
|
||||
mvn checkstyle:check --no-transfer-progress
|
||||
# Must pass - takes ~50 seconds
|
||||
```
|
||||
|
||||
2. **Full Clean Build**:
|
||||
```bash
|
||||
mvn clean package -DskipTests=true --no-transfer-progress
|
||||
# Must succeed - takes ~2 minutes
|
||||
```
|
||||
|
||||
3. **Documentation**: Update javadoc for public methods and classes
|
||||
4. **Contribution Guidelines**: Follow `CONTRIBUTING.md` - PRs must target `develop` branch
|
||||
|
||||
## Module Dependencies and Build Order
|
||||
|
||||
### Core Module Dependencies (Build Order)
|
||||
1. `weixin-graal` (GraalVM support)
|
||||
2. `weixin-java-common` (foundation for all other modules)
|
||||
3. Core SDK modules (mp, pay, miniapp, cp, open, channel, qidian)
|
||||
4. Framework integrations (spring-boot-starters, solon-plugins)
|
||||
|
||||
### Key Relationship Patterns
|
||||
- All SDK modules depend on `weixin-java-common`
|
||||
- Spring Boot starters depend on corresponding SDK modules
|
||||
- Solon plugins follow same pattern as Spring Boot starters
|
||||
- Each module has both single and multi-account configurations
|
||||
|
||||
## Common Tasks and Commands
|
||||
|
||||
### Validate Specific Module
|
||||
```bash
|
||||
# Build single module (replace 'weixin-java-mp' with target module):
|
||||
cd weixin-java-mp
|
||||
mvn clean compile --no-transfer-progress
|
||||
```
|
||||
|
||||
### Check Dependencies
|
||||
```bash
|
||||
# Analyze dependencies:
|
||||
mvn dependency:tree --no-transfer-progress
|
||||
|
||||
# Check for dependency updates:
|
||||
./others/check-dependency-updates.sh
|
||||
```
|
||||
|
||||
### Release and Publishing
|
||||
```bash
|
||||
# Version check:
|
||||
mvn versions:display-property-updates --no-transfer-progress
|
||||
|
||||
# Deploy (requires credentials):
|
||||
mvn clean deploy -P release --no-transfer-progress
|
||||
```
|
||||
|
||||
## Important Files and Locations
|
||||
|
||||
### Configuration Files
|
||||
- `pom.xml` - Root Maven configuration with dependency management
|
||||
- `quality-checks/google_checks.xml` - Checkstyle rules
|
||||
- `.editorconfig` - IDE formatting configuration
|
||||
- `.github/workflows/maven-publish.yml` - CI/CD pipeline
|
||||
|
||||
### Documentation
|
||||
- `README.md` - Project overview and usage (Chinese)
|
||||
- `CONTRIBUTING.md` - Development contribution guidelines
|
||||
- `demo.md` - Links to demo projects and examples
|
||||
- Each module has dedicated documentation and examples
|
||||
|
||||
### Test Resources
|
||||
- `*/src/test/resources/test-config.sample.xml` - Template for test configuration
|
||||
- Tests require real WeChat API credentials to run
|
||||
|
||||
## SDK Usage Patterns
|
||||
|
||||
### Maven Dependency Usage
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-mp</artifactId> <!-- or other modules -->
|
||||
<version>4.7.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Common Development Areas
|
||||
- **API Client Implementation**: Located in `*/service/impl/` directories
|
||||
- **Model Classes**: Located in `*/bean/` directories
|
||||
- **Configuration**: Located in `*/config/` directories
|
||||
- **Utilities**: Located in `*/util/` directories in weixin-java-common
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Build Issues
|
||||
- **OutOfMemoryError**: Increase Maven memory: `export MAVEN_OPTS="-Xmx2g"`
|
||||
- **Compilation Failures**: Usually dependency issues - run `mvn clean` first
|
||||
- **Checkstyle Failures**: Check `.editorconfig` settings in IDE
|
||||
|
||||
### Common Gotchas
|
||||
- **Tests Always Skip**: This is normal - tests require WeChat API credentials
|
||||
- **Multi-Module Changes**: Always build from root, not individual modules
|
||||
- **Branch Target**: PRs must target `develop` branch, not `master`/`release`
|
||||
|
||||
## Performance Notes
|
||||
- **First Build**: Takes 4-5 minutes due to dependency downloads
|
||||
- **Incremental Builds**: Much faster (~30-60 seconds)
|
||||
- **Checkstyle**: Runs quickly (~50 seconds) and should be run frequently
|
||||
- **IDE Performance**: Project uses Lombok - ensure annotation processing is enabled
|
||||
|
||||
Remember: This is a SDK library project, not a runnable application. Changes should focus on API functionality, not application behavior.
|
||||
129
NEW_TRANSFER_API_SUPPORT.md
Normal file
129
NEW_TRANSFER_API_SUPPORT.md
Normal file
@@ -0,0 +1,129 @@
|
||||
# 微信支付新版商户转账API支持
|
||||
|
||||
## 问题解答
|
||||
|
||||
**问题**: 新开通的商户号只能使用最新版本的商户转账接口,WxJava是否支持?
|
||||
|
||||
**答案**: **WxJava 已经完整支持新版商户转账API!** 从2025年1月15日开始生效的新版转账API已在WxJava中实现。
|
||||
|
||||
## 新版转账API特性
|
||||
|
||||
### 1. API接口对比
|
||||
|
||||
| 特性 | 传统转账API | 新版转账API (2025.1.15+) |
|
||||
|------|-------------|-------------------------|
|
||||
| **服务类** | `MerchantTransferService` | `TransferService` |
|
||||
| **API路径** | `/v3/transfer/batches` | `/v3/fund-app/mch-transfer/transfer-bills` |
|
||||
| **转账方式** | 批量转账 | 单笔转账 |
|
||||
| **场景支持** | 基础场景 | 丰富场景(如佣金报酬等) |
|
||||
| **撤销功能** | ❌ 不支持 | ✅ 支持 |
|
||||
| **适用范围** | 所有商户 | **新开通商户必须使用** |
|
||||
|
||||
### 2. 新版API功能列表
|
||||
|
||||
✅ **发起转账** - `transferBills()`
|
||||
✅ **查询转账** - `getBillsByOutBillNo()` / `getBillsByTransferBillNo()`
|
||||
✅ **撤销转账** - `transformBillsCancel()`
|
||||
✅ **回调通知** - `parseTransferBillsNotifyResult()`
|
||||
✅ **RSA加密** - 自动处理用户姓名加密
|
||||
✅ **场景支持** - 支持多种转账场景ID
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 1. 获取服务实例
|
||||
|
||||
```java
|
||||
// 获取WxPayService实例
|
||||
WxPayService wxPayService = new WxPayServiceImpl();
|
||||
wxPayService.setConfig(config);
|
||||
|
||||
// 获取新版转账服务 - 这就是新开通商户需要使用的服务!
|
||||
TransferService transferService = wxPayService.getTransferService();
|
||||
```
|
||||
|
||||
### 2. 发起转账(新版API)
|
||||
|
||||
```java
|
||||
// 构建转账请求
|
||||
TransferBillsRequest request = TransferBillsRequest.newBuilder()
|
||||
.appid("your_appid") // 应用ID
|
||||
.outBillNo("T" + System.currentTimeMillis()) // 商户转账单号
|
||||
.transferSceneId("1005") // 转账场景ID(佣金报酬)
|
||||
.openid("user_openid") // 用户openid
|
||||
.userName("张三") // 收款用户姓名(可选,自动加密)
|
||||
.transferAmount(100) // 转账金额(分)
|
||||
.transferRemark("佣金报酬") // 转账备注
|
||||
.build();
|
||||
|
||||
// 发起转账
|
||||
TransferBillsResult result = transferService.transferBills(request);
|
||||
System.out.println("转账成功,微信转账单号:" + result.getTransferBillNo());
|
||||
```
|
||||
|
||||
### 3. 查询转账结果
|
||||
|
||||
```java
|
||||
// 通过商户单号查询
|
||||
TransferBillsGetResult result = transferService.getBillsByOutBillNo("T1642567890123");
|
||||
|
||||
// 通过微信转账单号查询
|
||||
TransferBillsGetResult result2 = transferService.getBillsByTransferBillNo("wx_transfer_bill_no");
|
||||
|
||||
System.out.println("转账状态:" + result.getState());
|
||||
```
|
||||
|
||||
### 4. 撤销转账(新功能)
|
||||
|
||||
```java
|
||||
// 撤销转账
|
||||
TransferBillsCancelResult cancelResult = transferService.transformBillsCancel("T1642567890123");
|
||||
System.out.println("撤销状态:" + cancelResult.getState());
|
||||
```
|
||||
|
||||
## 重要说明
|
||||
|
||||
### 转账场景ID (transfer_scene_id)
|
||||
- **1005**: 佣金报酬(常用场景)
|
||||
- 其他场景需要在微信商户平台申请
|
||||
|
||||
### 转账状态说明
|
||||
- **ACCEPTED**: 转账已受理
|
||||
- **PROCESSING**: 转账处理中
|
||||
- **SUCCESS**: 转账成功
|
||||
- **FAIL**: 转账失败
|
||||
- **CANCELLED**: 转账撤销完成
|
||||
|
||||
### 新开通商户使用建议
|
||||
|
||||
1. **优先使用** `TransferService` (新版API)
|
||||
2. **不要使用** `MerchantTransferService` (可能不支持)
|
||||
3. **必须设置** 转账场景ID (`transfer_scene_id`)
|
||||
4. **建议开启** 回调通知以实时获取转账结果
|
||||
|
||||
## 完整示例代码
|
||||
|
||||
详细的使用示例请参考:
|
||||
- 📄 [NEW_TRANSFER_API_USAGE.md](./NEW_TRANSFER_API_USAGE.md) - 详细使用指南
|
||||
- 💻 [NewTransferApiExample.java](./weixin-java-pay/src/main/java/com/github/binarywang/wxpay/example/NewTransferApiExample.java) - 完整代码示例
|
||||
|
||||
## 常见问题
|
||||
|
||||
**Q: 我是新开通的商户,应该使用哪个服务?**
|
||||
A: 使用 `TransferService`,这是专为新版API设计的服务。
|
||||
|
||||
**Q: 新版API和旧版API有什么区别?**
|
||||
A: 新版API使用单笔转账模式,支持更丰富的转账场景,并且支持撤销功能。
|
||||
|
||||
**Q: 如何设置转账场景ID?**
|
||||
A: 在商户平台申请相应场景,常用的佣金报酬场景ID是"1005"。
|
||||
|
||||
**Q: 用户姓名需要加密吗?**
|
||||
A: WxJava会自动处理RSA加密,您只需要传入明文姓名即可。
|
||||
|
||||
## 版本要求
|
||||
|
||||
- WxJava 版本:4.7.0+
|
||||
- 支持时间:2025年1月15日+
|
||||
- 适用商户:所有商户(新开通商户强制使用)
|
||||
|
||||
通过以上说明,新开通的微信支付商户可以放心使用WxJava进行商户转账操作!
|
||||
148
NEW_TRANSFER_API_USAGE.md
Normal file
148
NEW_TRANSFER_API_USAGE.md
Normal file
@@ -0,0 +1,148 @@
|
||||
# 微信支付新版商户转账API使用指南
|
||||
|
||||
## 概述
|
||||
|
||||
从2025年1月15日开始,微信支付推出了新版的商户转账API。新开通的商户号只能使用最新版本的商户转账接口。WxJava 已经完整支持新版转账API。
|
||||
|
||||
## API对比
|
||||
|
||||
### 传统转账API (仍然支持)
|
||||
- **服务类**: `MerchantTransferService`
|
||||
- **API前缀**: `/v3/transfer/batches`
|
||||
- **特点**: 支持批量转账,一次可以转账给多个用户
|
||||
|
||||
### 新版转账API (2025.1.15+)
|
||||
- **服务类**: `TransferService`
|
||||
- **API前缀**: `/v3/fund-app/mch-transfer/transfer-bills`
|
||||
- **特点**: 单笔转账,支持更丰富的转账场景
|
||||
|
||||
## 使用新版转账API
|
||||
|
||||
### 1. 获取服务实例
|
||||
|
||||
```java
|
||||
// 获取WxPayService实例
|
||||
WxPayService wxPayService = new WxPayServiceImpl();
|
||||
wxPayService.setConfig(config);
|
||||
|
||||
// 获取新版转账服务
|
||||
TransferService transferService = wxPayService.getTransferService();
|
||||
```
|
||||
|
||||
### 2. 发起转账
|
||||
|
||||
```java
|
||||
// 构建转账请求
|
||||
TransferBillsRequest request = TransferBillsRequest.newBuilder()
|
||||
.appid("your_appid") // 应用ID
|
||||
.outBillNo("T" + System.currentTimeMillis()) // 商户转账单号
|
||||
.transferSceneId("1005") // 转账场景ID(佣金报酬)
|
||||
.openid("user_openid") // 用户openid
|
||||
.userName("张三") // 收款用户姓名(可选,需要加密)
|
||||
.transferAmount(100) // 转账金额(分)
|
||||
.transferRemark("佣金报酬") // 转账备注
|
||||
.notifyUrl("https://your-domain.com/notify") // 回调地址(可选)
|
||||
.userRecvPerception("Y") // 用户收款感知(可选)
|
||||
.build();
|
||||
|
||||
try {
|
||||
TransferBillsResult result = transferService.transferBills(request);
|
||||
System.out.println("转账成功,微信转账单号:" + result.getTransferBillNo());
|
||||
System.out.println("状态:" + result.getState());
|
||||
} catch (WxPayException e) {
|
||||
System.err.println("转账失败:" + e.getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 查询转账结果
|
||||
|
||||
```java
|
||||
// 通过商户单号查询
|
||||
String outBillNo = "T1642567890123";
|
||||
TransferBillsGetResult result = transferService.getBillsByOutBillNo(outBillNo);
|
||||
|
||||
// 通过微信转账单号查询
|
||||
String transferBillNo = "1000000000000000000000000001";
|
||||
TransferBillsGetResult result2 = transferService.getBillsByTransferBillNo(transferBillNo);
|
||||
|
||||
System.out.println("转账状态:" + result.getState());
|
||||
System.out.println("转账金额:" + result.getTransferAmount());
|
||||
```
|
||||
|
||||
### 4. 撤销转账
|
||||
|
||||
```java
|
||||
// 撤销转账(仅在特定状态下可撤销)
|
||||
String outBillNo = "T1642567890123";
|
||||
TransferBillsCancelResult cancelResult = transferService.transformBillsCancel(outBillNo);
|
||||
System.out.println("撤销结果:" + cancelResult.getState());
|
||||
```
|
||||
|
||||
### 5. 处理回调通知
|
||||
|
||||
```java
|
||||
// 在回调接口中处理通知
|
||||
@PostMapping("/transfer/notify")
|
||||
public String handleTransferNotify(HttpServletRequest request) throws Exception {
|
||||
String notifyData = StreamUtils.copyToString(request.getInputStream(), StandardCharsets.UTF_8);
|
||||
|
||||
// 构建签名头
|
||||
SignatureHeader header = new SignatureHeader();
|
||||
header.setTimeStamp(request.getHeader("Wechatpay-Timestamp"));
|
||||
header.setNonce(request.getHeader("Wechatpay-Nonce"));
|
||||
header.setSignature(request.getHeader("Wechatpay-Signature"));
|
||||
header.setSerial(request.getHeader("Wechatpay-Serial"));
|
||||
|
||||
try {
|
||||
TransferBillsNotifyResult notifyResult = transferService.parseTransferBillsNotifyResult(notifyData, header);
|
||||
|
||||
// 处理业务逻辑
|
||||
String outBillNo = notifyResult.getOutBillNo();
|
||||
String state = notifyResult.getState();
|
||||
|
||||
System.out.println("转账单号:" + outBillNo + ",状态:" + state);
|
||||
|
||||
return "SUCCESS";
|
||||
} catch (WxPayException e) {
|
||||
System.err.println("验签失败:" + e.getMessage());
|
||||
return "FAIL";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 重要参数说明
|
||||
|
||||
### 转账场景ID (transfer_scene_id)
|
||||
- **1005**: 佣金报酬(常用)
|
||||
- 其他场景ID需要在商户平台申请
|
||||
|
||||
### 转账状态
|
||||
- **PROCESSING**: 转账中
|
||||
- **SUCCESS**: 转账成功
|
||||
- **FAILED**: 转账失败
|
||||
- **REFUNDED**: 已退款
|
||||
|
||||
### 用户收款感知 (user_recv_perception)
|
||||
- **Y**: 用户会收到微信转账通知
|
||||
- **N**: 用户不会收到微信转账通知
|
||||
|
||||
## 新旧API对比总结
|
||||
|
||||
| 特性 | 传统API (MerchantTransferService) | 新版API (TransferService) |
|
||||
|------|----------------------------------|---------------------------|
|
||||
| 发起方式 | 批量转账 | 单笔转账 |
|
||||
| API路径 | `/v3/transfer/batches` | `/v3/fund-app/mch-transfer/transfer-bills` |
|
||||
| 场景支持 | 基础转账场景 | 丰富的转账场景 |
|
||||
| 回调通知 | 支持 | 支持 |
|
||||
| 撤销功能 | 不支持 | 支持 |
|
||||
| 适用商户 | 所有商户 | 新开通商户必须使用 |
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **新开通的商户号**: 必须使用新版API (`TransferService`)
|
||||
2. **转账场景ID**: 需要在商户平台申请相应的转账场景
|
||||
3. **用户姓名加密**: 如果传入用户姓名,会自动进行RSA加密
|
||||
4. **回调验签**: 建议开启回调验签以确保安全性
|
||||
5. **错误处理**: 妥善处理各种异常情况
|
||||
|
||||
通过以上指南,您可以轻松使用WxJava的新版商户转账API功能。
|
||||
@@ -53,8 +53,8 @@
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="#" target="_blank">
|
||||
<img height="120" src="images/banners/aliyun.jpg" alt="ad">
|
||||
<a href="https://www.crmeb.com/xiazai" target="_blank">
|
||||
<img height="120" src="https://crmebjavamer.oss-cn-beijing.aliyuncs.com/crmebimage/gitee/WechatIMG202.jpg" alt="ad">
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
0
others/mvnw
vendored
Normal file → Executable file
0
others/mvnw
vendored
Normal file → Executable file
25
pom.xml
25
pom.xml
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>WxJava - Weixin/Wechat Java SDK</name>
|
||||
<description>微信开发Java SDK</description>
|
||||
@@ -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>
|
||||
@@ -187,7 +187,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.10</version>
|
||||
<version>3.18.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -468,6 +468,21 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.0</version> <!-- 建议使用最新版本 -->
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<!-- 绑定到 verify 阶段,在 install 之前执行 -->
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal> <!-- 使用 jar-no-fork 效率更高 -->
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<packaging>pom</packaging>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.binarywang.solon.wxjava.channel.service.WxChannelMultiServicesImpl;
|
||||
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;
|
||||
@@ -84,6 +85,9 @@ public abstract class AbstractWxChannelConfiguration {
|
||||
case HTTP_CLIENT:
|
||||
wxChannelService = new WxChannelServiceHttpClientImpl();
|
||||
break;
|
||||
case HTTP_COMPONENTS:
|
||||
wxChannelService = new WxChannelServiceHttpComponentsImpl();
|
||||
break;
|
||||
default:
|
||||
wxChannelService = new WxChannelServiceImpl();
|
||||
break;
|
||||
|
||||
@@ -11,6 +11,10 @@ public enum HttpClientType {
|
||||
* HttpClient
|
||||
*/
|
||||
HTTP_CLIENT,
|
||||
/**
|
||||
* HttpComponents
|
||||
*/
|
||||
HTTP_COMPONENTS
|
||||
// WxChannelServiceOkHttpImpl 实现经测试无法正常完成业务固暂不支持OK_HTTP方式
|
||||
// /**
|
||||
// * OkHttp.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -7,10 +7,7 @@ import com.binarywang.solon.wxjava.cp_multi.service.WxCpMultiServicesImpl;
|
||||
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;
|
||||
@@ -96,6 +93,9 @@ public abstract class AbstractWxCpConfiguration {
|
||||
case HTTP_CLIENT:
|
||||
wxCpService = new WxCpServiceApacheHttpClientImpl();
|
||||
break;
|
||||
case HTTP_COMPONENTS:
|
||||
wxCpService = new WxCpServiceHttpComponentsImpl();
|
||||
break;
|
||||
default:
|
||||
wxCpService = new WxCpServiceImpl();
|
||||
break;
|
||||
|
||||
@@ -117,6 +117,10 @@ public class WxCpMultiProperties implements Serializable {
|
||||
* HttpClient
|
||||
*/
|
||||
HTTP_CLIENT,
|
||||
/**
|
||||
* HttpComponents
|
||||
*/
|
||||
HTTP_COMPONENTS,
|
||||
/**
|
||||
* OkHttp
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<packaging>pom</packaging>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
@@ -26,6 +26,7 @@
|
||||
<module>wx-java-open-spring-boot-starter</module>
|
||||
<module>wx-java-qidian-spring-boot-starter</module>
|
||||
<module>wx-java-cp-multi-spring-boot-starter</module>
|
||||
<module>wx-java-cp-tp-multi-spring-boot-starter</module>
|
||||
<module>wx-java-cp-spring-boot-starter</module>
|
||||
<module>wx-java-channel-spring-boot-starter</module>
|
||||
<module>wx-java-channel-multi-spring-boot-starter</module>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -119,6 +119,8 @@ public abstract class AbstractWxChannelConfiguration {
|
||||
config.setAesKey(aesKey);
|
||||
}
|
||||
config.setStableAccessToken(useStableAccessToken);
|
||||
config.setApiHostUrl(StringUtils.trimToNull(wxChannelSingleProperties.getApiHostUrl()));
|
||||
config.setAccessTokenUrl(StringUtils.trimToNull(wxChannelSingleProperties.getAccessTokenUrl()));
|
||||
}
|
||||
|
||||
private void configHttp(WxChannelDefaultConfigImpl config, WxChannelMultiProperties.ConfigStorage storage) {
|
||||
|
||||
@@ -40,4 +40,16 @@ public class WxChannelSingleProperties implements Serializable {
|
||||
* 是否使用稳定版 Access Token
|
||||
*/
|
||||
private boolean useStableAccessToken = false;
|
||||
|
||||
/**
|
||||
* 自定义API主机地址,用于替换默认的 https://api.weixin.qq.com
|
||||
* 例如:http://proxy.company.com:8080
|
||||
*/
|
||||
private String apiHostUrl;
|
||||
|
||||
/**
|
||||
* 自定义获取AccessToken地址,用于向自定义统一服务获取AccessToken
|
||||
* 例如:http://proxy.company.com:8080/oauth/token
|
||||
*/
|
||||
private String accessTokenUrl;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java-channel-multi-spring-boot-starter</artifactId>
|
||||
<artifactId>wx-java-channel-spring-boot-starter</artifactId>
|
||||
<version>${version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ public abstract class AbstractWxChannelConfigStorageConfiguration {
|
||||
config.setAesKey(StringUtils.trimToNull(properties.getAesKey()));
|
||||
config.setMsgDataFormat(StringUtils.trimToNull(properties.getMsgDataFormat()));
|
||||
config.setStableAccessToken(properties.isUseStableAccessToken());
|
||||
config.setApiHostUrl(StringUtils.trimToNull(properties.getApiHostUrl()));
|
||||
config.setAccessTokenUrl(StringUtils.trimToNull(properties.getAccessTokenUrl()));
|
||||
|
||||
WxChannelProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
|
||||
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
|
||||
|
||||
@@ -46,6 +46,18 @@ public class WxChannelProperties {
|
||||
*/
|
||||
private boolean useStableAccessToken = false;
|
||||
|
||||
/**
|
||||
* 自定义API主机地址,用于替换默认的 https://api.weixin.qq.com
|
||||
* 例如:http://proxy.company.com:8080
|
||||
*/
|
||||
private String apiHostUrl;
|
||||
|
||||
/**
|
||||
* 自定义获取AccessToken地址,用于向自定义统一服务获取AccessToken
|
||||
* 例如:http://proxy.company.com:8080/oauth/token
|
||||
*/
|
||||
private String accessTokenUrl;
|
||||
|
||||
/**
|
||||
* 存储策略
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -139,6 +139,9 @@ public abstract class AbstractWxCpConfiguration {
|
||||
if (StringUtils.isNotBlank(msgAuditLibPath)) {
|
||||
config.setMsgAuditLibPath(msgAuditLibPath);
|
||||
}
|
||||
if (StringUtils.isNotBlank(wxCpSingleProperties.getBaseApiUrl())) {
|
||||
config.setBaseApiUrl(wxCpSingleProperties.getBaseApiUrl());
|
||||
}
|
||||
}
|
||||
|
||||
private void configHttp(WxCpDefaultConfigImpl config, WxCpMultiProperties.ConfigStorage storage) {
|
||||
|
||||
@@ -43,4 +43,10 @@ public class WxCpSingleProperties implements Serializable {
|
||||
* 微信企业号应用 会话存档类库路径
|
||||
*/
|
||||
private String msgAuditLibPath;
|
||||
|
||||
/**
|
||||
* 自定义企业微信服务器baseUrl,用于替换默认的 https://qyapi.weixin.qq.com
|
||||
* 例如:http://proxy.company.com:8080
|
||||
*/
|
||||
private String baseApiUrl;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -48,6 +48,12 @@ public class WxCpProperties {
|
||||
*/
|
||||
private String msgAuditLibPath;
|
||||
|
||||
/**
|
||||
* 自定义企业微信服务器baseUrl,用于替换默认的 https://qyapi.weixin.qq.com
|
||||
* 例如:http://proxy.company.com:8080
|
||||
*/
|
||||
private String baseApiUrl;
|
||||
|
||||
/**
|
||||
* 配置存储策略,默认内存
|
||||
*/
|
||||
|
||||
@@ -37,6 +37,9 @@ public abstract class AbstractWxCpConfigStorageConfiguration {
|
||||
if (StringUtils.isNotBlank(msgAuditLibPath)) {
|
||||
config.setMsgAuditLibPath(msgAuditLibPath);
|
||||
}
|
||||
if (StringUtils.isNotBlank(properties.getBaseApiUrl())) {
|
||||
config.setBaseApiUrl(properties.getBaseApiUrl());
|
||||
}
|
||||
|
||||
WxCpProperties.ConfigStorage storage = properties.getConfigStorage();
|
||||
String httpProxyHost = storage.getHttpProxyHost();
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
# wx-java-cp-multi-spring-boot-starter
|
||||
|
||||
企业微信多账号配置
|
||||
|
||||
- 实现多 WxCpService 初始化。
|
||||
- 未实现 WxCpTpService 初始化,需要的小伙伴可以参考多 WxCpService 配置的实现。
|
||||
- 未实现 WxCpCgService 初始化,需要的小伙伴可以参考多 WxCpService 配置的实现。
|
||||
|
||||
## 快速开始
|
||||
|
||||
1. 引入依赖
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java-cp-multi-spring-boot-starter</artifactId>
|
||||
<version>${version}</version>
|
||||
</dependency>
|
||||
```
|
||||
2. 添加配置(application.properties)
|
||||
```properties
|
||||
# 应用 1 配置
|
||||
wx.cp.corps.tenantId1.corp-id = @corp-id
|
||||
wx.cp.corps.tenantId1.corp-secret = @corp-secret
|
||||
## 选填
|
||||
wx.cp.corps.tenantId1.agent-id = @agent-id
|
||||
wx.cp.corps.tenantId1.token = @token
|
||||
wx.cp.corps.tenantId1.aes-key = @aes-key
|
||||
wx.cp.corps.tenantId1.msg-audit-priKey = @msg-audit-priKey
|
||||
wx.cp.corps.tenantId1.msg-audit-lib-path = @msg-audit-lib-path
|
||||
|
||||
# 应用 2 配置
|
||||
wx.cp.corps.tenantId2.corp-id = @corp-id
|
||||
wx.cp.corps.tenantId2.corp-secret = @corp-secret
|
||||
## 选填
|
||||
wx.cp.corps.tenantId2.agent-id = @agent-id
|
||||
wx.cp.corps.tenantId2.token = @token
|
||||
wx.cp.corps.tenantId2.aes-key = @aes-key
|
||||
wx.cp.corps.tenantId2.msg-audit-priKey = @msg-audit-priKey
|
||||
wx.cp.corps.tenantId2.msg-audit-lib-path = @msg-audit-lib-path
|
||||
|
||||
# 公共配置
|
||||
## ConfigStorage 配置(选填)
|
||||
wx.cp.config-storage.type=memory # 配置类型: memory(默认), jedis, redisson, redistemplate
|
||||
## http 客户端配置(选填)
|
||||
## # http客户端类型: http_client(默认), ok_http, jodd_http
|
||||
wx.cp.config-storage.http-client-type=http_client
|
||||
wx.cp.config-storage.http-proxy-host=
|
||||
wx.cp.config-storage.http-proxy-port=
|
||||
wx.cp.config-storage.http-proxy-username=
|
||||
wx.cp.config-storage.http-proxy-password=
|
||||
## 最大重试次数,默认:5 次,如果小于 0,则为 0
|
||||
wx.cp.config-storage.max-retry-times=5
|
||||
## 重试时间间隔步进,默认:1000 毫秒,如果小于 0,则为 1000
|
||||
wx.cp.config-storage.retry-sleep-millis=1000
|
||||
```
|
||||
3. 支持自动注入的类型: `WxCpMultiServices`
|
||||
|
||||
4. 使用样例
|
||||
|
||||
```java
|
||||
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServices;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.api.WxCpUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class DemoService {
|
||||
@Autowired
|
||||
private WxCpTpMultiServices wxCpTpMultiServices;
|
||||
|
||||
public void test() {
|
||||
// 应用 1 的 WxCpService
|
||||
WxCpService wxCpService1 = wxCpMultiServices.getWxCpService("tenantId1");
|
||||
WxCpUserService userService1 = wxCpService1.getUserService();
|
||||
userService1.getUserId("xxx");
|
||||
// todo ...
|
||||
|
||||
// 应用 2 的 WxCpService
|
||||
WxCpService wxCpService2 = wxCpMultiServices.getWxCpService("tenantId2");
|
||||
WxCpUserService userService2 = wxCpService2.getUserService();
|
||||
userService2.getUserId("xxx");
|
||||
// todo ...
|
||||
|
||||
// 应用 3 的 WxCpService
|
||||
WxCpService wxCpService3 = wxCpMultiServices.getWxCpService("tenantId3");
|
||||
// 判断是否为空
|
||||
if (wxCpService3 == null) {
|
||||
// todo wxCpService3 为空,请先配置 tenantId3 企业微信应用参数
|
||||
return;
|
||||
}
|
||||
WxCpUserService userService3 = wxCpService3.getUserService();
|
||||
userService3.getUserId("xxx");
|
||||
// todo ...
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>wx-java-cp-tp-multi-spring-boot-starter</artifactId>
|
||||
<name>WxJava - Spring Boot Starter for WxCp::支持多账号配置</name>
|
||||
<description>微信企业号开发的 Spring Boot Starter::支持多账号配置</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-cp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.binarywang.spring.starter.wxjava.cp.autoconfigure;
|
||||
|
||||
import com.binarywang.spring.starter.wxjava.cp.configuration.WxCpTpMultiServicesAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* 企业微信自动注册
|
||||
*
|
||||
* @author yl
|
||||
* created on 2023/10/16
|
||||
*/
|
||||
@Configuration
|
||||
@Import(WxCpTpMultiServicesAutoConfiguration.class)
|
||||
public class WxCpTpMultiAutoConfiguration {
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.binarywang.spring.starter.wxjava.cp.configuration;
|
||||
|
||||
import com.binarywang.spring.starter.wxjava.cp.configuration.services.WxCpTpInJedisTpConfiguration;
|
||||
import com.binarywang.spring.starter.wxjava.cp.configuration.services.WxCpTpInMemoryTpConfiguration;
|
||||
import com.binarywang.spring.starter.wxjava.cp.configuration.services.WxCpTpInRedisTemplateTpConfiguration;
|
||||
import com.binarywang.spring.starter.wxjava.cp.configuration.services.WxCpTpInRedissonTpConfiguration;
|
||||
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* 企业微信平台相关服务自动注册
|
||||
*
|
||||
* @author yl
|
||||
* created on 2023/10/16
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(WxCpTpMultiProperties.class)
|
||||
@Import({
|
||||
WxCpTpInJedisTpConfiguration.class,
|
||||
WxCpTpInMemoryTpConfiguration.class,
|
||||
WxCpTpInRedissonTpConfiguration.class,
|
||||
WxCpTpInRedisTemplateTpConfiguration.class
|
||||
})
|
||||
public class WxCpTpMultiServicesAutoConfiguration {
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.binarywang.spring.starter.wxjava.cp.configuration.services;
|
||||
|
||||
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiProperties;
|
||||
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpSingleProperties;
|
||||
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServices;
|
||||
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServicesImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
|
||||
import me.chanjar.weixin.cp.tp.service.WxCpTpService;
|
||||
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceApacheHttpClientImpl;
|
||||
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceImpl;
|
||||
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceJoddHttpImpl;
|
||||
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceOkHttpImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* WxCpConfigStorage 抽象配置类
|
||||
*
|
||||
* @author yl
|
||||
* created on 2023/10/16
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public abstract class AbstractWxCpTpConfiguration {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param wxCpTpMultiProperties 应用列表配置
|
||||
* @param services 用于支持,应用启动之后,可以调用这个接口添加新服务对象。主要是配置是从数据库中读取的
|
||||
* @return
|
||||
*/
|
||||
public WxCpTpMultiServices wxCpMultiServices(WxCpTpMultiProperties wxCpTpMultiProperties,WxCpTpMultiServices services) {
|
||||
Map<String, WxCpTpSingleProperties> corps = wxCpTpMultiProperties.getCorps();
|
||||
if (corps == null || corps.isEmpty()) {
|
||||
log.warn("企业微信应用参数未配置,通过 WxCpMultiServices#getWxCpTpService(\"tenantId\")获取实例将返回空");
|
||||
return new WxCpTpMultiServicesImpl();
|
||||
}
|
||||
|
||||
if (services == null) {
|
||||
services = new WxCpTpMultiServicesImpl();
|
||||
}
|
||||
|
||||
Set<Map.Entry<String, WxCpTpSingleProperties>> entries = corps.entrySet();
|
||||
for (Map.Entry<String, WxCpTpSingleProperties> entry : entries) {
|
||||
String tenantId = entry.getKey();
|
||||
WxCpTpSingleProperties wxCpTpSingleProperties = entry.getValue();
|
||||
WxCpTpDefaultConfigImpl storage = this.wxCpTpConfigStorage(wxCpTpMultiProperties);
|
||||
this.configCorp(storage, wxCpTpSingleProperties);
|
||||
this.configHttp(storage, wxCpTpMultiProperties.getConfigStorage());
|
||||
WxCpTpService wxCpTpService = this.wxCpTpService(storage, wxCpTpMultiProperties.getConfigStorage());
|
||||
if (services.getWxCpTpService(tenantId) == null) {
|
||||
// 不存在的才会添加到服务列表中
|
||||
services.addWxCpTpService(tenantId, wxCpTpService);
|
||||
}
|
||||
}
|
||||
return services;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置 WxCpDefaultConfigImpl
|
||||
*
|
||||
* @param wxCpTpMultiProperties 参数
|
||||
* @return WxCpDefaultConfigImpl
|
||||
*/
|
||||
protected abstract WxCpTpDefaultConfigImpl wxCpTpConfigStorage(WxCpTpMultiProperties wxCpTpMultiProperties);
|
||||
|
||||
private WxCpTpService wxCpTpService(WxCpTpConfigStorage wxCpTpConfigStorage, WxCpTpMultiProperties.ConfigStorage storage) {
|
||||
WxCpTpMultiProperties.HttpClientType httpClientType = storage.getHttpClientType();
|
||||
WxCpTpService cpTpService;
|
||||
switch (httpClientType) {
|
||||
case OK_HTTP:
|
||||
cpTpService = new WxCpTpServiceOkHttpImpl();
|
||||
break;
|
||||
case JODD_HTTP:
|
||||
cpTpService = new WxCpTpServiceJoddHttpImpl();
|
||||
break;
|
||||
case HTTP_CLIENT:
|
||||
cpTpService = new WxCpTpServiceApacheHttpClientImpl();
|
||||
break;
|
||||
default:
|
||||
cpTpService = new WxCpTpServiceImpl();
|
||||
break;
|
||||
}
|
||||
cpTpService.setWxCpTpConfigStorage(wxCpTpConfigStorage);
|
||||
int maxRetryTimes = storage.getMaxRetryTimes();
|
||||
if (maxRetryTimes < 0) {
|
||||
maxRetryTimes = 0;
|
||||
}
|
||||
int retrySleepMillis = storage.getRetrySleepMillis();
|
||||
if (retrySleepMillis < 0) {
|
||||
retrySleepMillis = 1000;
|
||||
}
|
||||
cpTpService.setRetrySleepMillis(retrySleepMillis);
|
||||
cpTpService.setMaxRetryTimes(maxRetryTimes);
|
||||
return cpTpService;
|
||||
}
|
||||
|
||||
private void configCorp(WxCpTpDefaultConfigImpl config, WxCpTpSingleProperties wxCpTpSingleProperties) {
|
||||
String corpId = wxCpTpSingleProperties.getCorpId();
|
||||
String providerSecret = wxCpTpSingleProperties.getProviderSecret();
|
||||
String suiteId = wxCpTpSingleProperties.getSuiteId();
|
||||
String token = wxCpTpSingleProperties.getToken();
|
||||
String suiteSecret = wxCpTpSingleProperties.getSuiteSecret();
|
||||
// 企业微信,私钥,会话存档路径
|
||||
config.setCorpId(corpId);
|
||||
config.setProviderSecret(providerSecret);
|
||||
config.setEncodingAESKey(wxCpTpSingleProperties.getEncodingAESKey());
|
||||
config.setSuiteId(suiteId);
|
||||
config.setToken(token);
|
||||
config.setSuiteSecret(suiteSecret);
|
||||
}
|
||||
|
||||
private void configHttp(WxCpTpDefaultConfigImpl config, WxCpTpMultiProperties.ConfigStorage storage) {
|
||||
String httpProxyHost = storage.getHttpProxyHost();
|
||||
Integer httpProxyPort = storage.getHttpProxyPort();
|
||||
String httpProxyUsername = storage.getHttpProxyUsername();
|
||||
String httpProxyPassword = storage.getHttpProxyPassword();
|
||||
if (StringUtils.isNotBlank(httpProxyHost)) {
|
||||
config.setHttpProxyHost(httpProxyHost);
|
||||
if (httpProxyPort != null) {
|
||||
config.setHttpProxyPort(httpProxyPort);
|
||||
}
|
||||
if (StringUtils.isNotBlank(httpProxyUsername)) {
|
||||
config.setHttpProxyUsername(httpProxyUsername);
|
||||
}
|
||||
if (StringUtils.isNotBlank(httpProxyPassword)) {
|
||||
config.setHttpProxyPassword(httpProxyPassword);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.binarywang.spring.starter.wxjava.cp.configuration.services;
|
||||
|
||||
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiProperties;
|
||||
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiRedisProperties;
|
||||
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServices;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpJedisConfigImpl;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpTpJedisConfigImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
/**
|
||||
* 自动装配基于 jedis 策略配置
|
||||
*
|
||||
* @author yl
|
||||
* created on 2023/10/16
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(
|
||||
prefix = WxCpTpMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "jedis"
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxCpTpInJedisTpConfiguration extends AbstractWxCpTpConfiguration {
|
||||
private final WxCpTpMultiProperties wxCpTpMultiProperties;
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
@Bean
|
||||
public WxCpTpMultiServices wxCpMultiServices() {
|
||||
return this.wxCpMultiServices(wxCpTpMultiProperties,null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxCpTpDefaultConfigImpl wxCpTpConfigStorage(WxCpTpMultiProperties wxCpTpMultiProperties) {
|
||||
return this.configRedis(wxCpTpMultiProperties);
|
||||
}
|
||||
|
||||
private WxCpTpDefaultConfigImpl configRedis(WxCpTpMultiProperties wxCpTpMultiProperties) {
|
||||
WxCpTpMultiRedisProperties wxCpTpMultiRedisProperties = wxCpTpMultiProperties.getConfigStorage().getRedis();
|
||||
JedisPool jedisPool;
|
||||
if (wxCpTpMultiRedisProperties != null && StringUtils.isNotEmpty(wxCpTpMultiRedisProperties.getHost())) {
|
||||
jedisPool = getJedisPool(wxCpTpMultiProperties);
|
||||
} else {
|
||||
jedisPool = applicationContext.getBean(JedisPool.class);
|
||||
}
|
||||
return new WxCpTpJedisConfigImpl(jedisPool, wxCpTpMultiProperties.getConfigStorage().getKeyPrefix());
|
||||
}
|
||||
|
||||
private JedisPool getJedisPool(WxCpTpMultiProperties wxCpTpMultiProperties) {
|
||||
WxCpTpMultiProperties.ConfigStorage storage = wxCpTpMultiProperties.getConfigStorage();
|
||||
WxCpTpMultiRedisProperties redis = storage.getRedis();
|
||||
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
if (redis.getMaxActive() != null) {
|
||||
config.setMaxTotal(redis.getMaxActive());
|
||||
}
|
||||
if (redis.getMaxIdle() != null) {
|
||||
config.setMaxIdle(redis.getMaxIdle());
|
||||
}
|
||||
if (redis.getMaxWaitMillis() != null) {
|
||||
config.setMaxWaitMillis(redis.getMaxWaitMillis());
|
||||
}
|
||||
if (redis.getMinIdle() != null) {
|
||||
config.setMinIdle(redis.getMinIdle());
|
||||
}
|
||||
config.setTestOnBorrow(true);
|
||||
config.setTestWhileIdle(true);
|
||||
|
||||
return new JedisPool(config, redis.getHost(), redis.getPort(),
|
||||
redis.getTimeout(), redis.getPassword(), redis.getDatabase());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.binarywang.spring.starter.wxjava.cp.configuration.services;
|
||||
|
||||
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiProperties;
|
||||
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServices;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 自动装配基于内存策略配置
|
||||
*
|
||||
* @author yl
|
||||
* created on 2023/10/16
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(
|
||||
prefix = WxCpTpMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "memory", matchIfMissing = true
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxCpTpInMemoryTpConfiguration extends AbstractWxCpTpConfiguration {
|
||||
private final WxCpTpMultiProperties wxCpTpMultiProperties;
|
||||
|
||||
@Bean
|
||||
public WxCpTpMultiServices wxCpMultiServices() {
|
||||
return this.wxCpMultiServices(wxCpTpMultiProperties,null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxCpTpDefaultConfigImpl wxCpTpConfigStorage(WxCpTpMultiProperties wxCpTpMultiProperties) {
|
||||
return this.configInMemory();
|
||||
}
|
||||
|
||||
private WxCpTpDefaultConfigImpl configInMemory() {
|
||||
return new WxCpTpDefaultConfigImpl();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.binarywang.spring.starter.wxjava.cp.configuration.services;
|
||||
|
||||
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiProperties;
|
||||
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServices;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpRedisTemplateConfigImpl;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpTpRedisTemplateConfigImpl;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
||||
/**
|
||||
* 自动装配基于 redisTemplate 策略配置
|
||||
*
|
||||
* @author yl
|
||||
* created on 2023/10/16
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(
|
||||
prefix = WxCpTpMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "redistemplate"
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxCpTpInRedisTemplateTpConfiguration extends AbstractWxCpTpConfiguration {
|
||||
private final WxCpTpMultiProperties wxCpTpMultiProperties;
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
@Bean
|
||||
public WxCpTpMultiServices wxCpMultiServices() {
|
||||
return this.wxCpMultiServices(wxCpTpMultiProperties,null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxCpTpDefaultConfigImpl wxCpTpConfigStorage(WxCpTpMultiProperties wxCpTpMultiProperties) {
|
||||
return this.configRedisTemplate(wxCpTpMultiProperties);
|
||||
}
|
||||
|
||||
private WxCpTpDefaultConfigImpl configRedisTemplate(WxCpTpMultiProperties wxCpTpMultiProperties) {
|
||||
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
|
||||
return new WxCpTpRedisTemplateConfigImpl(redisTemplate, wxCpTpMultiProperties.getConfigStorage().getKeyPrefix());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.binarywang.spring.starter.wxjava.cp.configuration.services;
|
||||
|
||||
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiProperties;
|
||||
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiRedisProperties;
|
||||
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServices;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
|
||||
import me.chanjar.weixin.cp.config.impl.AbstractWxCpTpInRedisConfigImpl;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpTpRedissonConfigImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.redisson.Redisson;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.config.Config;
|
||||
import org.redisson.config.TransportMode;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 自动装配基于 redisson 策略配置
|
||||
*
|
||||
* @author yl
|
||||
* created on 2023/10/16
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(
|
||||
prefix = WxCpTpMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "redisson"
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxCpTpInRedissonTpConfiguration extends AbstractWxCpTpConfiguration {
|
||||
private final WxCpTpMultiProperties wxCpTpMultiProperties;
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
@Bean
|
||||
public WxCpTpMultiServices wxCpMultiServices() {
|
||||
return this.wxCpMultiServices(wxCpTpMultiProperties,null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxCpTpDefaultConfigImpl wxCpTpConfigStorage(WxCpTpMultiProperties wxCpTpMultiProperties) {
|
||||
return this.configRedisson(wxCpTpMultiProperties);
|
||||
}
|
||||
|
||||
private WxCpTpDefaultConfigImpl configRedisson(WxCpTpMultiProperties wxCpTpMultiProperties) {
|
||||
WxCpTpMultiRedisProperties redisProperties = wxCpTpMultiProperties.getConfigStorage().getRedis();
|
||||
RedissonClient redissonClient;
|
||||
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
|
||||
redissonClient = getRedissonClient(wxCpTpMultiProperties);
|
||||
} else {
|
||||
redissonClient = applicationContext.getBean(RedissonClient.class);
|
||||
}
|
||||
return new WxCpTpRedissonConfigImpl(redissonClient, wxCpTpMultiProperties.getConfigStorage().getKeyPrefix());
|
||||
}
|
||||
|
||||
private RedissonClient getRedissonClient(WxCpTpMultiProperties wxCpTpMultiProperties) {
|
||||
WxCpTpMultiProperties.ConfigStorage storage = wxCpTpMultiProperties.getConfigStorage();
|
||||
WxCpTpMultiRedisProperties redis = storage.getRedis();
|
||||
|
||||
Config config = new Config();
|
||||
config.useSingleServer()
|
||||
.setAddress("redis://" + redis.getHost() + ":" + redis.getPort())
|
||||
.setDatabase(redis.getDatabase())
|
||||
.setPassword(redis.getPassword());
|
||||
config.setTransportMode(TransportMode.NIO);
|
||||
return Redisson.create(config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.binarywang.spring.starter.wxjava.cp.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 企业微信多企业接入相关配置属性
|
||||
*
|
||||
* @author yl
|
||||
* created on 2023/10/16
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@ConfigurationProperties(prefix = WxCpTpMultiProperties.PREFIX)
|
||||
public class WxCpTpMultiProperties implements Serializable {
|
||||
private static final long serialVersionUID = -1569510477055668503L;
|
||||
public static final String PREFIX = "wx.cp.tp";
|
||||
|
||||
private Map<String, WxCpTpSingleProperties> corps = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 配置存储策略,默认内存
|
||||
*/
|
||||
private ConfigStorage configStorage = new ConfigStorage();
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public static class ConfigStorage implements Serializable {
|
||||
private static final long serialVersionUID = 4815731027000065434L;
|
||||
/**
|
||||
* 存储类型
|
||||
*/
|
||||
private StorageType type = StorageType.memory;
|
||||
|
||||
/**
|
||||
* 指定key前缀
|
||||
*/
|
||||
private String keyPrefix = "wx:cp:tp";
|
||||
|
||||
/**
|
||||
* redis连接配置
|
||||
*/
|
||||
@NestedConfigurationProperty
|
||||
private WxCpTpMultiRedisProperties redis = new WxCpTpMultiRedisProperties();
|
||||
|
||||
/**
|
||||
* http客户端类型.
|
||||
*/
|
||||
private HttpClientType httpClientType = HttpClientType.HTTP_CLIENT;
|
||||
|
||||
/**
|
||||
* http代理主机
|
||||
*/
|
||||
private String httpProxyHost;
|
||||
|
||||
/**
|
||||
* http代理端口
|
||||
*/
|
||||
private Integer httpProxyPort;
|
||||
|
||||
/**
|
||||
* http代理用户名
|
||||
*/
|
||||
private String httpProxyUsername;
|
||||
|
||||
/**
|
||||
* http代理密码
|
||||
*/
|
||||
private String httpProxyPassword;
|
||||
|
||||
/**
|
||||
* http 请求最大重试次数
|
||||
* <pre>
|
||||
* {@link me.chanjar.weixin.cp.api.WxCpService#setMaxRetryTimes(int)}
|
||||
* {@link me.chanjar.weixin.cp.api.impl.BaseWxCpServiceImpl#setMaxRetryTimes(int)}
|
||||
* </pre>
|
||||
*/
|
||||
private int maxRetryTimes = 5;
|
||||
|
||||
/**
|
||||
* http 请求重试间隔
|
||||
* <pre>
|
||||
* {@link me.chanjar.weixin.cp.api.WxCpService#setRetrySleepMillis(int)}
|
||||
* {@link me.chanjar.weixin.cp.api.impl.BaseWxCpServiceImpl#setRetrySleepMillis(int)}
|
||||
* </pre>
|
||||
*/
|
||||
private int retrySleepMillis = 1000;
|
||||
}
|
||||
|
||||
public enum StorageType {
|
||||
/**
|
||||
* 内存
|
||||
*/
|
||||
memory,
|
||||
/**
|
||||
* jedis
|
||||
*/
|
||||
jedis,
|
||||
/**
|
||||
* redisson
|
||||
*/
|
||||
redisson,
|
||||
/**
|
||||
* redistemplate
|
||||
*/
|
||||
redistemplate
|
||||
}
|
||||
|
||||
public enum HttpClientType {
|
||||
/**
|
||||
* HttpClient
|
||||
*/
|
||||
HTTP_CLIENT,
|
||||
/**
|
||||
* OkHttp
|
||||
*/
|
||||
OK_HTTP,
|
||||
/**
|
||||
* JoddHttp
|
||||
*/
|
||||
JODD_HTTP
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.binarywang.spring.starter.wxjava.cp.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Redis配置.
|
||||
*
|
||||
* @author yl
|
||||
* created on 2023/10/16
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class WxCpTpMultiRedisProperties implements Serializable {
|
||||
private static final long serialVersionUID = -5924815351660074401L;
|
||||
|
||||
/**
|
||||
* 主机地址.
|
||||
*/
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 端口号.
|
||||
*/
|
||||
private int port = 6379;
|
||||
|
||||
/**
|
||||
* 密码.
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 超时.
|
||||
*/
|
||||
private int timeout = 2000;
|
||||
|
||||
/**
|
||||
* 数据库.
|
||||
*/
|
||||
private int database = 0;
|
||||
|
||||
private Integer maxActive;
|
||||
private Integer maxIdle;
|
||||
private Integer maxWaitMillis;
|
||||
private Integer minIdle;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.binarywang.spring.starter.wxjava.cp.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 企业微信企业相关配置属性
|
||||
*
|
||||
* @author yl
|
||||
* created on 2023/10/16
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class WxCpTpSingleProperties implements Serializable {
|
||||
private static final long serialVersionUID = -7502823825007859418L;
|
||||
/**
|
||||
* 微信企业号 corpId
|
||||
*/
|
||||
private String corpId;
|
||||
/**
|
||||
* 微信企业号 服务商 providerSecret
|
||||
*/
|
||||
private String providerSecret;
|
||||
/**
|
||||
* 微信企业号应用 token
|
||||
*/
|
||||
private String token;
|
||||
|
||||
private String encodingAESKey;
|
||||
|
||||
/**
|
||||
* 微信企业号 第三方 应用 ID
|
||||
*/
|
||||
private String suiteId;
|
||||
/**
|
||||
* 微信企业号应用
|
||||
*/
|
||||
private String suiteSecret;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.binarywang.spring.starter.wxjava.cp.service;
|
||||
|
||||
|
||||
import me.chanjar.weixin.cp.tp.service.WxCpTpService;
|
||||
|
||||
/**
|
||||
* 企业微信 {@link WxCpTpService} 所有实例存放类.
|
||||
*
|
||||
* @author yl
|
||||
* created on 2023/10/16
|
||||
*/
|
||||
public interface WxCpTpMultiServices {
|
||||
/**
|
||||
* 通过租户 Id 获取 WxCpTpService
|
||||
*
|
||||
* @param tenantId 租户 Id
|
||||
* @return WxCpTpService
|
||||
*/
|
||||
WxCpTpService getWxCpTpService(String tenantId);
|
||||
|
||||
void addWxCpTpService(String tenantId, WxCpTpService wxCpService);
|
||||
|
||||
/**
|
||||
* 根据租户 Id,从列表中移除一个 WxCpTpService 实例
|
||||
*
|
||||
* @param tenantId 租户 Id
|
||||
*/
|
||||
void removeWxCpTpService(String tenantId);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.binarywang.spring.starter.wxjava.cp.service;
|
||||
|
||||
|
||||
import me.chanjar.weixin.cp.tp.service.WxCpTpService;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 企业微信 {@link WxCpTpMultiServices} 默认实现
|
||||
*
|
||||
* @author yl
|
||||
* created on 2023/10/16
|
||||
*/
|
||||
public class WxCpTpMultiServicesImpl implements WxCpTpMultiServices {
|
||||
private final Map<String, WxCpTpService> services = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 通过租户 Id 获取 WxCpTpService
|
||||
*
|
||||
* @param tenantId 租户 Id
|
||||
* @return WxCpTpService
|
||||
*/
|
||||
@Override
|
||||
public WxCpTpService getWxCpTpService(String tenantId) {
|
||||
return this.services.get(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据租户 Id,添加一个 WxCpTpService 到列表
|
||||
*
|
||||
* @param tenantId 租户 Id
|
||||
* @param wxCpService WxCpTpService 实例
|
||||
*/
|
||||
@Override
|
||||
public void addWxCpTpService(String tenantId, WxCpTpService wxCpService) {
|
||||
this.services.put(tenantId, wxCpService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeWxCpTpService(String tenantId) {
|
||||
this.services.remove(tenantId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.binarywang.spring.starter.wxjava.cp.autoconfigure.WxCpTpMultiAutoConfiguration
|
||||
@@ -0,0 +1 @@
|
||||
com.binarywang.spring.starter.wxjava.cp.autoconfigure.WxCpTpMultiAutoConfiguration
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.binarywang.spring.starter.wxjava.miniapp.configuration;
|
||||
|
||||
import com.binarywang.spring.starter.wxjava.miniapp.configuration.services.WxMaInJedisConfiguration;
|
||||
import com.binarywang.spring.starter.wxjava.miniapp.configuration.services.WxMaInMemoryConfiguration;
|
||||
import com.binarywang.spring.starter.wxjava.miniapp.configuration.services.WxMaInRedisTemplateConfiguration;
|
||||
import com.binarywang.spring.starter.wxjava.miniapp.configuration.services.WxMaInRedissonConfiguration;
|
||||
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaMultiProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@@ -17,9 +18,10 @@ import org.springframework.context.annotation.Import;
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(WxMaMultiProperties.class)
|
||||
@Import({
|
||||
WxMaInJedisConfiguration.class,
|
||||
WxMaInMemoryConfiguration.class,
|
||||
WxMaInRedissonConfiguration.class,
|
||||
WxMaInJedisConfiguration.class,
|
||||
WxMaInMemoryConfiguration.class,
|
||||
WxMaInRedissonConfiguration.class,
|
||||
WxMaInRedisTemplateConfiguration.class
|
||||
})
|
||||
public class WxMaMultiServiceConfiguration {
|
||||
}
|
||||
|
||||
@@ -108,12 +108,12 @@ public abstract class AbstractWxMaConfiguration {
|
||||
return wxMaService;
|
||||
}
|
||||
|
||||
private void configApp(WxMaDefaultConfigImpl config, WxMaSingleProperties corpProperties) {
|
||||
String appId = corpProperties.getAppId();
|
||||
String appSecret = corpProperties.getAppSecret();
|
||||
String token = corpProperties.getToken();
|
||||
String aesKey = corpProperties.getAesKey();
|
||||
boolean useStableAccessToken = corpProperties.isUseStableAccessToken();
|
||||
private void configApp(WxMaDefaultConfigImpl config, WxMaSingleProperties properties) {
|
||||
String appId = properties.getAppId();
|
||||
String appSecret = properties.getAppSecret();
|
||||
String token = properties.getToken();
|
||||
String aesKey = properties.getAesKey();
|
||||
boolean useStableAccessToken = properties.isUseStableAccessToken();
|
||||
|
||||
config.setAppid(appId);
|
||||
config.setSecret(appSecret);
|
||||
@@ -123,7 +123,10 @@ public abstract class AbstractWxMaConfiguration {
|
||||
if (StringUtils.isNotBlank(aesKey)) {
|
||||
config.setAesKey(aesKey);
|
||||
}
|
||||
config.setMsgDataFormat(properties.getMsgDataFormat());
|
||||
config.useStableAccessToken(useStableAccessToken);
|
||||
config.setApiHostUrl(StringUtils.trimToNull(properties.getApiHostUrl()));
|
||||
config.setAccessTokenUrl(StringUtils.trimToNull(properties.getAccessTokenUrl()));
|
||||
}
|
||||
|
||||
private void configHttp(WxMaDefaultConfigImpl config, WxMaMultiProperties.ConfigStorage storage) {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.binarywang.spring.starter.wxjava.miniapp.configuration.services;
|
||||
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
|
||||
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaMultiProperties;
|
||||
import com.binarywang.spring.starter.wxjava.miniapp.service.WxMaMultiServices;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
||||
/**
|
||||
* 自动装配基于 redisTemplate 策略配置
|
||||
*
|
||||
* @author <a href="mailto:huangbing0730@gmail">hb0730</a> 2025/9/10
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = WxMaMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "redis_template")
|
||||
@RequiredArgsConstructor
|
||||
public class WxMaInRedisTemplateConfiguration extends AbstractWxMaConfiguration {
|
||||
private final WxMaMultiProperties wxMaMultiProperties;
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
@Bean
|
||||
public WxMaMultiServices wxMaMultiServices() {
|
||||
return this.wxMaMultiServices(wxMaMultiProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxMaDefaultConfigImpl wxMaConfigStorage(WxMaMultiProperties wxMaMultiProperties) {
|
||||
return this.configRedisTemplate(wxMaMultiProperties);
|
||||
}
|
||||
|
||||
private WxMaDefaultConfigImpl configRedisTemplate(WxMaMultiProperties wxMaMultiProperties) {
|
||||
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
|
||||
RedisTemplateWxRedisOps wxRedisOps = new RedisTemplateWxRedisOps(redisTemplate);
|
||||
return new WxMaRedisBetterConfigImpl(wxRedisOps, wxMaMultiProperties.getConfigStorage().getKeyPrefix());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,8 +33,25 @@ public class WxMaSingleProperties implements Serializable {
|
||||
*/
|
||||
private String aesKey;
|
||||
|
||||
/**
|
||||
* 消息格式,XML或者JSON.
|
||||
*/
|
||||
private String msgDataFormat;
|
||||
|
||||
/**
|
||||
* 是否使用稳定版 Access Token
|
||||
*/
|
||||
private boolean useStableAccessToken = false;
|
||||
|
||||
/**
|
||||
* 自定义API主机地址,用于替换默认的 https://api.weixin.qq.com
|
||||
* 例如:http://proxy.company.com:8080
|
||||
*/
|
||||
private String apiHostUrl;
|
||||
|
||||
/**
|
||||
* 自定义获取AccessToken地址,用于向自定义统一服务获取AccessToken
|
||||
* 例如:http://proxy.company.com:8080/oauth/token
|
||||
*/
|
||||
private String accessTokenUrl;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.binarywang.spring.starter.wxjava.miniapp.config.storage;
|
||||
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -10,12 +12,15 @@ import org.apache.commons.lang3.StringUtils;
|
||||
public abstract class AbstractWxMaConfigStorageConfiguration {
|
||||
|
||||
protected WxMaDefaultConfigImpl config(WxMaDefaultConfigImpl config, WxMaProperties properties) {
|
||||
WxMaProperties.ConfigStorage storage = properties.getConfigStorage();
|
||||
config.setAppid(StringUtils.trimToNull(properties.getAppid()));
|
||||
config.setSecret(StringUtils.trimToNull(properties.getSecret()));
|
||||
config.setToken(StringUtils.trimToNull(properties.getToken()));
|
||||
config.setAesKey(StringUtils.trimToNull(properties.getAesKey()));
|
||||
config.setMsgDataFormat(StringUtils.trimToNull(properties.getMsgDataFormat()));
|
||||
config.useStableAccessToken(properties.isUseStableAccessToken());
|
||||
config.setApiHostUrl(StringUtils.trimToNull(properties.getApiHostUrl()));
|
||||
config.setAccessTokenUrl(StringUtils.trimToNull(properties.getAccessTokenUrl()));
|
||||
|
||||
WxMaProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
|
||||
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
|
||||
@@ -25,6 +30,19 @@ public abstract class AbstractWxMaConfigStorageConfiguration {
|
||||
config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
|
||||
}
|
||||
|
||||
// 设置自定义的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);
|
||||
}
|
||||
|
||||
int maxRetryTimes = configStorageProperties.getMaxRetryTimes();
|
||||
if (configStorageProperties.getMaxRetryTimes() < 0) {
|
||||
maxRetryTimes = 0;
|
||||
|
||||
@@ -49,6 +49,18 @@ public class WxMaProperties {
|
||||
*/
|
||||
private boolean useStableAccessToken = false;
|
||||
|
||||
/**
|
||||
* 自定义API主机地址,用于替换默认的 https://api.weixin.qq.com
|
||||
* 例如:http://proxy.company.com:8080
|
||||
*/
|
||||
private String apiHostUrl;
|
||||
|
||||
/**
|
||||
* 自定义获取AccessToken地址,用于向自定义统一服务获取AccessToken
|
||||
* 例如:http://proxy.company.com:8080/oauth/token
|
||||
*/
|
||||
private String accessTokenUrl;
|
||||
|
||||
/**
|
||||
* 存储策略
|
||||
*/
|
||||
@@ -112,6 +124,21 @@ public class WxMaProperties {
|
||||
* </pre>
|
||||
*/
|
||||
private int maxRetryTimes = 5;
|
||||
|
||||
/**
|
||||
* 连接超时时间,单位毫秒
|
||||
*/
|
||||
private int connectionTimeout = 5000;
|
||||
|
||||
/**
|
||||
* 读数据超时时间,即socketTimeout,单位毫秒
|
||||
*/
|
||||
private int soTimeout = 5000;
|
||||
|
||||
/**
|
||||
* 从连接池获取链接的超时时间,单位毫秒
|
||||
*/
|
||||
private int connectionRequestTimeout = 5000;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -7,10 +7,7 @@ import com.binarywang.spring.starter.wxjava.mp.service.WxMpMultiServicesImpl;
|
||||
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;
|
||||
@@ -91,6 +88,9 @@ public abstract class AbstractWxMpConfiguration {
|
||||
case HTTP_CLIENT:
|
||||
wxMpService = new WxMpServiceHttpClientImpl();
|
||||
break;
|
||||
case HTTP_COMPONENTS:
|
||||
wxMpService = new WxMpServiceHttpComponentsImpl();
|
||||
break;
|
||||
default:
|
||||
wxMpService = new WxMpServiceImpl();
|
||||
break;
|
||||
|
||||
@@ -142,6 +142,10 @@ public class WxMpMultiProperties implements Serializable {
|
||||
* HttpClient
|
||||
*/
|
||||
HTTP_CLIENT,
|
||||
/**
|
||||
* HttpComponents
|
||||
*/
|
||||
HTTP_COMPONENTS,
|
||||
/**
|
||||
* OkHttp
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
|
||||
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
|
||||
import me.chanjar.weixin.common.redis.WxRedisOps;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.config.WxMpHostConfig;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
||||
@@ -122,6 +124,19 @@ public class WxMpStorageAutoConfiguration {
|
||||
config.setSecret(properties.getSecret());
|
||||
config.setToken(properties.getToken());
|
||||
config.setAesKey(properties.getAesKey());
|
||||
WxMpProperties.ConfigStorage storage = properties.getConfigStorage();
|
||||
// 设置自定义的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);
|
||||
}
|
||||
config.setUseStableAccessToken(wxMpProperties.isUseStableAccessToken());
|
||||
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
|
||||
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
|
||||
|
||||
@@ -102,6 +102,21 @@ public class WxMpProperties {
|
||||
*/
|
||||
private String httpProxyPassword;
|
||||
|
||||
/**
|
||||
* 连接超时时间,单位毫秒
|
||||
*/
|
||||
private int connectionTimeout = 5000;
|
||||
|
||||
/**
|
||||
* 读数据超时时间,即socketTimeout,单位毫秒
|
||||
*/
|
||||
private int soTimeout = 5000;
|
||||
|
||||
/**
|
||||
* 从连接池获取链接的超时时间,单位毫秒
|
||||
*/
|
||||
private int connectionRequestTimeout = 5000;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.binarywang.spring.starter.wxjava.open.config.storage;
|
||||
|
||||
import com.binarywang.spring.starter.wxjava.open.properties.WxOpenProperties;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* @author yl
|
||||
@@ -28,6 +31,24 @@ public abstract class AbstractWxOpenConfigStorageConfiguration {
|
||||
}
|
||||
config.setRetrySleepMillis(retrySleepMillis);
|
||||
config.setMaxRetryTimes(maxRetryTimes);
|
||||
|
||||
// 设置URL配置
|
||||
config.setApiHostUrl(StringUtils.trimToNull(properties.getApiHostUrl()));
|
||||
config.setAccessTokenUrl(StringUtils.trimToNull(properties.getAccessTokenUrl()));
|
||||
|
||||
// 设置自定义的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);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,18 @@ public class WxOpenProperties {
|
||||
*/
|
||||
private String aesKey;
|
||||
|
||||
/**
|
||||
* 自定义API主机地址,用于替换默认的 https://api.weixin.qq.com
|
||||
* 例如:http://proxy.company.com:8080
|
||||
*/
|
||||
private String apiHostUrl;
|
||||
|
||||
/**
|
||||
* 自定义获取AccessToken地址,用于向自定义统一服务获取AccessToken
|
||||
* 例如:http://proxy.company.com:8080/oauth/token
|
||||
*/
|
||||
private String accessTokenUrl;
|
||||
|
||||
/**
|
||||
* 存储策略.
|
||||
*/
|
||||
@@ -108,6 +120,21 @@ public class WxOpenProperties {
|
||||
*/
|
||||
private int maxRetryTimes = 5;
|
||||
|
||||
/**
|
||||
* 连接超时时间,单位毫秒
|
||||
*/
|
||||
private int connectionTimeout = 5000;
|
||||
|
||||
/**
|
||||
* 读数据超时时间,即socketTimeout,单位毫秒
|
||||
*/
|
||||
private int soTimeout = 5000;
|
||||
|
||||
/**
|
||||
* 从连接池获取链接的超时时间,单位毫秒
|
||||
*/
|
||||
private int connectionRequestTimeout = 5000;
|
||||
|
||||
}
|
||||
|
||||
public enum StorageType {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -50,15 +50,18 @@ public class WxPayAutoConfiguration {
|
||||
payConfig.setSubMchId(StringUtils.trimToNull(this.properties.getSubMchId()));
|
||||
payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
|
||||
payConfig.setUseSandboxEnv(this.properties.isUseSandboxEnv());
|
||||
payConfig.setNotifyUrl(StringUtils.trimToNull(this.properties.getNotifyUrl()));
|
||||
//以下是apiv3以及支付分相关
|
||||
payConfig.setServiceId(StringUtils.trimToNull(this.properties.getServiceId()));
|
||||
payConfig.setPayScoreNotifyUrl(StringUtils.trimToNull(this.properties.getPayScoreNotifyUrl()));
|
||||
payConfig.setPayScorePermissionNotifyUrl(StringUtils.trimToNull(this.properties.getPayScorePermissionNotifyUrl()));
|
||||
payConfig.setPrivateKeyPath(StringUtils.trimToNull(this.properties.getPrivateKeyPath()));
|
||||
payConfig.setPrivateCertPath(StringUtils.trimToNull(this.properties.getPrivateCertPath()));
|
||||
payConfig.setCertSerialNo(StringUtils.trimToNull(this.properties.getCertSerialNo()));
|
||||
payConfig.setApiV3Key(StringUtils.trimToNull(this.properties.getApiv3Key()));
|
||||
payConfig.setPublicKeyId(StringUtils.trimToNull(this.properties.getPublicKeyId()));
|
||||
payConfig.setPublicKeyPath(StringUtils.trimToNull(this.properties.getPublicKeyPath()));
|
||||
payConfig.setApiHostUrl(StringUtils.trimToNull(this.properties.getApiHostUrl()));
|
||||
|
||||
wxPayService.setConfig(payConfig);
|
||||
return wxPayService;
|
||||
|
||||
@@ -59,11 +59,21 @@ public class WxPayProperties {
|
||||
*/
|
||||
private String apiv3Key;
|
||||
|
||||
/**
|
||||
* 微信支付异步回调地址,通知url必须为直接可访问的url,不能携带参数
|
||||
*/
|
||||
private String notifyUrl;
|
||||
|
||||
/**
|
||||
* 微信支付分回调地址
|
||||
*/
|
||||
private String payScoreNotifyUrl;
|
||||
|
||||
/**
|
||||
* 微信支付分授权回调地址
|
||||
*/
|
||||
private String payScorePermissionNotifyUrl;
|
||||
|
||||
/**
|
||||
* apiv3 商户apiclient_key.pem
|
||||
*/
|
||||
@@ -90,4 +100,10 @@ public class WxPayProperties {
|
||||
*/
|
||||
private boolean useSandboxEnv;
|
||||
|
||||
/**
|
||||
* 自定义API主机地址,用于替换默认的 https://api.mch.weixin.qq.com
|
||||
* 例如:http://proxy.company.com:8080
|
||||
*/
|
||||
private String apiHostUrl;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-graal</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-java-channel</artifactId>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
@@ -56,7 +56,7 @@ public class WxChannelBasicServiceImpl implements WxChannelBasicService {
|
||||
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();
|
||||
}
|
||||
@@ -64,19 +64,19 @@ public class WxChannelBasicServiceImpl implements WxChannelBasicService {
|
||||
@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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package me.chanjar.weixin.channel.bean.after;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import me.chanjar.weixin.channel.bean.base.AddressInfo;
|
||||
|
||||
/**
|
||||
* 换货类型的发货物流信息
|
||||
*
|
||||
* @author <a href="https://github.com/lixize">Zeyes</a>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class AfterSaleExchangeDeliveryInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3039216368034112038L;
|
||||
|
||||
/** 快递单号 */
|
||||
@JsonProperty("waybill_id")
|
||||
private String waybillId;
|
||||
|
||||
/** 物流公司id */
|
||||
@JsonProperty("delivery_id")
|
||||
private String deliveryId;
|
||||
|
||||
/** 物流公司名称 */
|
||||
@JsonProperty("delivery_name")
|
||||
private String deliveryName;
|
||||
|
||||
/** 地址信息 */
|
||||
@JsonProperty("address_info")
|
||||
private AddressInfo addressInfo;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package me.chanjar.weixin.channel.bean.after;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 换货商品信息
|
||||
*
|
||||
* @author <a href="https://github.com/lixize">Zeyes</a>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class AfterSaleExchangeProductInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1341436607011117854L;
|
||||
|
||||
/** 商品spuid */
|
||||
@JsonProperty("product_id")
|
||||
private String productId;
|
||||
|
||||
/** 旧商品skuid */
|
||||
@JsonProperty("old_sku_id")
|
||||
private String oldSkuId;
|
||||
|
||||
/** 新商品skuid */
|
||||
@JsonProperty("new_sku_id")
|
||||
private String newSkuId;
|
||||
|
||||
/** 数量 */
|
||||
@JsonProperty("product_cnt")
|
||||
private String productCnt;
|
||||
}
|
||||
@@ -86,4 +86,16 @@ public class AfterSaleInfo implements Serializable {
|
||||
/** 仅在待商家审核退款退货申请或收货期间返回,表示操作剩余时间(秒数)*/
|
||||
@JsonProperty("deadline")
|
||||
private Long deadline;
|
||||
|
||||
/** 售后换货商品信息 */
|
||||
@JsonProperty("exchange_product_info")
|
||||
private AfterSaleExchangeProductInfo exchangeProductInfo;
|
||||
|
||||
/** 售后换货物流信息 */
|
||||
@JsonProperty("exchange_delivery_info")
|
||||
private AfterSaleExchangeDeliveryInfo exchangeDeliveryInfo;
|
||||
|
||||
/** 售后换货虚拟号码信息 */
|
||||
@JsonProperty("virtual_tel_num_info")
|
||||
private AfterSaleVirtualNumberInfo virtualTelNumInfo;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package me.chanjar.weixin.channel.bean.after;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 虚拟号码信息
|
||||
*
|
||||
* @author <a href="https://github.com/lixize">Zeyes</a>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class AfterSaleVirtualNumberInfo implements Serializable {
|
||||
private static final long serialVersionUID = -5756618937333859985L;
|
||||
|
||||
/** 虚拟号码 */
|
||||
@JsonProperty("virtual_tel_number")
|
||||
private String virtualTelNumber;
|
||||
|
||||
/** 虚拟号码过期时间 */
|
||||
@JsonProperty("virtual_tel_expire_time")
|
||||
private Long virtualTelExpireTime;
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package me.chanjar.weixin.channel.executor;
|
||||
|
||||
import me.chanjar.weixin.channel.bean.image.ChannelImageResponse;
|
||||
import me.chanjar.weixin.channel.util.JsonUtils;
|
||||
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.InputStreamResponseHandler;
|
||||
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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.HttpGet;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ApacheHttpChannelMediaDownloadRequestExecutor extends ChannelMediaDownloadRequestExecutor<CloseableHttpClient, HttpHost> {
|
||||
|
||||
public ApacheHttpChannelMediaDownloadRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp, File tmpDirFile) {
|
||||
super(requestHttp, tmpDirFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelImageResponse execute(String uri, String data, WxType wxType) throws WxErrorException, IOException {
|
||||
if (data != null) {
|
||||
if (uri.indexOf('?') == -1) {
|
||||
uri += '?';
|
||||
}
|
||||
uri += uri.endsWith("?") ? data : '&' + data;
|
||||
}
|
||||
|
||||
HttpGet httpGet = new HttpGet(uri);
|
||||
if (requestHttp.getRequestHttpProxy() != null) {
|
||||
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
|
||||
httpGet.setConfig(config);
|
||||
}
|
||||
|
||||
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpGet);
|
||||
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response)) {
|
||||
Header[] contentTypeHeader = response.getHeaders("Content-Type");
|
||||
String contentType = null;
|
||||
if (contentTypeHeader != null && contentTypeHeader.length > 0) {
|
||||
contentType = contentTypeHeader[0].getValue();
|
||||
if (contentType.startsWith(ContentType.APPLICATION_JSON.getMimeType())) {
|
||||
// application/json; encoding=utf-8 下载媒体文件出错
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
return JsonUtils.decode(responseContent, ChannelImageResponse.class);
|
||||
}
|
||||
}
|
||||
|
||||
String fileName = this.getFileName(response);
|
||||
if (StringUtils.isBlank(fileName)) {
|
||||
fileName = String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
String baseName = FilenameUtils.getBaseName(fileName);
|
||||
if (StringUtils.isBlank(fileName) || baseName.length() < 3) {
|
||||
baseName = String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
String extension = FilenameUtils.getExtension(fileName);
|
||||
if (StringUtils.isBlank(extension)) {
|
||||
extension = "unknown";
|
||||
}
|
||||
File file = createTmpFile(inputStream, baseName, extension, tmpDirFile);
|
||||
return new ChannelImageResponse(file, contentType);
|
||||
}
|
||||
}
|
||||
|
||||
private String getFileName(CloseableHttpResponse response) throws WxErrorException {
|
||||
Header[] contentDispositionHeader = response.getHeaders("Content-disposition");
|
||||
if (contentDispositionHeader == null || contentDispositionHeader.length == 0) {
|
||||
return createDefaultFileName();
|
||||
}
|
||||
return this.extractFileNameFromContentString(contentDispositionHeader[0].getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String uri, String data, ResponseHandler<ChannelImageResponse> handler, WxType wxType)
|
||||
throws WxErrorException, IOException {
|
||||
handler.handle(this.execute(uri, data, wxType));
|
||||
}
|
||||
}
|
||||
@@ -1,66 +1,34 @@
|
||||
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.RequestExecutor;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 视频号小店 图片上传接口 请求的参数是File, 返回的结果是String
|
||||
*
|
||||
* @author <a href="https://github.com/lixize">Zeyes</a>
|
||||
*/
|
||||
public class ChannelFileUploadRequestExecutor implements RequestExecutor<String, File> {
|
||||
public abstract class ChannelFileUploadRequestExecutor<H, P> implements RequestExecutor<String, File> {
|
||||
|
||||
protected RequestHttp<CloseableHttpClient, HttpHost> requestHttp;
|
||||
protected RequestHttp<H, P> requestHttp;
|
||||
|
||||
public ChannelFileUploadRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp) {
|
||||
public ChannelFileUploadRequestExecutor(RequestHttp<H, P> requestHttp) {
|
||||
this.requestHttp = 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));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static RequestExecutor<String, File> create(RequestHttp<?, ?> requestHttp) throws WxErrorException {
|
||||
public static RequestExecutor<String, File> create(RequestHttp<?, ?> requestHttp) {
|
||||
switch (requestHttp.getRequestType()) {
|
||||
case APACHE_HTTP:
|
||||
return new ChannelFileUploadRequestExecutor((RequestHttp<CloseableHttpClient, HttpHost>) requestHttp);
|
||||
return new ApacheHttpChannelFileUploadRequestExecutor(
|
||||
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp);
|
||||
case HTTP_COMPONENTS:
|
||||
return new HttpComponentsChannelFileUploadRequestExecutor(
|
||||
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp);
|
||||
default:
|
||||
throw new WxErrorException("不支持的http框架");
|
||||
throw new IllegalArgumentException("不支持的http执行器类型:" + requestHttp.getRequestType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,9 @@
|
||||
package me.chanjar.weixin.channel.executor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.channel.bean.image.ChannelImageResponse;
|
||||
import me.chanjar.weixin.channel.util.JsonUtils;
|
||||
import me.chanjar.weixin.common.enums.WxType;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.RequestHttp;
|
||||
import me.chanjar.weixin.common.util.http.ResponseHandler;
|
||||
import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler;
|
||||
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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.HttpGet;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -36,77 +20,29 @@ import static org.apache.commons.io.FileUtils.openOutputStream;
|
||||
*
|
||||
* @author <a href="https://github.com/lixize">Zeyes</a>
|
||||
*/
|
||||
@Slf4j
|
||||
public class ChannelMediaDownloadRequestExecutor implements RequestExecutor<ChannelImageResponse, String> {
|
||||
public abstract class ChannelMediaDownloadRequestExecutor<H, P> implements RequestExecutor<ChannelImageResponse, String> {
|
||||
|
||||
protected RequestHttp<CloseableHttpClient, HttpHost> requestHttp;
|
||||
protected RequestHttp<H, P> requestHttp;
|
||||
protected File tmpDirFile;
|
||||
|
||||
private static final Pattern PATTERN = Pattern.compile(".*filename=\"(.*)\"");
|
||||
|
||||
public ChannelMediaDownloadRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp, File tmpDirFile) {
|
||||
public ChannelMediaDownloadRequestExecutor(RequestHttp<H, P> requestHttp, File tmpDirFile) {
|
||||
this.requestHttp = requestHttp;
|
||||
this.tmpDirFile = tmpDirFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelImageResponse execute(String uri, String data, WxType wxType) throws WxErrorException, IOException {
|
||||
if (data != null) {
|
||||
if (uri.indexOf('?') == -1) {
|
||||
uri += '?';
|
||||
}
|
||||
uri += uri.endsWith("?") ? data : '&' + data;
|
||||
}
|
||||
|
||||
HttpGet httpGet = new HttpGet(uri);
|
||||
if (requestHttp.getRequestHttpProxy() != null) {
|
||||
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
|
||||
httpGet.setConfig(config);
|
||||
}
|
||||
|
||||
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpGet);
|
||||
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response)) {
|
||||
Header[] contentTypeHeader = response.getHeaders("Content-Type");
|
||||
String contentType = null;
|
||||
if (contentTypeHeader != null && contentTypeHeader.length > 0) {
|
||||
contentType = contentTypeHeader[0].getValue();
|
||||
if (contentType.startsWith(ContentType.APPLICATION_JSON.getMimeType())) {
|
||||
// application/json; encoding=utf-8 下载媒体文件出错
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
return JsonUtils.decode(responseContent, ChannelImageResponse.class);
|
||||
}
|
||||
}
|
||||
|
||||
String fileName = this.getFileName(response);
|
||||
if (StringUtils.isBlank(fileName)) {
|
||||
fileName = String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
String baseName = FilenameUtils.getBaseName(fileName);
|
||||
if (StringUtils.isBlank(fileName) || baseName.length() < 3) {
|
||||
baseName = String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
String extension = FilenameUtils.getExtension(fileName);
|
||||
if (StringUtils.isBlank(extension)) {
|
||||
extension = "unknown";
|
||||
}
|
||||
File file = createTmpFile(inputStream, baseName, extension, tmpDirFile);
|
||||
return new ChannelImageResponse(file, contentType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String uri, String data, ResponseHandler<ChannelImageResponse> handler, WxType wxType)
|
||||
throws WxErrorException, IOException {
|
||||
handler.handle(this.execute(uri, data, wxType));
|
||||
}
|
||||
|
||||
public static RequestExecutor<ChannelImageResponse, String> create(RequestHttp<?, ?> requestHttp, File tmpDirFile) throws WxErrorException {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static RequestExecutor<ChannelImageResponse, String> create(RequestHttp<?, ?> requestHttp, File tmpDirFile) {
|
||||
switch (requestHttp.getRequestType()) {
|
||||
case APACHE_HTTP:
|
||||
return new ChannelMediaDownloadRequestExecutor((RequestHttp<CloseableHttpClient, HttpHost>) requestHttp, tmpDirFile);
|
||||
return new ApacheHttpChannelMediaDownloadRequestExecutor(
|
||||
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp, tmpDirFile);
|
||||
case HTTP_COMPONENTS:
|
||||
return new HttpComponentsChannelMediaDownloadRequestExecutor(
|
||||
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp, tmpDirFile);
|
||||
default:
|
||||
throw new WxErrorException("不支持的http框架");
|
||||
throw new IllegalArgumentException("不支持的http执行器类型:" + requestHttp.getRequestType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,19 +64,11 @@ public class ChannelMediaDownloadRequestExecutor implements RequestExecutor<Chan
|
||||
return resultFile;
|
||||
}
|
||||
|
||||
private String getFileName(CloseableHttpResponse response) throws WxErrorException {
|
||||
Header[] contentDispositionHeader = response.getHeaders("Content-disposition");
|
||||
if (contentDispositionHeader == null || contentDispositionHeader.length == 0) {
|
||||
return createDefaultFileName();
|
||||
}
|
||||
return this.extractFileNameFromContentString(contentDispositionHeader[0].getValue());
|
||||
}
|
||||
|
||||
private String createDefaultFileName() {
|
||||
protected String createDefaultFileName() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
private String extractFileNameFromContentString(String content) throws WxErrorException {
|
||||
protected String extractFileNameFromContentString(String content) {
|
||||
if (content == null || content.isEmpty()) {
|
||||
return createDefaultFileName();
|
||||
}
|
||||
|
||||
@@ -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.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;
|
||||
|
||||
public class HttpComponentsChannelFileUploadRequestExecutor extends ChannelFileUploadRequestExecutor<CloseableHttpClient, HttpHost> {
|
||||
public HttpComponentsChannelFileUploadRequestExecutor(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.EXTENDED)
|
||||
.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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package me.chanjar.weixin.channel.executor;
|
||||
|
||||
import me.chanjar.weixin.channel.bean.image.ChannelImageResponse;
|
||||
import me.chanjar.weixin.channel.util.JsonUtils;
|
||||
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.hc.InputStreamResponseHandler;
|
||||
import me.chanjar.weixin.common.util.http.hc.Utf8ResponseHandler;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.hc.client5.http.ClientProtocolException;
|
||||
import org.apache.hc.client5.http.classic.methods.HttpGet;
|
||||
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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class HttpComponentsChannelMediaDownloadRequestExecutor extends ChannelMediaDownloadRequestExecutor<CloseableHttpClient, HttpHost> {
|
||||
|
||||
public HttpComponentsChannelMediaDownloadRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp, File tmpDirFile) {
|
||||
super(requestHttp, tmpDirFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelImageResponse execute(String uri, String data, WxType wxType) throws WxErrorException, IOException {
|
||||
if (data != null) {
|
||||
if (uri.indexOf('?') == -1) {
|
||||
uri += '?';
|
||||
}
|
||||
uri += uri.endsWith("?") ? data : '&' + data;
|
||||
}
|
||||
|
||||
HttpGet httpGet = new HttpGet(uri);
|
||||
if (requestHttp.getRequestHttpProxy() != null) {
|
||||
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
|
||||
httpGet.setConfig(config);
|
||||
}
|
||||
|
||||
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpGet);
|
||||
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response)) {
|
||||
Header[] contentTypeHeader = response.getHeaders("Content-Type");
|
||||
String contentType = null;
|
||||
if (contentTypeHeader != null && contentTypeHeader.length > 0) {
|
||||
contentType = contentTypeHeader[0].getValue();
|
||||
if (contentType.startsWith(ContentType.APPLICATION_JSON.getMimeType())) {
|
||||
// application/json; encoding=utf-8 下载媒体文件出错
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
return JsonUtils.decode(responseContent, ChannelImageResponse.class);
|
||||
}
|
||||
}
|
||||
|
||||
String fileName = this.getFileName(response);
|
||||
if (StringUtils.isBlank(fileName)) {
|
||||
fileName = String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
String baseName = FilenameUtils.getBaseName(fileName);
|
||||
if (StringUtils.isBlank(fileName) || baseName.length() < 3) {
|
||||
baseName = String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
String extension = FilenameUtils.getExtension(fileName);
|
||||
if (StringUtils.isBlank(extension)) {
|
||||
extension = "unknown";
|
||||
}
|
||||
File file = createTmpFile(inputStream, baseName, extension, tmpDirFile);
|
||||
return new ChannelImageResponse(file, contentType);
|
||||
} catch (HttpException httpException) {
|
||||
throw new ClientProtocolException(httpException.getMessage(), httpException);
|
||||
}
|
||||
}
|
||||
|
||||
private String getFileName(CloseableHttpResponse response) throws WxErrorException {
|
||||
Header[] contentDispositionHeader = response.getHeaders("Content-disposition");
|
||||
if (contentDispositionHeader == null || contentDispositionHeader.length == 0) {
|
||||
return createDefaultFileName();
|
||||
}
|
||||
return this.extractFileNameFromContentString(contentDispositionHeader[0].getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String uri, String data, ResponseHandler<ChannelImageResponse> handler, WxType wxType)
|
||||
throws WxErrorException, IOException {
|
||||
handler.handle(this.execute(uri, data, wxType));
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>4.7.6.B</version>
|
||||
<version>4.7.8.B</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-java-common</artifactId>
|
||||
|
||||
@@ -302,6 +302,7 @@ public class WxConsts {
|
||||
public static final String VIEW = "VIEW";
|
||||
public static final String MASS_SEND_JOB_FINISH = "MASSSENDJOBFINISH";
|
||||
|
||||
public static final String SYS_APPROVAL_CHANGE = "sys_approval_change";
|
||||
/**
|
||||
* 扫码推事件的事件推送
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,7 @@ public class WxMinishopImageUploadCustomizeResult implements Serializable {
|
||||
private WxMinishopPicFileCustomizeResult imgInfo;
|
||||
|
||||
public static WxMinishopImageUploadCustomizeResult fromJson(String json) {
|
||||
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
|
||||
JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject();
|
||||
WxMinishopImageUploadCustomizeResult result = new WxMinishopImageUploadCustomizeResult();
|
||||
result.setErrcode(jsonObject.get(WxConsts.ERR_CODE).getAsNumber().toString());
|
||||
if (result.getErrcode().equals("0")) {
|
||||
|
||||
@@ -21,7 +21,7 @@ public class WxMinishopImageUploadResult implements Serializable {
|
||||
|
||||
|
||||
public static WxMinishopImageUploadResult fromJson(String json) {
|
||||
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
|
||||
JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject();
|
||||
WxMinishopImageUploadResult result = new WxMinishopImageUploadResult();
|
||||
result.setErrcode(jsonObject.get(WxConsts.ERR_CODE).getAsNumber().toString());
|
||||
if (result.getErrcode().equals("0")) {
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package me.chanjar.weixin.common.executor;
|
||||
|
||||
import jodd.http.HttpConnectionProvider;
|
||||
import jodd.http.ProxyInfo;
|
||||
import me.chanjar.weixin.common.bean.CommonUploadParam;
|
||||
import me.chanjar.weixin.common.enums.WxType;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
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 java.io.IOException;
|
||||
|
||||
@@ -34,15 +38,19 @@ public abstract class CommonUploadRequestExecutor<H, P> implements RequestExecut
|
||||
* @param requestHttp 请求信息
|
||||
* @return 执行器
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static RequestExecutor<String, CommonUploadParam> create(RequestHttp requestHttp) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static RequestExecutor<String, CommonUploadParam> create(RequestHttp<?, ?> requestHttp) {
|
||||
switch (requestHttp.getRequestType()) {
|
||||
case APACHE_HTTP:
|
||||
return new CommonUploadRequestExecutorApacheImpl(requestHttp);
|
||||
return new CommonUploadRequestExecutorApacheImpl(
|
||||
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp);
|
||||
case JODD_HTTP:
|
||||
return new CommonUploadRequestExecutorJoddHttpImpl(requestHttp);
|
||||
return new CommonUploadRequestExecutorJoddHttpImpl((RequestHttp<HttpConnectionProvider, ProxyInfo>) requestHttp);
|
||||
case OK_HTTP:
|
||||
return new CommonUploadRequestExecutorOkHttpImpl(requestHttp);
|
||||
return new CommonUploadRequestExecutorOkHttpImpl((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp);
|
||||
case HTTP_COMPONENTS:
|
||||
return new CommonUploadRequestExecutorHttpComponentsImpl(
|
||||
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp);
|
||||
default:
|
||||
throw new IllegalArgumentException("不支持的http执行器类型:" + requestHttp.getRequestType());
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ import java.io.InputStream;
|
||||
* @author <a href="https://www.sacoc.cn">广州跨界</a>
|
||||
* created on 2024/01/11
|
||||
*/
|
||||
public class CommonUploadRequestExecutorApacheImpl
|
||||
extends CommonUploadRequestExecutor<CloseableHttpClient, HttpHost> {
|
||||
public class CommonUploadRequestExecutorApacheImpl extends CommonUploadRequestExecutor<CloseableHttpClient, HttpHost> {
|
||||
|
||||
public CommonUploadRequestExecutorApacheImpl(RequestHttp<CloseableHttpClient, HttpHost> requestHttp) {
|
||||
super(requestHttp);
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package me.chanjar.weixin.common.executor;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.chanjar.weixin.common.bean.CommonUploadData;
|
||||
import me.chanjar.weixin.common.bean.CommonUploadParam;
|
||||
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.commons.lang3.StringUtils;
|
||||
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.InputStreamBody;
|
||||
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import org.apache.hc.core5.http.ContentType;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Apache HttpComponents 通用文件上传器
|
||||
*/
|
||||
public class CommonUploadRequestExecutorHttpComponentsImpl extends CommonUploadRequestExecutor<CloseableHttpClient, HttpHost> {
|
||||
|
||||
public CommonUploadRequestExecutorHttpComponentsImpl(RequestHttp<CloseableHttpClient, HttpHost> requestHttp) {
|
||||
super(requestHttp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(String uri, CommonUploadParam param, 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 (param != null) {
|
||||
CommonUploadData data = param.getData();
|
||||
InnerStreamBody part = new InnerStreamBody(data.getInputStream(), ContentType.DEFAULT_BINARY, data.getFileName(), data.getLength());
|
||||
HttpEntity entity = MultipartEntityBuilder
|
||||
.create()
|
||||
.addPart(param.getName(), part)
|
||||
.setMode(HttpMultipartMode.EXTENDED)
|
||||
.build();
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
String responseContent = requestHttp.getRequestHttpClient().execute(httpPost, Utf8ResponseHandler.INSTANCE);
|
||||
if (StringUtils.isEmpty(responseContent)) {
|
||||
throw new WxErrorException(String.format("上传失败,服务器响应空 url:%s param:%s", uri, param));
|
||||
}
|
||||
WxError error = WxError.fromJson(responseContent, wxType);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
return responseContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部流 请求体
|
||||
*/
|
||||
@Getter
|
||||
public static class InnerStreamBody extends InputStreamBody {
|
||||
|
||||
private final long contentLength;
|
||||
|
||||
public InnerStreamBody(final InputStream in, final ContentType contentType, final String filename, long contentLength) {
|
||||
super(in, contentType, filename);
|
||||
this.contentLength = contentLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package me.chanjar.weixin.common.requestexecuter.ocr;
|
||||
|
||||
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;
|
||||
|
||||
public class OcrDiscernHttpComponentsRequestExecutor extends OcrDiscernRequestExecutor<CloseableHttpClient, HttpHost> {
|
||||
public OcrDiscernHttpComponentsRequestExecutor(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("file", 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 responseContent;
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,13 @@ public abstract class OcrDiscernRequestExecutor<H, P> implements RequestExecutor
|
||||
public static RequestExecutor<String, File> create(RequestHttp<?, ?> requestHttp) {
|
||||
switch (requestHttp.getRequestType()) {
|
||||
case APACHE_HTTP:
|
||||
return new OcrDiscernApacheHttpRequestExecutor((RequestHttp<CloseableHttpClient, HttpHost>) requestHttp);
|
||||
return new OcrDiscernApacheHttpRequestExecutor(
|
||||
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp);
|
||||
case HTTP_COMPONENTS:
|
||||
return new OcrDiscernHttpComponentsRequestExecutor(
|
||||
(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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.chanjar.weixin.common.util;
|
||||
|
||||
import org.apache.commons.lang3.RegExUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -17,7 +18,7 @@ public class DataUtils {
|
||||
public static <E> E handleDataWithSecret(E data) {
|
||||
E dataForLog = data;
|
||||
if(data instanceof String && StringUtils.contains((String)data, "&secret=")){
|
||||
dataForLog = (E) StringUtils.replaceAll((String)data,"&secret=\\w+&","&secret=******&");
|
||||
dataForLog = (E) RegExUtils.replaceAll((String)data,"&secret=\\w+&","&secret=******&");
|
||||
}
|
||||
return dataForLog;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
package me.chanjar.weixin.common.util.http;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import jodd.http.HttpConnectionProvider;
|
||||
import jodd.http.ProxyInfo;
|
||||
import me.chanjar.weixin.common.enums.WxType;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheMediaDownloadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.hc.HttpComponentsMediaDownloadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.jodd.JoddHttpMediaDownloadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.okhttp.OkHttpMediaDownloadRequestExecutor;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 下载媒体文件请求执行器.
|
||||
@@ -40,13 +39,17 @@ public abstract class BaseMediaDownloadRequestExecutor<H, P> implements RequestE
|
||||
public static RequestExecutor<File, String> create(RequestHttp<?, ?> requestHttp, File tmpDirFile) {
|
||||
switch (requestHttp.getRequestType()) {
|
||||
case APACHE_HTTP:
|
||||
return new ApacheMediaDownloadRequestExecutor((RequestHttp<CloseableHttpClient, HttpHost>) requestHttp, tmpDirFile);
|
||||
return new ApacheMediaDownloadRequestExecutor(
|
||||
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp, tmpDirFile);
|
||||
case JODD_HTTP:
|
||||
return new JoddHttpMediaDownloadRequestExecutor((RequestHttp<HttpConnectionProvider, ProxyInfo>) requestHttp, tmpDirFile);
|
||||
case OK_HTTP:
|
||||
return new OkHttpMediaDownloadRequestExecutor((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp, tmpDirFile);
|
||||
case HTTP_COMPONENTS:
|
||||
return new HttpComponentsMediaDownloadRequestExecutor(
|
||||
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp, tmpDirFile);
|
||||
default:
|
||||
return null;
|
||||
throw new IllegalArgumentException("不支持的http执行器类型:" + requestHttp.getRequestType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ public enum HttpClientType {
|
||||
*/
|
||||
JODD_HTTP,
|
||||
/**
|
||||
* apache httpclient.
|
||||
* apache httpclient 4.x.
|
||||
*/
|
||||
APACHE_HTTP,
|
||||
/**
|
||||
@@ -17,7 +17,7 @@ public enum HttpClientType {
|
||||
*/
|
||||
OK_HTTP,
|
||||
/**
|
||||
* apache httpclient5.
|
||||
* apache httpclient 5.x.
|
||||
*/
|
||||
APACHE_HTTP_5
|
||||
HTTP_COMPONENTS
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package me.chanjar.weixin.common.util.http;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpResponseProxy;
|
||||
import me.chanjar.weixin.common.util.http.hc5.ApacheHttpClient5ResponseProxy;
|
||||
import me.chanjar.weixin.common.util.http.hc.HttpComponentsResponseProxy;
|
||||
import me.chanjar.weixin.common.util.http.jodd.JoddHttpResponseProxy;
|
||||
import me.chanjar.weixin.common.util.http.okhttp.OkHttpResponseProxy;
|
||||
|
||||
@@ -26,8 +26,8 @@ public interface HttpResponseProxy {
|
||||
return new ApacheHttpResponseProxy(response);
|
||||
}
|
||||
|
||||
static ApacheHttpClient5ResponseProxy from(org.apache.hc.client5.http.impl.classic.CloseableHttpResponse response) {
|
||||
return new ApacheHttpClient5ResponseProxy(response);
|
||||
static HttpComponentsResponseProxy from(org.apache.hc.client5.http.impl.classic.CloseableHttpResponse response) {
|
||||
return new HttpComponentsResponseProxy(response);
|
||||
}
|
||||
|
||||
static JoddHttpResponseProxy from(jodd.http.HttpResponse response) {
|
||||
@@ -40,7 +40,7 @@ public interface HttpResponseProxy {
|
||||
|
||||
String getFileName() throws WxErrorException;
|
||||
|
||||
default String extractFileNameFromContentString(String content) throws WxErrorException {
|
||||
static String extractFileNameFromContentString(String content) throws WxErrorException {
|
||||
if (content == null || content.isEmpty()) {
|
||||
throw new WxErrorException("无法获取到文件名,content为空");
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user