@@ -39,8 +39,7 @@ implementation 'com.github.wechatpay-apiv3:wechatpay-apache-httpclient:0.2.2'
3939
4040## 开始
4141
42- 如果你使用的是` HttpClientBuilder ` 或者` HttpClients#custom() ` 来构造` HttpClient ` ,你可以直接替换为` WechatPayHttpClientBuilder ` 。我们提供相应的方法,可以方便的传入商户私钥和微信支付平台证书等信息。
43-
42+ 如果你使用的是` HttpClientBuilder ` 或者` HttpClients#custom() ` 来构造` HttpClient ` ,你可以直接替换为` WechatPayHttpClientBuilder ` 。
4443``` java
4544import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder ;
4645
@@ -61,8 +60,8 @@ HttpResponse response = httpClient.execute(...);
6160
6261+ ` merchantId ` 商户号。
6362+ ` 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 ` 实例列表 ,用于应答签名的验证。你也可以使用后面章节提到的“[ 自动更新证书功能] ( #自动更新证书功能 ) ”,而不需要关心平台证书的来龙去脉 。
6665
6766### 示例:获取平台证书
6867
@@ -107,7 +106,7 @@ rootNode.putObject("payer")
107106
108107objectMapper. writeValue(bos, rootNode);
109108
110- httpPost. setEntity(new StringEntity (bos. toString(" UTF-8" )));
109+ httpPost. setEntity(new StringEntity (bos. toString(" UTF-8" ), " UTF-8 " ));
111110CloseableHttpResponse response = httpClient. execute(httpPost);
112111
113112String bodyAsString = EntityUtils . toString(response. getEntity());
@@ -142,7 +141,7 @@ rootNode.put("mchid","1900009191");
142141
143142objectMapper. writeValue(bos, rootNode);
144143
145- httpPost. setEntity(new StringEntity (bos. toString(" UTF-8" )));
144+ httpPost. setEntity(new StringEntity (bos. toString(" UTF-8" ), " UTF-8 " ));
146145CloseableHttpResponse response = httpClient. execute(httpPost);
147146
148147String bodyAsString = EntityUtils . toString(response. getEntity());
@@ -169,19 +168,18 @@ WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create()
169168 .withWechatpay(wechatpayCertificates);
170169```
171170
172- ## 自动更新证书功能(可选)
171+ ## 自动更新证书功能
173172
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个小时)更新证书 。
175174
176175示例代码:
177176
178177``` java
179- // 不需要传入微信支付证书,将会自动更新
178+ // 不需要传入微信支付证书了
180179AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier (
181180 new WechatPay2Credentials (merchantId, new PrivateKeySigner (merchantSerialNumber, merchantPrivateKey)),
182181 apiV3Key. getBytes(" utf-8" ));
183182
184-
185183WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder . create()
186184 .withMerchant(merchantId, merchantSerialNumber, merchantPrivateKey)
187185 .withValidator(new WechatPay2Validator (verifier))
0 commit comments