@@ -39,8 +39,7 @@ implementation 'com.github.wechatpay-apiv3:wechatpay-apache-httpclient:0.2.2'
39
39
40
40
## 开始
41
41
42
- 如果你使用的是` HttpClientBuilder ` 或者` HttpClients#custom() ` 来构造` HttpClient ` ,你可以直接替换为` WechatPayHttpClientBuilder ` 。我们提供相应的方法,可以方便的传入商户私钥和微信支付平台证书等信息。
43
-
42
+ 如果你使用的是` HttpClientBuilder ` 或者` HttpClients#custom() ` 来构造` HttpClient ` ,你可以直接替换为` WechatPayHttpClientBuilder ` 。
44
43
``` java
45
44
import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder ;
46
45
@@ -61,8 +60,8 @@ HttpResponse response = httpClient.execute(...);
61
60
62
61
+ ` merchantId ` 商户号。
63
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 ) 。
64
- + ` merchantPrivateKey ` 字符串格式的商户私钥,也就是通过证书工具得到的 ` apiclient_key.pem ` 文件中的内容 。
65
- + ` wechatpayCertificates ` 微信支付平台证书的实例列表 ,用于应答签名的验证。你也可以使用后面章节提到的“自动更新证书功能” 。
63
+ + ` merchantPrivateKey ` 商户私钥 ` PrivateKey ` 实例 。
64
+ + ` wechatpayCertificates ` [ 微信支付平台证书 ] ( https://wechatpay-api.gitbook.io/wechatpay-api-v3/ren-zheng/zheng-shu#ping-tai-zheng-shu ) 的 ` X509Certificate ` 实例列表 ,用于应答签名的验证。你也可以使用后面章节提到的“[ 自动更新证书功能] ( #自动更新证书功能 ) ”,而不需要关心平台证书的来龙去脉 。
66
65
67
66
### 示例:获取平台证书
68
67
@@ -107,7 +106,7 @@ rootNode.putObject("payer")
107
106
108
107
objectMapper. writeValue(bos, rootNode);
109
108
110
- httpPost. setEntity(new StringEntity (bos. toString(" UTF-8" )));
109
+ httpPost. setEntity(new StringEntity (bos. toString(" UTF-8" ), " UTF-8 " ));
111
110
CloseableHttpResponse response = httpClient. execute(httpPost);
112
111
113
112
String bodyAsString = EntityUtils . toString(response. getEntity());
@@ -142,7 +141,7 @@ rootNode.put("mchid","1900009191");
142
141
143
142
objectMapper. writeValue(bos, rootNode);
144
143
145
- httpPost. setEntity(new StringEntity (bos. toString(" UTF-8" )));
144
+ httpPost. setEntity(new StringEntity (bos. toString(" UTF-8" ), " UTF-8 " ));
146
145
CloseableHttpResponse response = httpClient. execute(httpPost);
147
146
148
147
String bodyAsString = EntityUtils . toString(response. getEntity());
@@ -169,19 +168,18 @@ WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create()
169
168
.withWechatpay(wechatpayCertificates);
170
169
```
171
170
172
- ## 自动更新证书功能(可选)
171
+ ## 自动更新证书功能
173
172
174
- 新版本 ` >=0.1.5 ` 可使用 AutoUpdateCertificatesVerifier 类,该类于原 CertificatesVerifier 上增加证书的 ** 超时自动更新 ** (默认与上次更新时间超过一小时后自动更新),并会在首次创建时,进行证书更新 。
173
+ 版本 ` >=0.1.5 ` 可使用 AutoUpdateCertificatesVerifier 类替代默认的验签器。它会在构造时自动下载商户对应的 [ 微信支付平台证书 ] ( https://wechatpay-api.gitbook.io/wechatpay-api-v3/ren-zheng/zheng-shu#ping-tai-zheng-shu ) ,并每隔一段时间(默认为1个小时)更新证书 。
175
174
176
175
示例代码:
177
176
178
177
``` java
179
- // 不需要传入微信支付证书,将会自动更新
178
+ // 不需要传入微信支付证书了
180
179
AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier (
181
180
new WechatPay2Credentials (merchantId, new PrivateKeySigner (merchantSerialNumber, merchantPrivateKey)),
182
181
apiV3Key. getBytes(" utf-8" ));
183
182
184
-
185
183
WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder . create()
186
184
.withMerchant(merchantId, merchantSerialNumber, merchantPrivateKey)
187
185
.withValidator(new WechatPay2Validator (verifier))
0 commit comments