@@ -37,6 +37,14 @@ implementation 'com.github.wechatpay-apiv3:wechatpay-apache-httpclient:0.2.2'
37
37
</dependency >
38
38
```
39
39
40
+ ## 名词解释
41
+
42
+ + 商户API证书,是用来证实商户身份的。证书中包含商户号、证书序列号、证书有效期等信息,由证书授权机构(Certificate Authority ,简称CA)签发,以防证书被伪造或篡改。如何获取请见[ 商户API证书] ( https://wechatpay-api.gitbook.io/wechatpay-api-v3/ren-zheng/zheng-shu#shang-hu-api-zheng-shu ) 。
43
+ + 商户API私钥。商户申请商户API证书时,会生成商户私钥,并保存在本地证书文件夹的文件apiclient_key.pem中。注:不要把私钥文件暴露在公共场合,如上传到Github,写在客户端代码等。
44
+ + 微信支付平台证书。平台证书是指由微信支付负责申请的,包含微信支付平台标识、公钥信息的证书。商户可以使用平台证书中的公钥进行应答签名的验证。获取平台证书需通过[ 获取平台证书列表] ( https://wechatpay-api.gitbook.io/wechatpay-api-v3/ren-zheng/zheng-shu#ping-tai-zheng-shu ) 接口下载。
45
+ + 证书序列号。每个证书都有一个由CA颁发的唯一编号,即证书序列号。如何查看证书序列号请看[ 这里] ( https://wechatpay-api.gitbook.io/wechatpay-api-v3/chang-jian-wen-ti/zheng-shu-xiang-guan#ru-he-cha-kan-zheng-shu-xu-lie-hao ) 。
46
+ + API v3密钥。为了保证安全性,微信支付在回调通知和平台证书下载接口中,对关键信息进行了AES-256-GCM加密。API v3密钥是加密时使用的对称密钥。商户可以在【商户平台】->【API安全】的页面设置该密钥。
47
+
40
48
## 开始
41
49
42
50
如果你使用的是` HttpClientBuilder ` 或者` HttpClients#custom() ` 来构造` HttpClient ` ,你可以直接替换为` WechatPayHttpClientBuilder ` 。
@@ -59,9 +67,9 @@ HttpResponse response = httpClient.execute(...);
59
67
参数说明:
60
68
61
69
+ ` merchantId ` 商户号。
62
- + ` merchantSerialNumber ` 商户证书的证书序列号,请参考 [ 什么是证书序列号 ] ( https://wechatpay-api.gitbook.io/wechatpay-api-v3/chang-jian-wen-ti/zheng-shu-xiang-guan#shen-me-shi-zheng-shu-xu-lie-hao ) 和 [ 如何查看证书序列号 ] ( https://wechatpay-api.gitbook.io/wechatpay-api-v3/chang-jian-wen-ti/zheng-shu-xiang-guan#ru-he-cha-kan-zheng-shu-xu-lie-hao ) 。
63
- + ` merchantPrivateKey ` 商户私钥 ` PrivateKey ` 实例 。
64
- + ` wechatpayCertificates ` [ 微信支付平台证书] ( https://wechatpay-api.gitbook.io/wechatpay-api-v3/ren-zheng/zheng-shu#ping-tai-zheng-shu ) 的 ` X509Certificate ` 实例列表,用于应答签名的验证 。你也可以使用后面章节提到的“[ 自动更新证书功能] ( #自动更新证书功能 ) ”,而不需要关心平台证书的来龙去脉。
70
+ + ` merchantSerialNumber ` 商户API证书的证书序列号 。
71
+ + ` merchantPrivateKey ` 商户API私钥,如何加载商户API私钥请看 [ 常见问题 ] ( #如何加载商户私钥 ) 。
72
+ + ` wechatpayCertificates ` 微信支付平台证书。你也可以使用后面章节提到的“[ 自动更新证书功能] ( #自动更新证书功能 ) ”,而不需要关心平台证书的来龙去脉。
65
73
66
74
### 示例:获取平台证书
67
75
@@ -172,6 +180,8 @@ WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create()
172
180
173
181
版本` >=0.1.5 ` 可使用 AutoUpdateCertificatesVerifier 类替代默认的验签器。它会在构造时自动下载商户对应的[ 微信支付平台证书] ( https://wechatpay-api.gitbook.io/wechatpay-api-v3/ren-zheng/zheng-shu#ping-tai-zheng-shu ) ,并每隔一段时间(默认为1个小时)更新证书。
174
182
183
+ 参数说明:` apiV3Key ` 是String格式的API v3密钥。
184
+
175
185
示例代码:
176
186
177
187
``` java
@@ -255,6 +265,20 @@ try (FileInputStream ins1 = new FileInputStream(file)) {
255
265
256
266
## 常见问题
257
267
268
+ ### 如何加载商户私钥
269
+
270
+ 商户申请商户API证书时,会生成商户私钥,并保存在本地证书文件夹的文件` apiclient_key.pem ` 中。商户开发者可以使用方法` PemUtil.loadPrivateKey() ` 加载证书。
271
+
272
+ ``` java
273
+ # 示例:私钥存储在文件
274
+ PrivateKey merchantPrivateKey = PemUtil . loadPrivateKey(
275
+ new FileInputStream (" /path/to/apiclient_key.pem" ));
276
+
277
+ # 示例:私钥为String 字符串
278
+ PrivateKey merchantPrivateKey = PemUtil . loadPrivateKey(
279
+ new ByteArrayInputStream (privateKey. getBytes(" utf-8" )));
280
+ ```
281
+
258
282
### 如何下载平台证书?
259
283
260
284
使用` WechatPayHttpClientBuilder ` 需要调用` withWechatpay ` 设置[ 微信支付平台证书] ( https://wechatpay-api.gitbook.io/wechatpay-api-v3/ren-zheng/zheng-shu#ping-tai-zheng-shu ) ,而平台证书又只能通过调用[ 获取平台证书接口] ( https://wechatpay-api.gitbook.io/wechatpay-api-v3/jie-kou-wen-dang/ping-tai-zheng-shu#huo-qu-ping-tai-zheng-shu-lie-biao ) 下载。为了解开"死循环",你可以在第一次下载平台证书时,按照下述方法临时"跳过”应答签名的验证。
@@ -299,9 +323,12 @@ dependencies {
299
323
}
300
324
```
301
325
326
+ ### 更多常见问题
327
+
328
+ 请看商户平台的[ 常见问题] ( https://pay.weixin.qq.com/wiki/doc/apiv3_partner/wechatpay/wechatpay7_0.shtml ) ,或者[ 这里] ( https://wechatpay-api.gitbook.io/wechatpay-api-v3/chang-jian-wen-ti ) 。
329
+
302
330
## 联系我们
303
331
304
332
如果你发现了** BUG** 或者有任何疑问、建议,请通过issue进行反馈。
305
333
306
334
也欢迎访问我们的[ 开发者社区] ( https://developers.weixin.qq.com/community/pay ) 。
307
-
0 commit comments