mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 16:18:51 +08:00
微信支付证书路径判断代码优化
This commit is contained in:
parent
9a928f2601
commit
c494fbe71d
@ -158,18 +158,27 @@ public class WxPayConfig {
|
|||||||
|
|
||||||
InputStream inputStream;
|
InputStream inputStream;
|
||||||
final String prefix = "classpath:";
|
final String prefix = "classpath:";
|
||||||
|
String fileHasProblemMsg = "证书文件【" + this.keyPath + "】有问题,请核实!";
|
||||||
|
String fileNotFoundMsg = "证书文件【" + this.keyPath + "】不存在,请核实!";
|
||||||
if (this.keyPath.startsWith(prefix)) {
|
if (this.keyPath.startsWith(prefix)) {
|
||||||
inputStream = WxPayConfig.class.getResourceAsStream(this.keyPath.replace(prefix, ""));
|
String path = StringUtils.removeFirst(this.keyPath, prefix);
|
||||||
|
if (!path.startsWith("/")) {
|
||||||
|
path = "/" + path;
|
||||||
|
}
|
||||||
|
inputStream = WxPayConfig.class.getResourceAsStream(path);
|
||||||
|
if (inputStream == null) {
|
||||||
|
throw new WxPayException(fileNotFoundMsg);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
File file = new File(this.keyPath);
|
File file = new File(this.keyPath);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
throw new WxPayException("证书文件【" + file.getPath() + "】不存在!");
|
throw new WxPayException(fileNotFoundMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
inputStream = new FileInputStream(file);
|
inputStream = new FileInputStream(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new WxPayException("证书文件有问题,请核实!", e);
|
throw new WxPayException(fileHasProblemMsg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +189,7 @@ public class WxPayConfig {
|
|||||||
this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build();
|
this.sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build();
|
||||||
return this.sslContext;
|
return this.sslContext;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new WxPayException("证书文件有问题,请核实!", e);
|
throw new WxPayException(fileHasProblemMsg, e);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(inputStream);
|
IOUtils.closeQuietly(inputStream);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user