Преглед изворни кода

feat(wechat): 实现订单发货信息上传接口

- 新增 `uploadShippingInfo` 方法支持微信支付订单发货信息上传
- 支持多种物流模式和发货模式配置
- 添加用户 openid 和发货列表参数校验
- 集成微信小程序发货信息录入 API 接口
- 增加接口调用失败日志记录与异常抛出机制
- 标记旧版 `uploadShippingInfo` 方法为废弃状态
runphp пре 4 месеци
родитељ
комит
cf76bd395b
1 измењених фајлова са 32 додато и 2 уклоњено
  1. 32 2
      src/Service/ExpressService.php

+ 32 - 2
src/Service/ExpressService.php

@@ -55,10 +55,40 @@ class ExpressService
      *
      * 使用微信支付单号
      *
+     * @param string $transactionID 微信支付单号
+     * @param string $openid 用户openid
+     * @param array $shippingList 订单发货信息
+     * @param int $logisticsType 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
+     * @param int $deliveryMode 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
+     *
      * @link https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/order-shipping/order-shipping.html#%E4%B8%80%E3%80%81%E5%8F%91%E8%B4%A7%E4%BF%A1%E6%81%AF%E5%BD%95%E5%85%A5%E6%8E%A5%E5%8F%A3
      */
-    public function uploadShippingInfo(string $transactionID): array
+    public function uploadShippingInfo(
+        string $transactionID,
+        string $openid,
+        array  $shippingList,
+        int    $logisticsType = 1,
+        int    $deliveryMode = 1,
+        bool   $isAllDelivered = false,
+    ): void
     {
-
+        $response = $this->miniApp->getClient()->postJson('/wxa/sec/order/upload_shipping_info', [
+            'order_key' => [
+                'order_number_type' => 2, // 使用微信支付单号
+                'transaction_id' => $transactionID,
+            ],
+            'logistics_type' => $logisticsType,
+            'delivery_mode' => $deliveryMode,
+            'payer' => [
+                'openid' => $openid,
+            ],
+            'upload_time' => date('c'),
+            'shipping_list' => $shippingList,
+        ]);
+        if ($response->isFailed()) {
+            $responseData = $response->toArray();
+            Log::error('发货信息录入失败{transaction_id}{response}', ['transaction_id' => $transactionID, 'response' => json_encode($responseData)]);
+            throw_logic_exception(msg: '发货信息录入失败', code: $responseData['errcode']);
+        }
     }
 }