Przeglądaj źródła

快递轨迹查询临时提交

eric2h 3 lat temu
rodzic
commit
4e6571536f

+ 4 - 7
app/Http/Controllers/TestController.php

@@ -15,6 +15,7 @@ use App\OrderCommodity;
 use App\Rejected;
 use App\RejectedBill;
 use App\RejectedBillItem;
+use App\Services\LogisticALiYunService;
 use App\Services\LogService;
 use App\Services\OracleDOCOrderHeaderService;
 use App\Services\OrderCommodityService;
@@ -55,13 +56,9 @@ class TestController extends Controller
     }
     public function test(Request $request)
     {
-        $req = json_decode(
-            <<<json
-{"request":[{"OrderNo":"SO220824002947","CustomerID":"HENIAN-NEW","CarrierID":"BSZFC","ConsigneeName":"\u674e\u521a","C_Tel1":"13386015319,13386015319","C_Address1":"\u6c5f\u82cf\u7701\u82cf\u5dde\u5e02\u5e38\u719f\u5e02\u83ab\u57ce\u8857\u4e1c\u8def3\u53f7\u7199\u9ea6\u957f\u4e09\u89d2\u65f6\u5c1a\u4f9b\u5e94\u94fe\u4e00\u671f3\u697c2\u53f7\u5e93","C_Province":"\u6c5f\u82cf\u7701","C_City":"\u82cf\u5dde\u5e02","C_District":"\u5e38\u719f\u5e02","ReservedField01":"199270842873-SDO516764043198","ReservedField02":null,"ReservedField03":null,"ReservedField04":null,"ReservedField05":null,"order_list":[{"SKU_Descr_c":"Vsinger \u6d1b\u5929\u4f9d 8\u738b\u9f99\u7cfb\u5217\u76d2\u86cb\uff08BOX\uff09","SKU":"6974260921198","Alternate_sku1":"6974260921198","Qtyordered_each":"108","Cubic":"0","GrossWeight":"0","NetWeight":"0","ReservedField01":null,"ReservedField02":null,"ReservedField03":null,"ReservedField04":null,"ReservedField05":null}]}]}
-json
-
-            , true);
-        dd(Http::post("https://api.baoshi56.com/oapi/device/check/waybill/create", $req)->body());
+        /** @var LogisticALiYunService $service */
+        $service  = app(LogisticALiYunService::class);
+        $service->query("78291084184840");
     }
 }
 

+ 2 - 0
app/Providers/AppServiceProvider.php

@@ -34,6 +34,7 @@ use App\Services\InventoryAccountService;
 use App\Services\InventoryCompareService;
 use App\Services\LaborCompanyDispatchDetailService;
 use App\Services\LaborReportsCountingRecordService;
+use App\Services\LogisticALiYunService;
 use App\Services\LogisticSFService;
 use App\Services\LogisticYTOService;
 use App\Services\LogisticZopService;
@@ -282,6 +283,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('LaborReportsCountingRecordService', LaborReportsCountingRecordService::class);
         app()->singleton('LogService', LogService::class);
         app()->singleton('LogisticAliJiSuApiService',LogisticAliJiSuApiService::class);
+        app()->singleton('LogisticALiYunService',LogisticALiYunService::class);
         app()->singleton('LogisticSFService', LogisticSFService::class);
         app()->singleton('LogisticService', LogisticService::class);
         app()->singleton('LogisticSyncRecordService', LogisticSyncRecordService::class);

+ 145 - 0
app/Services/LogisticALiYunService.php

