Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 【微信支付】初始化V3客户端:修复p12证书从closed inputstream加载失败的问题 #3392

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -405,38 +406,24 @@ 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;
}
// 分解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());

Expand All @@ -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();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方请使用log打印,谢谢

}
return null;

Expand Down