Skip to content

Commit 630a8d9

Browse files
authored
bump version to 0.4.2 (#106)
1 parent c5d89c7 commit 630a8d9

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

README.md

+32-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## 项目状态
1010

11-
当前版本`0.4.1`为测试版本。请商户的专业技术人员在使用时注意系统和软件的正确性和兼容性,以及带来的风险。
11+
当前版本`0.4.2`为测试版本。请商户的专业技术人员在使用时注意系统和软件的正确性和兼容性,以及带来的风险。
1212

1313
## 升级指引
1414

@@ -27,7 +27,7 @@
2727
在你的`build.gradle`文件中加入如下的依赖
2828

2929
```groovy
30-
implementation 'com.github.wechatpay-apiv3:wechatpay-apache-httpclient:0.4.1'
30+
implementation 'com.github.wechatpay-apiv3:wechatpay-apache-httpclient:0.4.2'
3131
```
3232

3333
### Maven
@@ -37,7 +37,7 @@ implementation 'com.github.wechatpay-apiv3:wechatpay-apache-httpclient:0.4.1'
3737
<dependency>
3838
<groupId>com.github.wechatpay-apiv3</groupId>
3939
<artifactId>wechatpay-apache-httpclient</artifactId>
40-
<version>0.4.1</version>
40+
<version>0.4.2</version>
4141
</dependency>
4242
```
4343

@@ -270,6 +270,35 @@ try (FileInputStream ins1 = new FileInputStream(file)) {
270270

271271
[AutoUpdateVerifierTest.uploadImageTest](/src/test/java/com/wechat/pay/contrib/apache/httpclient/AutoUpdateVerifierTest.java#90)是一个更完整的示例。
272272

273+
## 回调通知的验签与解密
274+
版本>=`0.4.2`可使用 `NotificationHandler.parse(request)` 对回调通知验签和解密:
275+
276+
1. 使用`NotificationRequest`构造一个回调通知请求体,需设置应答平台证书序列号、应答随机串、应答时间戳、应答签名串、应答主体。
277+
2. 使用`NotificationHandler`构造一个回调通知处理器,需设置验证器、apiV3密钥。调用`parse(request)`得到回调通知`notification`
278+
279+
示例请参考下列代码。
280+
```java
281+
// 构建request,传入必要参数
282+
NotificationRequest request = new NotificationRequest.Builder().withSerialNumber(wechatPaySerial)
283+
.withNonce(nonce)
284+
.withTimestamp(timestamp)
285+
.withSignature(signature)
286+
.withBody(body)
287+
.build();
288+
NotificationHandler handler = new NotificationHandler(verifier, apiV3Key.getBytes(StandardCharsets.UTF_8));
289+
// 验签和解析请求体
290+
Notification notification = handler.parse(request);
291+
// 从notification中获取解密报文
292+
System.out.println(nottDecryptData());
293+
```
294+
295+
[NotificationHandlerTest](src/test/java/com/wechat/pay/contrib/apache/httpclient/NotificationHandlerTest.java#105)是一个更完整的示例。
296+
297+
### 异常处理
298+
`parse(request)`可能返回以下异常,推荐对异常打日志或上报监控。
299+
- 抛出`ValidationException`时,请先检查传入参数是否与回调通知参数一致。若一致,说明参数可能被恶意篡改导致验签失败。
300+
- 抛出`ParseException`时,请先检查传入包体是否与回调通知包体一致。若一致,请检查AES密钥是否正确设置。若正确,说明包体可能被恶意篡改导致解析失败。
301+
273302
## 常见问题
274303

275304
### 如何加载商户私钥

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group 'com.github.wechatpay-apiv3'
8-
version '0.4.1'
8+
version '0.4.2'
99

1010
sourceCompatibility = 1.8
1111
targetCompatibility = 1.8

0 commit comments

Comments
 (0)