@@ -0,0 +1,145 @@
+<?php
+
+namespace App\Services;
+
+use App\Traits\ServiceAppAop;
+
+class LogisticALiYunService
+{
+    use ServiceAppAop;
+
+    public function query($logistic_number)
+    {
+        $host = config('api_logistic.ALiYun.prod.search.host');
+        $path = config('api_logistic.ALiYun.prod.search.path');
+        $headers = [
+            "Authorization:APPCODE " . config('api_logistic.ALiYun.prod.app-code')
+        ];
+        $url = $host.$path.'?no='.$logistic_number;
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, config('api_logistic.ALiYun.prod.method'));
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($curl, CURLOPT_FAILONERROR, false);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($curl, CURLOPT_HEADER, true);
+        if (1 == strpos("$" . $host, "https://")) {
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        $out_put = curl_exec($curl);
+        dd($out_put);
+        $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+
+        list($header, $body) = explode("\r\n\r\n", $out_put, 2);
+        if ($httpCode == 200) {
+            print("正常请求计费(其他均不计费)<br>");
+            print($body);
+        } else {
+            if ($httpCode == 400 && strpos($header, "Invalid Param Location") !== false) {
+                print("参数错误");
+            } elseif ($httpCode == 400 && strpos($header, "Invalid AppCode") !== false) {
+                print("AppCode错误");
+            } elseif ($httpCode == 400 && strpos($header, "Invalid Url") !== false) {
+                print("请求的 Method、Path 或者环境错误");
+            } elseif ($httpCode == 403 && strpos($header, "Unauthorized") !== false) {
+                print("服务未被授权(或URL和Path不正确)");
+            } elseif ($httpCode == 403 && strpos($header, "Quota Exhausted") !== false) {
+                print("套餐包次数用完");
+            } elseif ($httpCode == 403 && strpos($header, "Api Market Subscription quota exhausted") !== false) {
+                print("套餐包次数用完,请续购套餐");
+            } elseif ($httpCode == 500) {
+                print("API网关错误");
+            } elseif ($httpCode == 0) {
+                print("URL错误");
+            } else {
+                print("参数名错误 或 其他错误");
+                print($httpCode);
+                $headers = explode("\r\n", $header);
+                $headList = array();
+                foreach ($headers as $head) {
+                    $value = explode(':', $head);
+                    $headList[$value[0]] = $value[1];
+                }
+                print($headList['x-ca-error-message']);
+            }
+        }
+    }
+
+    public function format($response, $logistic_number): array
+    {
+        $result = [];
+        if (!isset($response) || ($response && $response->status != 0)) {
+            return [
+                'logistic_number' => $logistic_number,
+            ];
+        } else {
+            try {
+                if ($response->result->number ?? false) $result['logistic_number'] = $response->result->number;
+            } catch (\Exception $e) {
+                LogService::log(LogisticYTOService::class, "AliJiSu快递信息异常", $response);
+            }
+            $list = $response->result->list;
+            if (!empty($list) && is_array($list)) {
+                $lastNativeRoute = $list[0];
+                $result['status'] = $this->getStatus($response);
+                if ($result['status'] == '已签收') $result['received_at'] = $lastNativeRoute->time;
+                $result['transfer_status'] = $this->getTransferStatus($list);
+                $result['routes_length'] = array_key_exists('transfer_status', $result) ? count($result['transfer_status']) : 0;
+            } else {
+                $result['status'] = null;
+                $result['transfer_status'] = [];
+            }
+            if (!array_key_exists('status', $result)) {
+                $result['status'] = null;
+                $result['transfer_status'] = [];
+            }
+            return $result;
+        }
+    }
+
+    /**
+     * @param $nativeData
+     * @return string
+     */
+    private function getStatus($nativeData): string
+    {
+        $status = null;
+        switch ($nativeData->result->deliverystatus) {
+            case '1':
+                $status = '在途';
+                break;
+            case '2':
+                $status = '派送中';
+                break;
+            case '3':
+                $status = '已签收';
+                break;
+            case '4':
+                $status = '派送异常';
+                break;
+            default:
+                $status = '其他';
+        }
+        return $status;
+    }
+
+    /**
+     * @param $nativeRoutes
+     * @return array
+     */
+    private function getTransferStatus($nativeRoutes): array
+    {
+        $transferStatus = [];
+        foreach ($nativeRoutes as $nativeRoute) {
+            $item = [];
+            $item['accept_time'] = $nativeRoute->time;
+            $item['accept_address'] = $nativeRoute->status;
+            $item['remark'] = "";
+            $transferStatus[] = $item;
+        }
+        return $transferStatus;
+    }
+
+
+}

+ 13 - 0
config/api_logistic.php

@@ -166,6 +166,19 @@ return [
             ],
         ],
     ],
+    'ALiYun' => [
+        'prod' => [
+            'app-key' => '203946797',
+            'app-secret' => '5jlb4OfKkVFAbEXa7ebvnSQt5wCLQqWb',
+            'app-code' => '531dca65c4df41bfaa0c58cb52f444db',
+            'type' => 'auto',
+            'method' => 'GET',
+            'search' => [
+                'host' => 'https://wuliu.market.alicloudapi.com/',
+                'path' => 'kdi',
+            ],
+        ],
+    ],
     'init_date' => '2021-05-17 23:59:59',
     'querying_days' => 15,
     'DB' => [