From 19d6084bf66c394cdbd484aeb1b0e73a7f20f0a3 Mon Sep 17 00:00:00 2001 From: leung Date: Thu, 24 Oct 2024 18:39:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dp12=E8=AF=81=E4=B9=A6=E4=BB=8Eclosed=20inputs?= =?UTF-8?q?tream=E5=8A=A0=E8=BD=BD=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binarywang/wxpay/config/WxPayConfig.java | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java index 83a4b042c..3bc868d07 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java @@ -270,6 +270,7 @@ public CloseableHttpClient initApiV3HttpClient() throws WxPayException { if (objects != null) { merchantPrivateKey = (PrivateKey) objects[0]; certificate = (X509Certificate) objects[1]; + this.certSerialNo = certificate.getSerialNumber().toString(16).toUpperCase(); } try { if (merchantPrivateKey == null) { @@ -405,30 +406,12 @@ private InputStream loadConfigInputStream(String configPath) throws WxPayExcepti } } - /** - * 从配置路径 加载p12证书文件流 - * - * @return 文件流 - */ - private InputStream loadP12InputStream() { - try (InputStream inputStream = this.loadConfigInputStream(this.keyString, this.getKeyPath(), - this.keyContent, "p12证书");) { - return inputStream; - } catch (Exception e) { - return null; - } - } - /** * 分解p12证书文件 * * @return */ private Object[] p12ToPem() { - InputStream inputStream = this.loadP12InputStream(); - if (inputStream == null) { - return null; - } String key = getMchId(); if (StringUtils.isBlank(key)) { return null; @@ -436,7 +419,11 @@ private Object[] p12ToPem() { // 分解p12证书文件 PrivateKey privateKey = null; X509Certificate x509Certificate = null; - try { + try (InputStream inputStream = this.loadConfigInputStream(this.keyString, this.getKeyPath(), + this.keyContent, "p12证书");){ + if (inputStream == null) { + return null; + } KeyStore keyStore = KeyStore.getInstance("PKCS12"); keyStore.load(inputStream, key.toCharArray()); @@ -446,8 +433,8 @@ private Object[] p12ToPem() { Certificate certificate = keyStore.getCertificate(alias); x509Certificate = (X509Certificate) certificate; return new Object[]{privateKey, x509Certificate}; - } catch (Exception ignored) { - + } catch (Exception e) { + e.printStackTrace(); } return null;