Просмотр исходного кода

调整兔灵erp物流同步回调接口

cgp 1 неделя назад
Родитель
Сommit
ce92ad4153

+ 4 - 3
fs-admin/src/main/java/com/fs/his/controller/JstOrderSyncController.java

@@ -34,7 +34,7 @@ public class JstOrderSyncController {
 
 
     /**
-     * 接收聚水潭物流同步推送
+     * 接收聚水潭erp回调
      * URL: POST /open/callback?partnerid=erp&method=logistics.upload&ts=xxx&sign=xxx
      */
     @PostMapping("/open/callback")
@@ -74,7 +74,7 @@ public class JstOrderSyncController {
         }
     }
 
-    // 模拟订单同步到兔灵erp接口
+    // 模拟订单推送到兔灵erp接口
     @PostMapping("/create")
     public Object syncOrderToJst(){
         TlCreateOrderRequest request=fillRequest();
@@ -166,7 +166,8 @@ public class JstOrderSyncController {
         //PaymentDTO pay = new PaymentDTO();
         TlPayDetail pay = new TlPayDetail();
         pay.setOuterPayId("PAY_20251110_001"); // 必填
-        pay.setPayDate("2025-11-10T10:30:00Z"); // 必填,RFC3339
+        //pay.setPayDate("2025-11-10T10:30:00Z"); // 必填,RFC3339
+        pay.setPayDate("2025-11-11 10:39:03"); // 必填,RFC3339
         pay.setPayment("online");
         pay.setSellerAccount("alipay@company.com"); // 必填
         pay.setBuyerAccount("buyer@example.com");   // 必填

+ 36 - 35
fs-service/src/main/java/com/fs/erp/service/impl/TlErpOrderServiceImpl.java

@@ -21,9 +21,12 @@ public class TlErpOrderServiceImpl implements TlErpOrderService {
 
     //测试兔灵ERP
     //@Value("${jst.api.url:https://api.xiangyue.life/api}")
+
+    //生产兔灵ERP
     @Value("${jst.api.url:https://papi.xiangyue.life/api}")
     private String jstApiBaseUrl;
 
+    //兔灵提供密钥
     @Value("${jst.secret.key:xysync_dLsSaheCzK7RU9gd}")
     private String secretKey;
 
@@ -50,12 +53,9 @@ public class TlErpOrderServiceImpl implements TlErpOrderService {
 
             String url = jstApiBaseUrl + "/v1/mp/sync/order/jst/create?sign=" + sign + "&t=" + timestamp;
             String requestBody = objectMapper.writeValueAsString(request);
-
+            log.info("url传参 sign: {}, t: {}", sign, timestamp);
             log.info("请求URL: {}", url);
             log.info("请求Body: {}", requestBody);
-            //log.info("sign = MD5({})", signSource);
-            log.info("最终 sign: {}, t: {}", sign, timestamp);
-            // 使用 Hutool HttpRequest 发送 POST 请求
             HttpResponse response = cn.hutool.http.HttpRequest.post(url)
                     .header("Content-Type", "application/json;charset=UTF-8")
                     .body(requestBody)
@@ -64,7 +64,7 @@ public class TlErpOrderServiceImpl implements TlErpOrderService {
 
             if (!response.isOk()) {
                 log.error("HTTP 请求失败,状态码: {}", response.getStatus());
-                throw new RuntimeException("调用聚水潭接口失败,HTTP 状态码: " + response.getStatus());
+                throw new RuntimeException("调用【兔灵】接口失败,HTTP 状态码: " + response.getStatus());
             }
 
             // 解析响应体
@@ -73,17 +73,17 @@ public class TlErpOrderServiceImpl implements TlErpOrderService {
             try {
                 result = objectMapper.readValue(responseBody, Map.class);
             } catch (Exception e) {
-                log.error("无法解析聚水潭响应体: {}", responseBody, e);
-                throw new RuntimeException("聚水潭返回非 JSON 响应", e);
+                log.error("无法解析【兔灵】响应体: {}", responseBody, e);
+                throw new RuntimeException("【兔灵】返回非 JSON 响应", e);
             }
             // 判断业务状态是否为 "ok"
             String status = (String) result.get("status");
             if (!"ok".equals(status)) {
                 String errmsg = (String) result.get("errmsg");
-                log.error("聚水潭业务处理失败,status: {}, errmsg: {}", status, errmsg);
-                throw new RuntimeException("聚水潭同步订单失败: " + (errmsg != null ? errmsg : "未知错误"));
+                log.error("【兔灵】业务处理失败,status: {}, errmsg: {}", status, errmsg);
+                throw new RuntimeException("【兔灵】同步订单失败: " + (errmsg != null ? errmsg : "未知错误"));
             }
-            log.info("订单同步到聚水潭成功!{}",result);
+            log.info("订单同步到【兔灵】成功!{}",result);
             return response;
         } catch (Exception e) {
             throw new RuntimeException(e);
@@ -91,6 +91,32 @@ public class TlErpOrderServiceImpl implements TlErpOrderService {
 
     }
 
+    public void processLogisticsPush(JstLogisticsPushRequest request) {
+        // 关键业务字段
+        String soId = request.getSoId();       // 外部单号
+        String lId = request.getLId();         // 物流单号
+        String lcId = request.getLcId();       // 快递公司编码
+        String sendDate = request.getSendDate();
+        log.info("收到聚水潭【兔灵】物流单号推送: 外部单号:{}, 物流单号:{}, 快递公司编码:{}, 发送时间:{}", soId, lId, lcId, sendDate);
+
+        // TODO: 根据 id 查询系统中的订单,并更新物流信息
+        // Order order = orderRepository.findBySoId(soId);
+        // if (order != null) {
+        //     order.setLogisticsNo(lId);
+        //     order.setLogisticsCompany(lcId);
+        //     order.setShipTime(LocalDateTime.parse(sendDate, ...));
+        //     orderRepository.save(order);
+        // }
+
+        //遍历处理items
+        if (request.getItems() != null) {
+            request.getItems().forEach(item -> {
+                log.debug("商品项: skuId={}, qty={}", item.getSkuId(), item.getQty());
+            });
+        }
+    }
+
+
     /**
      * 递归对 Map 进行按键升序排序(支持嵌套 Map 和 List)
      */
@@ -128,29 +154,4 @@ public class TlErpOrderServiceImpl implements TlErpOrderService {
         }
         return objectMapper.writeValueAsString(sortedList);
     }
-
-    public void processLogisticsPush(JstLogisticsPushRequest request) {
-        // 关键业务字段
-        String soId = request.getSoId();       // 外部单号
-        String lId = request.getLId();         // 物流单号
-        String lcId = request.getLcId();       // 快递公司编码
-        String sendDate = request.getSendDate();
-        log.info("【兔灵】物流单号推送: 外部单号:{}, 物流单号:{}, 快递公司编码:{}, 发送时间:{}", soId, lId, lcId, sendDate);
-
-        // TODO: 根据 id 查询系统中的订单,并更新物流信息
-        // Order order = orderRepository.findBySoId(soId);
-        // if (order != null) {
-        //     order.setLogisticsNo(lId);
-        //     order.setLogisticsCompany(lcId);
-        //     order.setShipTime(LocalDateTime.parse(sendDate, ...));
-        //     orderRepository.save(order);
-        // }
-
-        //遍历处理items
-        if (request.getItems() != null) {
-            request.getItems().forEach(item -> {
-                log.debug("商品项: skuId={}, qty={}", item.getSkuId(), item.getQty());
-            });
-        }
-    }
 }