Skip to content

Commit c483d6f

Browse files
authored
🐛 #3392【微信支付】修复V3客户端初始化时p12证书加载失败的问题
1 parent bf7356e commit c483d6f

File tree

1 file changed

+8
-21
lines changed
  • weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config

1 file changed

+8
-21
lines changed

Diff for: weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java

+8-21
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ public CloseableHttpClient initApiV3HttpClient() throws WxPayException {
270270
if (objects != null) {
271271
merchantPrivateKey = (PrivateKey) objects[0];
272272
certificate = (X509Certificate) objects[1];
273+
this.certSerialNo = certificate.getSerialNumber().toString(16).toUpperCase();
273274
}
274275
try {
275276
if (merchantPrivateKey == null) {
@@ -405,38 +406,24 @@ private InputStream loadConfigInputStream(String configPath) throws WxPayExcepti
405406
}
406407
}
407408

408-
/**
409-
* 从配置路径 加载p12证书文件流
410-
*
411-
* @return 文件流
412-
*/
413-
private InputStream loadP12InputStream() {
414-
try (InputStream inputStream = this.loadConfigInputStream(this.keyString, this.getKeyPath(),
415-
this.keyContent, "p12证书");) {
416-
return inputStream;
417-
} catch (Exception e) {
418-
return null;
419-
}
420-
}
421-
422409
/**
423410
* 分解p12证书文件
424411
*
425412
* @return
426413
*/
427414
private Object[] p12ToPem() {
428-
InputStream inputStream = this.loadP12InputStream();
429-
if (inputStream == null) {
430-
return null;
431-
}
432415
String key = getMchId();
433416
if (StringUtils.isBlank(key)) {
434417
return null;
435418
}
436419
// 分解p12证书文件
437420
PrivateKey privateKey = null;
438421
X509Certificate x509Certificate = null;
439-
try {
422+
try (InputStream inputStream = this.loadConfigInputStream(this.keyString, this.getKeyPath(),
423+
this.keyContent, "p12证书");){
424+
if (inputStream == null) {
425+
return null;
426+
}
440427
KeyStore keyStore = KeyStore.getInstance("PKCS12");
441428
keyStore.load(inputStream, key.toCharArray());
442429

@@ -446,8 +433,8 @@ private Object[] p12ToPem() {
446433
Certificate certificate = keyStore.getCertificate(alias);
447434
x509Certificate = (X509Certificate) certificate;
448435
return new Object[]{privateKey, x509Certificate};
449-
} catch (Exception ignored) {
450-
436+
} catch (Exception e) {
437+
e.printStackTrace();
451438
}
452439
return null;
453440

0 commit comments

Comments
 (0)