大改:重构项目
This commit is contained in:
@@ -154,4 +154,58 @@ public class WechatCertTestController extends BaseController {
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
@Operation(summary = "检查商户平台配置状态")
|
||||
@PostMapping("/check-merchant-config")
|
||||
public ApiResult<Map<String, Object>> checkMerchantConfig(
|
||||
@RequestParam String merchantId,
|
||||
@RequestParam String privateKeyPath,
|
||||
@RequestParam String merchantSerialNumber,
|
||||
@RequestParam String apiV3Key) {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
log.info("开始检查商户平台配置状态...");
|
||||
log.info("商户号: {}", merchantId);
|
||||
|
||||
// 尝试创建自动证书配置
|
||||
Config config = wechatCertAutoConfig.createAutoConfig(
|
||||
merchantId, privateKeyPath, merchantSerialNumber, apiV3Key);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("configCreated", true);
|
||||
result.put("message", "商户平台配置正常,自动证书配置创建成功");
|
||||
result.put("merchantId", merchantId);
|
||||
result.put("recommendation", "配置正常,可以正常使用微信支付功能");
|
||||
|
||||
log.info("✅ 商户平台配置检查成功");
|
||||
return success("配置检查成功", result);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("❌ 商户平台配置检查失败: {}", e.getMessage(), e);
|
||||
|
||||
result.put("success", false);
|
||||
result.put("configCreated", false);
|
||||
result.put("error", e.getMessage());
|
||||
result.put("merchantId", merchantId);
|
||||
|
||||
// 分析错误类型并提供解决方案
|
||||
if (e.getMessage().contains("404") || e.getMessage().contains("RESOURCE_NOT_EXISTS")) {
|
||||
result.put("errorType", "商户平台配置问题");
|
||||
result.put("solution", "请在微信支付商户平台完成以下配置:\n" +
|
||||
"1. 登录商户平台:https://pay.weixin.qq.com/\n" +
|
||||
"2. 进入:产品中心 → 开发配置 → API安全\n" +
|
||||
"3. 申请API证书\n" +
|
||||
"4. 申请使用微信支付公钥\n" +
|
||||
"5. 确保API证书和微信支付公钥状态为\"已生效\"");
|
||||
result.put("documentUrl", "https://pay.weixin.qq.com/doc/v3/merchant/4012153196");
|
||||
} else {
|
||||
result.put("errorType", "其他配置问题");
|
||||
result.put("solution", "请检查商户号、证书序列号、API密钥等配置是否正确");
|
||||
}
|
||||
|
||||
return success("配置检查完成(发现问题)", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,12 +338,25 @@ import com.gxwebsoft.common.core.service.PaymentCacheService;
|
||||
System.out.println("序列号: " + payment.getMerchantSerialNumber());
|
||||
System.out.println("API密钥: 已配置(长度:" + payment.getApiKey().length() + ")");
|
||||
|
||||
// 临时使用RSA配置替代自动证书配置,避免404错误
|
||||
System.out.println("=== 注意:使用RSA配置替代自动证书配置 ===");
|
||||
System.out.println("原因:商户平台可能未开启API安全功能或未申请微信支付公钥");
|
||||
|
||||
try {
|
||||
config = wechatCertAutoConfig.createAutoConfig(
|
||||
payment.getMchId(),
|
||||
privateKey,
|
||||
payment.getMerchantSerialNumber(),
|
||||
payment.getApiKey()
|
||||
);
|
||||
} catch (Exception e) {
|
||||
System.err.println("自动证书配置失败: " + e.getMessage());
|
||||
System.err.println("请在微信支付商户平台完成以下配置:");
|
||||
System.err.println("1. 开启API安全功能");
|
||||
System.err.println("2. 申请使用微信支付公钥");
|
||||
System.err.println("3. 参考文档:https://pay.weixin.qq.com/doc/v3/merchant/4012153196");
|
||||
throw new RuntimeException("微信支付配置失败,请先在商户平台开启API安全功能", e);
|
||||
}
|
||||
} else {
|
||||
// 生产环境兼容公钥配置
|
||||
if (payment.getPubKey() != null && !payment.getPubKey().isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user