ソースを参照

1. 跑腿的http post 请求的 Content-Type 默认统一为 application/json;charset=utf-8
2. 修复闪送回调中的bug

shizhongqi 7 ヶ月 前
コミット
1170ad4a75

+ 6 - 3
common/components/delivery/helpers/HttpClient.php

@@ -16,7 +16,7 @@ class HttpClient
     public static function post(string $url, array $data = [], array $headers = [], int $retry = 1)
     {
         $client = new Client([
-            'timeout' => 8.0,
+            'timeout' => 10.0,
             'verify' => false, // 禁用 SSL 证书验证(测试环境可用)
         ]);
 
@@ -24,7 +24,7 @@ class HttpClient
         //     'Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8',
         // ], $headers);
         $headers = array_merge([
-            'Content-Type' => 'application/json',
+            'Content-Type' => 'application/json;charset=utf-8',
         ], $headers);
 
         // 根据 Content-Type 决定请求体格式
@@ -173,8 +173,11 @@ class HttpClient
                 continue;
             }
 
+            //$headers = array_merge([
+                //'Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8',
+            //], $headers);
             $headers = array_merge([
-                'Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8',
+                'Content-Type' => 'application/json;charset=utf-8',
             ], $headers);
 
             // 根据 Content-Type 决定请求体格式

+ 1 - 1
common/components/delivery/platform/shansong/OrderStatusCallBack.php

@@ -39,7 +39,7 @@ class OrderStatusCallBack
             
             // 查找配送订单
             $deliveryOrder = $this->getDeliveryOrder($data['issOrderNo']);
-            if (!$deliveryOrder) {
+            if ($deliveryOrder === null) {
                 Yii::error('闪送订单不存在: issOrderNo=' . $data['issOrderNo'], 'shansong-callback');
                 return false;
             }

+ 2 - 3
common/components/delivery/services/adapter/ShansongAdapter.php

@@ -18,9 +18,8 @@ class ShansongAdapter extends Shansong implements Adapter
 
         $sign = SignHelper::makeSign($payload, $this->appSecret, 'md5', true, 'shansong');
         $payload['sign'] = $sign;
-        $header = ["Content-Type" => "application/x-www-form-urlencoded;charset=utf-8"];
-
-        $resp = HttpClient::post("{$this->baseUrl}/openapi/developer/v5/openCitiesLists", $payload, $header);
+        $headers = ["Content-Type" => "application/x-www-form-urlencoded;charset=utf-8"];
+        $resp = HttpClient::post("{$this->baseUrl}/openapi/developer/v5/openCitiesLists", $payload, $headers);
 
         $newCitiesArr = [];
         $citiesArr = $resp['data'];