Skip to content

Commit a864030

Browse files
committed
完善README
1 parent 37e254e commit a864030

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

README.md

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,48 @@
1111
当前版本`0.3.0`为测试版本。请商户的专业技术人员在使用时注意系统和软件的正确性和兼容性,以及带来的风险。
1212

1313
## 升级指引
14-
版本`0.3.0``Verifier`接口新增了`getLatestCertificate`方法。如果你已经在使用版本<`0.3.0`的SDK,且使用自定义类实现了`Verifier`接口,在升级版本为`0.3.0`时,请在自定义类中实现`getLatestCertificate`方法。
14+
15+
版本`v0.3.0` 进行了以下变更:
16+
17+
- 增加了[定时更新平台证书功能](#定时更新平台证书功能),替换原来的自动更新平台证书功能。
18+
19+
-`Verifier`接口新增了`getLatestCertificate`方法。
20+
21+
以上变更的原因为:
22+
23+
- 原来的自动更新平台证书功能,在新旧平台证书更换期间,可能导致下载新平台证书时验签不过,可参考 [issue](https://github.com/wechatpay-apiv3/wechatpay-apache-httpclient/issues/66) 。新增的定时更新平台证书功能,可避免上述问题。
24+
25+
- 在新旧平台证书更换期间,需要使用最新的平台证书加密请求消息中的敏感信息,可参考 [微信支付APIv3文档](https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay5_1.shtml)`getValidCertificate`方法不能保证获取最新的平台证书,因此增加`getLatestCertificate`方法来替换使用。
26+
27+
28+
若你正使用版本<`v0.3.0`的SDK,并准备升级为版本`v0.3.0`,请根据以下操作步骤进行。
29+
30+
- 升级依赖
31+
32+
- 使用Gradle管理依赖:将`build.gradle`中的SDK依赖修改为
33+
```groovy
34+
implementation 'com.github.wechatpay-apiv3:wechatpay-apache-httpclient:0.3.0'
35+
```
36+
- 使用Maven管理依赖:将Maven中的SDK依赖修改为
37+
```xml
38+
<dependency>
39+
<groupId>com.github.wechatpay-apiv3</groupId>
40+
<artifactId>wechatpay-apache-httpclient</artifactId>
41+
<version>0.3.0</version>
42+
</dependency>
43+
```
44+
45+
- 实现 getLatestCertificate 方法
46+
47+
**若你没有使用自定义类实现Verifier接口,则无需进行此步骤。**
48+
49+
若你使用自定义类实现了`Verifier`接口,在升级版本为`0.3.0`时,请在自定义类中实现`getLatestCertificate`方法。
50+
51+
- 使用 ScheduledUpdateCertificatesVerifier 替换 AutoUpdateCertificatesVerifier
52+
53+
**若你没有使用AutoUpdateCertificatesVerifier,则无需进行此步骤。**
54+
55+
将代码中使用`AutoUpdateCertificatesVerifier`的地方替换为`ScheduledUpdateCertificatesVerifier`,并修改import的类为`ScheduledUpdateCertificatesVerifier`。
1556
1657
## 环境要求
1758
@@ -72,7 +113,7 @@ HttpResponse response = httpClient.execute(...);
72113
+ `merchantId`商户号。
73114
+ `merchantSerialNumber`商户API证书的证书序列号。
74115
+ `merchantPrivateKey`商户API私钥,如何加载商户API私钥请看[常见问题](#如何加载商户私钥)
75-
+ `wechatpayCertificates`微信支付平台证书。你也可以使用后面章节提到的“[自动更新证书功能](#自动更新证书功能)”,而不需要关心平台证书的来龙去脉。
116+
+ `wechatpayCertificates`微信支付平台证书。你也可以使用后面章节提到的“[定时更新平台证书功能](#定时更新平台证书功能)”,而不需要关心平台证书的来龙去脉。
76117

77118
### 示例:获取平台证书
78119

@@ -179,7 +220,7 @@ WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create()
179220
.withWechatPay(wechatpayCertificates);
180221
```
181222

182-
## 定时更新证书功能
223+
## 定时更新平台证书功能
183224

184225
替换`自动更新证书功能`
185226

@@ -211,39 +252,6 @@ HttpResponse response = httpClient.execute(...);
211252

212253
但下载时会通过 **HTTPS****AES 对称加密**来保证证书安全,所以可以认为,在使用官方 JDK、且 APIv3 密钥不泄露的情况下,ScheduledUpdateCertificatesVerifier 是**安全**的。
213254

214-
## 自动更新证书功能
215-
216-
该功能存在缺陷,在新旧证书更换期间,可能导致下载新证书验签不过,建议使用 `定时更新证书功能` 替换。
217-
218-
版本`>=0.1.5`可使用 AutoUpdateCertificatesVerifier 类替代默认的验签器。它会在构造时自动下载商户对应的[微信支付平台证书](https://wechatpay-api.gitbook.io/wechatpay-api-v3/ren-zheng/zheng-shu#ping-tai-zheng-shu),并每隔一段时间(默认为1个小时)更新证书。
219-
220-
参数说明:`apiV3Key`是String格式的API v3密钥。
221-
222-
示例代码:
223-
224-
```java
225-
//不需要传入微信支付证书了
226-
AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
227-
new WechatPay2Credentials(merchantId, new PrivateKeySigner(merchantSerialNumber, merchantPrivateKey)),
228-
apiV3Key.getBytes("utf-8"));
229-
230-
WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create()
231-
.withMerchant(merchantId, merchantSerialNumber, merchantPrivateKey)
232-
.withValidator(new WechatPay2Validator(verifier))
233-
// ... 接下来,你仍然可以通过builder设置各种参数,来配置你的HttpClient
234-
235-
// 通过WechatPayHttpClientBuilder构造的HttpClient,会自动的处理签名和验签,并进行证书自动更新
236-
HttpClient httpClient = builder.build();
237-
238-
// 后面跟使用Apache HttpClient一样
239-
HttpResponse response = httpClient.execute(...);
240-
```
241-
### 风险
242-
243-
因为不需要传入微信支付平台证书,AutoUpdateCertificatesVerifier 在首次更新证书时**不会验签**,也就无法确认应答身份,可能导致下载错误的证书。
244-
245-
但下载时会通过 **HTTPS****AES 对称加密**来保证证书安全,所以可以认为,在使用官方 JDK、且 APIv3 密钥不泄露的情况下,AutoUpdateCertificatesVerifier 是**安全**的。
246-
247255
## 敏感信息加解密
248256

249257
### 加密

0 commit comments

Comments
 (0)