Selaa lähdekoodia

feat(wechatpay): 支持多种物流配送方式- 增加物流类型参数,支持实体物流、同城配送、虚拟商品和用户自提
- 调整接口参数默认值,使部分字段可选
- 根据物流类型动态构建请求数据结构
- 补充物流公司编码和收件人联系方式的处理逻辑- 优化发货信息上传接口的灵活性和兼容性

runphp 4 kuukautta sitten
vanhempi
sitoutus
a7861ad42d
2 muutettua tiedostoa jossa 24 lisäystä ja 19 poistoa
  1. 7 6
      src/PaymentProvider.php
  2. 17 13
      src/Trait/MiniAppTrait.php

+ 7 - 6
src/PaymentProvider.php

@@ -249,11 +249,12 @@ class PaymentProvider implements PaymentProviderInterface
      */
      */
     public function uploadShippingInfo(
     public function uploadShippingInfo(
         int    $orderID,
         int    $orderID,
-        string $itemDesc,
-        string $trackingNo,
-        string $expressCompany,
-        string $receiverContact,
-        bool   $failException = true
+        string $itemDesc = '',
+        string $trackingNo = '',
+        string $expressCompany = '',
+        string $receiverContact = '',
+        int $logisticsType = 1,
+        bool   $failException = true,
     ): array
     ): array
     {
     {
         $order = $this->extensionPaymentEntity->where([
         $order = $this->extensionPaymentEntity->where([
@@ -263,7 +264,7 @@ class PaymentProvider implements PaymentProviderInterface
         if ($order->isEmpty()) {
         if ($order->isEmpty()) {
             throw new \RuntimeException('支付订单不存在或未支付');
             throw new \RuntimeException('支付订单不存在或未支付');
         }
         }
-        return $this->uploadShippingInfoAPI($order->out_trade_no, $order->user_id, $itemDesc, $trackingNo, $expressCompany, $receiverContact, $failException);
+        return $this->uploadShippingInfoAPI($order->out_trade_no, $order->user_id, $itemDesc, $trackingNo, $expressCompany, $receiverContact, $logisticsType, $failException);
     }
     }
 
 
 
 

+ 17 - 13
src/Trait/MiniAppTrait.php

@@ -41,17 +41,19 @@ trait MiniAppTrait
      * @param string $expressCompany 物流公司编码
      * @param string $expressCompany 物流公司编码
      * @param string $receiverContact 收件人联系方式
      * @param string $receiverContact 收件人联系方式
      * @param bool $failException 是否抛出异常
      * @param bool $failException 是否抛出异常
+     * @param int $logisticsType 1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
      *
      *
      * @see 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
      * @see 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
      */
      */
     private function uploadShippingInfo(
     private function uploadShippingInfo(
         string $outTradeNo,
         string $outTradeNo,
         int    $userID,
         int    $userID,
-        string $itemDesc,
-        string $trackingNo,
-        string $expressCompany,
-        string $receiverContact,
-        bool   $failException = true
+        string $itemDesc = '',
+        string $trackingNo = '',
+        string $expressCompany = '',
+        string $receiverContact = '',
+        int $logisticsType = 1,
+        bool   $failException = true,
     ): array
     ): array
     {
     {
         $data = [
         $data = [
@@ -60,9 +62,15 @@ trait MiniAppTrait
                 'mchid' => WechatPayBuilder::getConfig()->mchid,
                 'mchid' => WechatPayBuilder::getConfig()->mchid,
                 'out_trade_no' => $outTradeNo,
                 'out_trade_no' => $outTradeNo,
             ],
             ],
-            'logistics_type' => 1, // 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
+            'logistics_type' => $logisticsType, // 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
             'delivery_mode' => 1, // 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
             'delivery_mode' => 1, // 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
-            'shipping_list' => [
+            'upload_time' => date('c'), // 上传时间,用于标识请求的先后顺序 示例值: `2022-12-15T13:29:35.120+08:00`
+            'payer' => [
+                'openid' => WechatUser::openid($userID), // 用户标识,用户在小程序appid下的唯一标识
+            ]
+        ];
+        if ($logisticsType == 1) {
+            $data['shipping_list'] = [
                 [
                 [
                     'tracking_no' => $trackingNo, // 物流单号
                     'tracking_no' => $trackingNo, // 物流单号
                     'express_company' => $expressCompany, // 物流公司编码,快递公司ID
                     'express_company' => $expressCompany, // 物流公司编码,快递公司ID
@@ -71,12 +79,8 @@ trait MiniAppTrait
                         'receiver_contact' => substr_replace($receiverContact, '****', -8, 4), // 收件人联系方式
                         'receiver_contact' => substr_replace($receiverContact, '****', -8, 4), // 收件人联系方式
                     ],
                     ],
                 ],
                 ],
-            ],
-            'upload_time' => date('c'), // 上传时间,用于标识请求的先后顺序 示例值: `2022-12-15T13:29:35.120+08:00`
-            'payer' => [
-                'openid' => WechatUser::openid($userID), // 用户标识,用户在小程序appid下的唯一标识
-            ]
-        ];
+            ];
+        }
         $response = WechatPayBuilder::getMiniApp()->getClient()->postJson('wxa/sec/order/upload_shipping_info', $data);
         $response = WechatPayBuilder::getMiniApp()->getClient()->postJson('wxa/sec/order/upload_shipping_info', $data);
         $result = $response->getContent();
         $result = $response->getContent();
         $result = json_decode($result, true);
         $result = json_decode($result, true);