|
|
@@ -30,25 +30,8 @@ public class PaymentConfigServiceImpl implements IPaymentConfigService {
|
|
|
|
|
|
private final SysConfigMapper sysConfigMapper;
|
|
|
|
|
|
- /** 证书保存目录(模块resources/cert下) */
|
|
|
- private String getCertDir() {
|
|
|
- try {
|
|
|
- // 获取当前模块的resources目录
|
|
|
- String resourcePath = this.getClass().getClassLoader().getResource("").getPath();
|
|
|
- // Windows路径处理
|
|
|
- if (resourcePath.startsWith("/")) {
|
|
|
- resourcePath = resourcePath.substring(1);
|
|
|
- }
|
|
|
- // 开发环境:target/classes -> src/main/resources
|
|
|
- if (resourcePath.contains("target/classes")) {
|
|
|
- resourcePath = resourcePath.replace("target/classes", "src/main/resources");
|
|
|
- }
|
|
|
- return resourcePath + "cert";
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("获取resources路径失败", e);
|
|
|
- throw new RuntimeException("获取证书目录失败", e);
|
|
|
- }
|
|
|
- }
|
|
|
+ /** 证书保存目录(运行目录/cert下,仿照日志保存方式) */
|
|
|
+ private static final String CERT_DIR = "./cert";
|
|
|
|
|
|
// 配置key
|
|
|
private static final String SHORT_PRICE_KEY = "payment.short.price";
|
|
|
@@ -117,15 +100,15 @@ public class PaymentConfigServiceImpl implements IPaymentConfigService {
|
|
|
public boolean savePrivateKey(MultipartFile file) {
|
|
|
try {
|
|
|
// 保存到resources/cert目录
|
|
|
- String certDir = getCertDir();
|
|
|
+ String certDir = CERT_DIR;
|
|
|
File dir = new File(certDir);
|
|
|
if (!dir.exists()) {
|
|
|
boolean created = dir.mkdirs();
|
|
|
log.info("创建目录 {}: {}", certDir, created);
|
|
|
}
|
|
|
|
|
|
- String filePath = certDir + "/apiclient_key.pem";
|
|
|
- File destFile = new File(filePath);
|
|
|
+ File destFile = new File(certDir, "apiclient_key.pem");
|
|
|
+ String filePath = destFile.getAbsolutePath();
|
|
|
|
|
|
// 使用 InputStream 写入文件,避免 transferTo 在 Windows 上的问题
|
|
|
try (InputStream is = file.getInputStream();
|
|
|
@@ -152,15 +135,15 @@ public class PaymentConfigServiceImpl implements IPaymentConfigService {
|
|
|
public boolean saveCert(MultipartFile file) {
|
|
|
try {
|
|
|
// 保存到resources/cert目录
|
|
|
- String certDir = getCertDir();
|
|
|
+ String certDir = CERT_DIR;
|
|
|
File dir = new File(certDir);
|
|
|
if (!dir.exists()) {
|
|
|
boolean created = dir.mkdirs();
|
|
|
log.info("创建目录 {}: {}", certDir, created);
|
|
|
}
|
|
|
|
|
|
- String filePath = certDir + "/apiclient_cert.pem";
|
|
|
- File destFile = new File(filePath);
|
|
|
+ File destFile = new File(certDir, "apiclient_cert.pem");
|
|
|
+ String filePath = destFile.getAbsolutePath();
|
|
|
|
|
|
// 使用 InputStream 写入文件,避免 transferTo 在 Windows 上的问题
|
|
|
try (InputStream is = file.getInputStream();
|
|
|
@@ -187,15 +170,15 @@ public class PaymentConfigServiceImpl implements IPaymentConfigService {
|
|
|
public boolean savePublicKey(MultipartFile file) {
|
|
|
try {
|
|
|
// 保存到resources/cert目录
|
|
|
- String certDir = getCertDir();
|
|
|
+ String certDir = CERT_DIR;
|
|
|
File dir = new File(certDir);
|
|
|
if (!dir.exists()) {
|
|
|
boolean created = dir.mkdirs();
|
|
|
log.info("创建目录 {}: {}", certDir, created);
|
|
|
}
|
|
|
|
|
|
- String filePath = certDir + "/pub_key.pem";
|
|
|
- File destFile = new File(filePath);
|
|
|
+ File destFile = new File(certDir, "pub_key.pem");
|
|
|
+ String filePath = destFile.getAbsolutePath();
|
|
|
|
|
|
// 使用 InputStream 写入文件
|
|
|
try (InputStream is = file.getInputStream();
|