From f6e300b10a74af6cc1df2b78aa97d8fe5effa1ad Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 31 Oct 2024 16:20:24 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=8F=8A=E6=97=B6=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=89=93=E5=BC=80=E7=9A=84InputStream=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binarywang/wxpay/config/WxPayConfig.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 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 932fa323e..637d46e98 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 @@ -279,15 +279,18 @@ public class WxPayConfig { if (StringUtils.isNotBlank(this.getPrivateKeyString())) { this.setPrivateKeyString(Base64.getEncoder().encodeToString(this.getPrivateKeyString().getBytes())); } - InputStream keyInputStream = this.loadConfigInputStream(this.getPrivateKeyString(), this.getPrivateKeyPath(), - this.privateKeyContent, "privateKeyPath"); - merchantPrivateKey = PemUtils.loadPrivateKey(keyInputStream); + + try (InputStream keyInputStream = this.loadConfigInputStream(this.getPrivateKeyString(), this.getPrivateKeyPath(), + this.privateKeyContent, "privateKeyPath")) { + merchantPrivateKey = PemUtils.loadPrivateKey(keyInputStream); + } } if (certificate == null && StringUtils.isBlank(this.getCertSerialNo())) { - InputStream certInputStream = this.loadConfigInputStream(this.getPrivateCertString(), this.getPrivateCertPath(), - this.privateCertContent, "privateCertPath"); - certificate = PemUtils.loadCertificate(certInputStream); + try (InputStream certInputStream = this.loadConfigInputStream(this.getPrivateCertString(), this.getPrivateCertPath(), + this.privateCertContent, "privateCertPath")) { + certificate = PemUtils.loadCertificate(certInputStream); + } this.certSerialNo = certificate.getSerialNumber().toString(16).toUpperCase(); }