Parcourir la source

【代码修复】PAY:微信扫码支付 v2 版本,缺少 product_id 的报错

YunaiV il y a 7 mois
Parent
commit
55e1bca3c0

+ 13 - 2
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java

@@ -2,9 +2,11 @@ package cn.iocoder.yudao.framework.web.core.handler;
 
 import cn.hutool.core.exceptions.ExceptionUtil;
 import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
 import cn.iocoder.yudao.framework.common.exception.ServiceException;
+import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.util.collection.SetUtils;
 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
@@ -222,8 +224,17 @@ public class GlobalExceptionHandler {
         // 不包含的时候,才进行打印,避免 ex 堆栈过多
         if (!IGNORE_ERROR_MESSAGES.contains(ex.getMessage())) {
             // 即使打印,也只打印第一层 StackTraceElement,并且使用 warn 在控制台输出,更容易看到
-            StackTraceElement[] stackTrace = ex.getStackTrace();
-            log.warn("[serviceExceptionHandler]\n\t{}", stackTrace[0]);
+            try {
+                StackTraceElement[] stackTraces = ex.getStackTrace();
+                for (StackTraceElement stackTrace : stackTraces) {
+                    if (ObjUtil.notEqual(stackTrace.getClassName(), ServiceExceptionUtil.class.getName())) {
+                        log.warn("[serviceExceptionHandler]\n\t{}", stackTrace);
+                        break;
+                    }
+                }
+            } catch (Exception ignored) {
+                // 忽略日志,避免影响主流程
+            }
         }
         return CommonResult.error(ex.getCode(), ex.getMessage());
     }

+ 1 - 0
yudao-module-pay/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/WxNativePayClient.java

@@ -35,6 +35,7 @@ public class WxNativePayClient extends AbstractWxPayClient {
     protected PayOrderRespDTO doUnifiedOrderV2(PayOrderUnifiedReqDTO reqDTO) throws WxPayException {
         // 构建 WxPayUnifiedOrderRequest 对象
         WxPayUnifiedOrderRequest request = buildPayUnifiedOrderRequestV2(reqDTO);
+//                .setProductId(reqDTO.getOutTradeNo()); // V2 必须传递 productId,无需在微信配置。该参数在 V3 简化,无需传递!
         // 执行请求
         WxPayNativeOrderResult response = client.createOrder(request);