jialuyu пре 1 месец
родитељ
комит
6787bf73c1

+ 11 - 1
ruoyi-modules/ruoyi-main/src/main/java/org/dromara/main/config/WxPayConfig.java

@@ -116,8 +116,18 @@ public class WxPayConfig {
             }
 
             if (privateKeyStream != null) {
-                privateKey = PemUtil.readPemPrivateKey(privateKeyStream);
+                // 读取商户私钥文本内容
+                String pemContent = cn.hutool.core.io.IoUtil.readUtf8(privateKeyStream);
                 privateKeyStream.close();
+
+                // 校验私钥格式是否符合 PEM 标准
+                if (StringUtils.isBlank(pemContent) || !pemContent.contains("-----BEGIN")) {
+                    log.warn("商户私钥文件 [{}] 内容为空或格式无效(缺少 PEM 头部),跳过全局微信支付初始化", privateKeyPath);
+                    return;
+                }
+
+                // 解析商户私钥,复用 parsePrivateKey 以兼容 PKCS#1 与 PKCS#8
+                privateKey = parsePrivateKey(pemContent);
             } else {
                 log.warn("找不到商户私钥:{},跳过微信支付初始化", privateKeyPath);
                 return;