Переглянути джерело

fix: 通知biz_content嵌套字段未展开导致handler读不到action/enterprise_id

alphaH 1 день тому
батько
коміт
f0e1fd3362

+ 21 - 0
java/src/main/java/com/payment/platform/module/payment/notification/service/NotificationService.java

@@ -72,6 +72,7 @@ public class NotificationService {
     public String verifyAndDispatch(Map<String, String> params) {
         String notifyId = params.get("notify_id");
         String msgMethod = params.get("msg_method");
+
         log.info("收到支付宝通知: msg_method={}, notify_id={}", msgMethod, notifyId);
 
         // Redis 幂等锁 — 对应 Python _is_notify_processed / _mark_notify_processed
@@ -111,6 +112,9 @@ public class NotificationService {
                 return "fail";
             }
 
+            // 解析 biz_content — 支付宝将业务参数嵌套在此字段,展开到 params 供 handler 读取
+            flattenBizContent(params);
+
             dispatch(msgMethod, params);
             entry.setProcessResult(true);
             notifyLogMapper.insert(entry);
@@ -160,6 +164,23 @@ public class NotificationService {
         }
     }
 
+    /** 展开 biz_content 嵌套字段到 params(不覆盖已有 key) */
+    private void flattenBizContent(Map<String, String> params) {
+        String bizContent = params.get("biz_content");
+        if (StrUtil.isBlank(bizContent)) return;
+        try {
+            @SuppressWarnings("unchecked")
+            Map<String, Object> nested = oMapper.readValue(bizContent, Map.class);
+            for (Map.Entry<String, Object> e : nested.entrySet()) {
+                if (e.getValue() != null && !params.containsKey(e.getKey())) {
+                    params.put(e.getKey(), String.valueOf(e.getValue()));
+                }
+            }
+        } catch (Exception e) {
+            log.warn("解析 biz_content 失败: {}", e.getMessage());
+        }
+    }
+
     // ========== 查询 ==========
 
     public PageResult<AlipayNotifyLogEntity> getLogPage(int pageNo, int pageSize) {