From 0f06a6dccf4aaba7cdac8f3a68560a92473cc81b Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 21 Dec 2020 21:51:01 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E5=A2=9E=E5=8A=A0K5=E7=89=A9=E6=B5=81?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +- src/platforms/K5Platform.php | 349 +++++++++++++++++++++++++++++ tests/platforms/K5PlatformTest.php | 78 +++++++ 3 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 src/platforms/K5Platform.php create mode 100644 tests/platforms/K5PlatformTest.php diff --git a/README.md b/README.md index 56d2707..41d6547 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Cross Border Express for Yii2 - 速递管家 - 易仓物流 - 顺丰国际物流 +- K5物流系统 [![Latest Stable Version](https://poser.pugx.org/yiier/yii2-cross-border-express/v/stable)](https://packagist.org/packages/yiier/yii2-cross-border-express) [![Total Downloads](https://poser.pugx.org/yiier/yii2-cross-border-express/downloads)](https://packagist.org/packages/yiier/yii2-cross-border-express) @@ -108,7 +109,12 @@ $config = [ "username" => "", "checkword" => "", "platform_code" => "", - ] + ], + 'k5' => [ + "host" => "", + "clientid" => "", + "token" => "", + ], ], ]; diff --git a/src/platforms/K5Platform.php b/src/platforms/K5Platform.php new file mode 100644 index 0000000..c12fb77 --- /dev/null +++ b/src/platforms/K5Platform.php @@ -0,0 +1,349 @@ + 'application/json; charset=utf8', + ]; + + $client = new \GuzzleHttp\Client([ + 'headers' => $headers, + 'timeout' => method_exists($this, 'getTimeout') ? $this->getTimeout() : 5.0, + ]); + $this->host = $this->config->get("host"); + if ($this->host == "") { + throw new ExpressException("物流代理商host不能为空"); + } + + if ($this->config->get("clientid") == "") { + throw new ExpressException("clientid不能为空"); + } + + if ($this->config->get("token") == "") { + throw new ExpressException("token不能为空"); + } + if ($this->config->get("orderType") != "") { + $this->OrderType = $this->config->get("orderType"); + } + if ($this->config->get("feePayType") != "") { + $this->FeePayType = $this->config->get("feePayType"); + } + return $client; + } + + /** + * @param string $countryCode + * @return array|void|Transport[] + */ + public function getTransportsByCountryCode(string $countryCode) + { + // TODO: Implement getTransportsByCountryCode() method. + } + + /** + * @param Order $order + * @return OrderResult + * @throws ExpressException + */ + public function createOrder(Order $order): OrderResult + { + + $parameter = $this->formatOrder($order); + + try { + $result = $this->client->post($this->host . "/PostInterfaceService?method=createOrder", [ + 'body' => json_encode($parameter, true) + ])->getBody(); + + return $this->parseResult($result); + } catch (ExpressException $exception) { + throw new ExpressException(sprintf("创建快件订单失败: %s", $exception->getMessage())); + } + } + + /** + * @inheritDoc + * @throws \OSS\Core\OssException + */ + public function getPrintUrl(string $orderNumber, array $params = []): string + { + return $this->getPrintFile($orderNumber); + } + + /** + * @param string $orderNumber + * @return string + * @throws \OSS\Core\OssException + */ + protected function getPrintFile(string $orderNumber): string + { + + $params = [ + 'OrderType'=>$this->OrderType, + 'Verify'=>$this->getVerifyData(), + 'CorpBillidDatas'=>[['CorpBillid'=>$orderNumber]] + ]; + + try { + $result = $this->client->post($this->host . "/PostInterfaceService?method=printOrderInvoice", [ + 'body' => json_encode($params, true) + ])->getBody(); + $orderInvoice = json_decode($result,true); + + if($orderInvoice['statusCode'] === 'success') { + return $orderInvoice['url']; + }else{ + throw new ExpressException(sprintf("创建包裹失败: %s", $orderInvoice['message'])); + } + } catch (ExpressException $exception) { + throw new ExpressException(sprintf("创建包裹失败: %s", $exception->getMessage())); + } + + + return ""; + } + + + /** + * @param string $orderNumber + * @return OrderFee + */ + public function getOrderFee(string $orderNumber): OrderFee + { + return new OrderFee(); + } + + /** + * @inheritDoc + */ + public function getOrderAllFee(array $query = []): array + { + return []; + } + + /** + * 验证信息 + * + * @return array + */ + private function getVerifyData(): array + { + return [ + 'Clientid'=>$this->config->get("clientid"), + 'Token'=>$this->config->get("token"), + ]; + + } + + /** + * @param string $result + * @return OrderResult + * @throws ExpressException + */ + protected function parseResult(string $result): OrderResult + { + $resData = $this->parseExpress($result); + $orderResult = new OrderResult(); + $orderResult->data = $result; + $orderResult->expressAgentNumber = !empty($resData["corpBillid"]) ? $resData["corpBillid"] : ""; + $orderResult->expressNumber = !empty($resData["customerNumber"]) ? $resData["customerNumber"] : ""; + $orderResult->expressTrackingNumber = !empty($resData["trackNumber"]) ? $resData["trackNumber"] : $this->getTracingNumber($resData["corpBillid"]); + return $orderResult; + } + + /** + * @param string $processCode + * @return string + * @throws ExpressException + */ + protected function getTracingNumber(string $processCode): string + { + + $params = [ + 'OrderType'=>$this->OrderType, + 'Verify'=>$this->getVerifyData(), + 'CorpBillidDatas'=>[['CorpBillid'=>$processCode]] + ]; + + try { + $result = $this->client->post($this->host . "/PostInterfaceService?method=searchOrderTracknumber", [ + 'body' => json_encode($params, true) + ])->getBody(); + $orderTrackNumber = json_decode($result,true); + return $orderTrackNumber[0]['trackNumber']?$orderTrackNumber[0]['trackNumber']:''; + } catch (ExpressException $exception) { + throw new ExpressException(sprintf("创建包裹失败: %s", $exception->getMessage())); + } + + return ""; + } + + /** + * @param string $result + * @return array + * @throws ExpressException + */ + protected function parseExpress(string $result): array + { + $arr = json_decode($result, true); + if (empty($arr) || !isset($arr['statusCode']) || $arr["statusCode"] !== 'success') { + throw new ExpressException('Invalid response: ' . $result, 400); + } + + if (isset($arr["returnDatas"][0]['statusCode']) && $arr["returnDatas"][0]['statusCode'] === 'error') { + throw new ExpressException($arr["returnDatas"][0]['message']); + } + + return isset($arr["returnDatas"][0]) ? $arr["returnDatas"][0] : []; + } + + /** + * 格式化所需要的数据 + * + * @param Order $orderClass + * @return array + */ + protected function formatOrder(Order $orderClass): array + { + + $items = []; + $volumes = []; + foreach ($orderClass->goods as $good) { + $items[] = [ + 'Sku'=>$good->sku, // 产品 Sku (OrderType 为仓储订单必传) + 'Cnname'=>$good->cnDescription, // 产品中文名 + 'Enname'=>$good->description, // 产品英文名 + 'Price'=>$good->worth, // 单价 + 'SingleWeight'=>$good->weight, // 单件重量 + 'Num'=>$good->quantity, // 数量 + ]; + $volumes[] = [ + 'Weight'=> $good->weight, // 实重 + 'Number'=>$good->quantity, // 件数 + 'Length'=>$good->length, // 长 + 'Width'=>$good->width, // 宽 + 'Height'=> $good->height, // 高 + + ]; + + } + + return [ + 'Verify' => $this->getVerifyData(), + 'OrderType'=>$this->OrderType, + 'OrderDatas'=>[[ + 'CustomerNumber'=>$orderClass->customerOrderNo, // 客户订单号(可传入贵公司内部单号) + 'ChannelCode'=>$orderClass->transportCode, // 渠道代码可调用[searchStartChannel]方法获取 + 'CountryCode'=>$orderClass->recipient->countryCode, // 国家二字代码 + 'TotalWeight'=>$orderClass->package->weight, // 订单总重量 + 'TotalValue'=>$orderClass->package->declareWorth, // 订单总申报价值 + 'Number'=>$orderClass->package->quantity, // 件数 + 'Recipient'=>[ + 'Name'=>$orderClass->recipient->name, // 名称 + 'Company'=>$orderClass->recipient->company, + 'Addres1'=>$orderClass->recipient->address, // 电话 + 'Addres2'=> $orderClass->recipient->doorplate, // 电话 + 'Tel'=> $orderClass->recipient->phone, // 电话 + 'Province'=>$orderClass->recipient->state, // 省州 + 'City'=>$orderClass->recipient->city, // 城市 + 'Post'=>$orderClass->recipient->zip, // 邮编 + ], + 'Sender'=>[ + 'Name'=>$orderClass->shipper->name, // 名称 + 'Company'=>$orderClass->shipper->company, + 'Addres'=>$orderClass->shipper->address, // 电话 + 'Country'=> $orderClass->shipper->countryCode, // 国家 + 'Mobile'=> $orderClass->shipper->phone, // 电话 + 'Tel'=> $orderClass->shipper->Tel, // 电话 + 'Province'=>$orderClass->shipper->state, // 省州 + 'City'=>$orderClass->shipper->city, // 城市 + 'Post'=>$orderClass->shipper->zip, // 邮编 + ], + + 'OrderItems'=>$items, // 订单明细产品信息 + + 'Volumes'=>$volumes, // 材积明细 (OrderType 为快递制单必传) + + 'FeePayData'=>[ + 'FeePayType'=>$this->FeePayType, // 支付方式[ PP:预付,CC:到付, TP:第三方]必传 + ], + + + ]], + + + + + + + + + ]; + } + + /** + * 获取启用得入仓渠道 + * + * + */ + public function searchStartChannel() + { + + try { + $result = $this->client->post($this->host . "/PostInterfaceService?method=searchStartChannel", [ + 'body' => json_encode(['Verify' => $this->getVerifyData()], true) + ])->getBody(); + return $this->parseResult($result); + } catch (ExpressException $exception) { + throw new ExpressException(sprintf("创建包裹失败: %s", $exception->getMessage())); + } + } +} diff --git a/tests/platforms/K5PlatformTest.php b/tests/platforms/K5PlatformTest.php new file mode 100644 index 0000000..22392dd --- /dev/null +++ b/tests/platforms/K5PlatformTest.php @@ -0,0 +1,78 @@ + 60.0, + "platforms" => [ + \yiier\crossBorderExpress\platforms\PlatformsName::K5_PLATFORM => [ + "host" => "http://cje56.kingtrans.net", + "clientid" => "KLXX", + "token" => "9868p7SfORYS4d1wFm9L", + //"warehouse_code" => "SZ" + ] + ] + ]; + + + public function testGetOrderFee() + { + + } + + public function testGetTransportsByCountryCode() + { + + } + + public function testGetPrintUrl() + { + $express = new Express($this->config, PlatformsName::K5_PLATFORM); + $res = $express->getPrintUrl("EYT0122169080SZ"); + var_dump($res); + + } + + public function testCreateOrder() + { + $express = new Express($this->config, PlatformsName::K5_PLATFORM); + try { + $orderResult = $express->createOrder($this->getExpressOrder()); + + var_dump($orderResult->expressNumber); + + } catch (\Exception $e) { + $this->expectException($e->getMessage()); + } + } + + public function testGetOrderAllFee() + { + + } +} From 51b95d788ede3168c8700429a43669ea08ea0e70 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 22 Dec 2020 13:44:42 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E5=A2=9E=E5=8A=A0K5=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/platforms/PlatformsName.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/platforms/PlatformsName.php b/src/platforms/PlatformsName.php index 78e5299..f902bba 100644 --- a/src/platforms/PlatformsName.php +++ b/src/platforms/PlatformsName.php @@ -21,4 +21,5 @@ class PlatformsName const COURIERBUTLER_PLATFORM = "courierbutler"; const ECCANG_PLATFORM = "eccang"; const SFEXPRESS_PLATFORM = "sfexpress"; + const SFEXPRESS_PLATFORM = "k5"; } From 65cdf849a1adaa0726534579774f6c07bddb13f5 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 22 Dec 2020 14:17:21 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9K5names=20=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E4=BB=A3=E7=A0=81=E9=94=99=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/platforms/PlatformsName.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/PlatformsName.php b/src/platforms/PlatformsName.php index f902bba..63f4878 100644 --- a/src/platforms/PlatformsName.php +++ b/src/platforms/PlatformsName.php @@ -21,5 +21,5 @@ class PlatformsName const COURIERBUTLER_PLATFORM = "courierbutler"; const ECCANG_PLATFORM = "eccang"; const SFEXPRESS_PLATFORM = "sfexpress"; - const SFEXPRESS_PLATFORM = "k5"; + const K5_PLATFORM = "k5"; } From e9b69e977c9c9100d450d1949ba28845073a5d30 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 22 Dec 2020 17:22:16 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=20K5=E6=9D=B0?= =?UTF-8?q?=E8=88=AA=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/platforms/K5PlatformTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/platforms/K5PlatformTest.php b/tests/platforms/K5PlatformTest.php index 22392dd..c06f26f 100644 --- a/tests/platforms/K5PlatformTest.php +++ b/tests/platforms/K5PlatformTest.php @@ -12,7 +12,7 @@ require_once("../../vendor/autoload.php"); -require_once("D:/phpstudy_pro/WWW/ft-erp/vendor/yiier/yii2-cross-border-express/tests/PHPUnit_Framework_TestCase.php"); +require_once("../PHPUnit_Framework_TestCase.php"); use yiier\crossBorderExpress\test; use yiier\crossBorderExpress\contracts\Goods; use yiier\crossBorderExpress\contracts\Order; @@ -31,9 +31,9 @@ class K5PlatformTest extends \PHPUnit_Framework_TestCase "timeout" => 60.0, "platforms" => [ \yiier\crossBorderExpress\platforms\PlatformsName::K5_PLATFORM => [ - "host" => "http://cje56.kingtrans.net", - "clientid" => "KLXX", - "token" => "9868p7SfORYS4d1wFm9L", + "host" => "http://xt.jiehang.net", + "clientid" => "KLXX008", + "token" => "IPLLEx18PbUSd8Fygejo", //"warehouse_code" => "SZ" ] ] @@ -62,6 +62,7 @@ public function testCreateOrder() { $express = new Express($this->config, PlatformsName::K5_PLATFORM); try { + //var_dump($express->searchStartChannel());exit; $orderResult = $express->createOrder($this->getExpressOrder()); var_dump($orderResult->expressNumber); From 6a5de8a3f22efae3d52d54a7e241be0cfb3c273d Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 23 Dec 2020 06:57:45 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E5=8E=BB=E6=8E=89=20=E6=97=A0=E6=95=88?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/platforms/K5Platform.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/platforms/K5Platform.php b/src/platforms/K5Platform.php index c12fb77..9bff43a 100644 --- a/src/platforms/K5Platform.php +++ b/src/platforms/K5Platform.php @@ -268,9 +268,9 @@ protected function formatOrder(Order $orderClass): array $volumes[] = [ 'Weight'=> $good->weight, // 实重 'Number'=>$good->quantity, // 件数 - 'Length'=>$good->length, // 长 - 'Width'=>$good->width, // 宽 - 'Height'=> $good->height, // 高 + //'Length'=>$good->length, // 长 + //'Width'=>$good->width, // 宽 + //'Height'=> $good->height, // 高 ]; @@ -302,7 +302,7 @@ protected function formatOrder(Order $orderClass): array 'Addres'=>$orderClass->shipper->address, // 电话 'Country'=> $orderClass->shipper->countryCode, // 国家 'Mobile'=> $orderClass->shipper->phone, // 电话 - 'Tel'=> $orderClass->shipper->Tel, // 电话 + 'Tel'=> $orderClass->shipper->phone, // 电话 'Province'=>$orderClass->shipper->state, // 省州 'City'=>$orderClass->shipper->city, // 城市 'Post'=>$orderClass->shipper->zip, // 邮编 From 60c888173e50c185057b5f97dea15f411c0ed424 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 24 Dec 2020 12:05:08 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9K5=E7=B3=BB=E7=BB=9F=20?= =?UTF-8?q?=E9=9D=A2=E5=8D=95=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/platforms/K5Platform.php | 61 ++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/src/platforms/K5Platform.php b/src/platforms/K5Platform.php index 9bff43a..438d265 100644 --- a/src/platforms/K5Platform.php +++ b/src/platforms/K5Platform.php @@ -115,7 +115,8 @@ public function createOrder(Order $order): OrderResult */ public function getPrintUrl(string $orderNumber, array $params = []): string { - return $this->getPrintFile($orderNumber); + + return $this->getPrintFile($orderNumber,$params['channelCode']); } /** @@ -123,17 +124,23 @@ public function getPrintUrl(string $orderNumber, array $params = []): string * @return string * @throws \OSS\Core\OssException */ - protected function getPrintFile(string $orderNumber): string + protected function getPrintFile(string $orderNumber,$channelCode): string { + $PrintPaper = $this->searchPrintPaper($channelCode); + + $params = [ 'OrderType'=>$this->OrderType, 'Verify'=>$this->getVerifyData(), - 'CorpBillidDatas'=>[['CorpBillid'=>$orderNumber]] + 'CorpBillidDatas'=>[['CorpBillid'=>$orderNumber]], + 'OrderType'=>$this->OrderType, + 'PrintPaper'=>$PrintPaper, + 'PrintContent'=>1 ]; try { - $result = $this->client->post($this->host . "/PostInterfaceService?method=printOrderInvoice", [ + $result = $this->client->post($this->host . "/PostInterfaceService?method=printOrderLabel", [ 'body' => json_encode($params, true) ])->getBody(); $orderInvoice = json_decode($result,true); @@ -169,6 +176,40 @@ public function getOrderAllFee(array $query = []): array return []; } + /** + * 查询渠道纸张代码 + * + * @param [type] $channelCode + * @return void + */ + public function searchPrintPaper($channelCode) + { + if(!$channelCode){ + throw new ExpressException("打印面单失败: 渠道码错误-".$channelCode); + } + $params = [ + 'Verify'=>$this->getVerifyData(), + 'ChannelCode'=>$channelCode + ]; + + try { + $result = $this->client->post($this->host . "/PostInterfaceService?method=searchPrintPaper", [ + 'body' => json_encode($params, true) + ])->getBody(); + $PrintPaper = json_decode($result,true); + if($PrintPaper['statusCode'] === 'success') { + return $PrintPaper['returnDatas'][0]['paperCode']; + }else{ + throw new ExpressException(sprintf("打印面单失败: %s", $PrintPaper['message'])); + } + //echo '
';var_dump($PrintPaper);exit;
+        } catch (ExpressException $exception) {
+            throw new ExpressException(sprintf("打印面单失败: %s", $exception->getMessage()));
+        }
+
+        return "";
+    }
+
     /**
      * 验证信息
      *
@@ -193,8 +234,8 @@ protected function parseResult(string $result): OrderResult
         $resData = $this->parseExpress($result);
         $orderResult = new OrderResult();
         $orderResult->data = $result;
-        $orderResult->expressAgentNumber = !empty($resData["corpBillid"]) ? $resData["corpBillid"] : "";
-        $orderResult->expressNumber = !empty($resData["customerNumber"]) ? $resData["customerNumber"] : "";
+        $orderResult->expressAgentNumber = !empty($resData["customerNumber"]) ? $resData["customerNumber"] : "";
+        $orderResult->expressNumber = !empty($resData["corpBillid"]) ? $resData["corpBillid"] : "";
         $orderResult->expressTrackingNumber = !empty($resData["trackNumber"]) ? $resData["trackNumber"] : $this->getTracingNumber($resData["corpBillid"]);
         return $orderResult;
     }
@@ -268,9 +309,9 @@ protected function formatOrder(Order $orderClass): array
             $volumes[] = [
                 'Weight'=> $good->weight, // 实重
                 'Number'=>$good->quantity, //  件数
-                //'Length'=>$good->length, //  长
-                //'Width'=>$good->width, // 宽
-                //'Height'=> $good->height, // 高
+                // 'Length'=>$good->length, //  长
+                // 'Width'=>$good->width, // 宽
+                // 'Height'=> $good->height, // 高
                 
             ];
             
@@ -341,7 +382,7 @@ public function searchStartChannel()
              $result = $this->client->post($this->host . "/PostInterfaceService?method=searchStartChannel", [
                  'body' => json_encode(['Verify' => $this->getVerifyData()], true)
              ])->getBody();
-             return $this->parseResult($result);
+             return json_decode($result,true);
          } catch (ExpressException $exception) {
              throw new ExpressException(sprintf("创建包裹失败: %s", $exception->getMessage()));
          }

From 508b7cfba19361a8073ed1db6ad1ab8741113baa Mon Sep 17 00:00:00 2001
From: andy 
Date: Fri, 25 Dec 2020 10:47:46 +0800
Subject: [PATCH 07/10] =?UTF-8?q?=E9=A3=9E=E7=89=B9=E7=89=A9=E6=B5=81=20?=
 =?UTF-8?q?=E8=BF=94=E5=9B=9Eunauthorized=5Fclient=20=E9=94=99=E8=AF=AF?=
 =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E4=B8=80=E8=88=AC=E6=98=AF=E5=9B=A0?=
 =?UTF-8?q?=E4=B8=BAtoken=E8=BF=87=E6=9C=9F=E5=AF=BC=E8=87=B4=20=E6=89=80?=
 =?UTF-8?q?=E4=BB=A5=E5=BC=BA=E8=A1=8C=E6=B8=85=E9=99=A4=E4=B8=80=E4=B8=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/platforms/FeitePlatform.php | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/platforms/FeitePlatform.php b/src/platforms/FeitePlatform.php
index 9300684..3676cda 100644
--- a/src/platforms/FeitePlatform.php
+++ b/src/platforms/FeitePlatform.php
@@ -119,6 +119,12 @@ public function getPrintUrl(string $orderNumber, array $params = []): string
         $response = $this->client->post($api, $body);
 
         $result = json_decode($response->getBody(), true);
+        
+        // 返回unauthorized_client 错误的时候一般是因为token过期导致 所以强行清除一下
+        if($result['Status'] === 0 && $result['ErrCode'] === 'unauthorized_client') {
+            $cache = \Yii::$app->cache;
+            $cache->delete(self::CACHE_KEY_FEITE_ACCESS_TOKEN);
+        }
 
         try {
             $b64 = $result['Data']['Label'];

From e1ac4605c7f53dcafa0db36db14c1d25d37ed38d Mon Sep 17 00:00:00 2001
From: andy 
Date: Thu, 31 Dec 2020 11:58:50 +0800
Subject: [PATCH 08/10] =?UTF-8?q?=E7=BA=B5=E6=A8=AA=E7=89=A9=E6=B5=81=20?=
 =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E8=B7=9F=E8=B8=AA=E5=8F=B7?=
 =?UTF-8?q?=20=E6=96=B9=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/platforms/CourierbutlerPlatform.php | 39 +++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/src/platforms/CourierbutlerPlatform.php b/src/platforms/CourierbutlerPlatform.php
index 2c1a970..0f5c88e 100644
--- a/src/platforms/CourierbutlerPlatform.php
+++ b/src/platforms/CourierbutlerPlatform.php
@@ -35,6 +35,37 @@ public function getClient()
         return $client;
     }
 
+
+    /**
+     * @param string $refrence_no 客户参考号
+     * @return string
+     * @throws ExpressException
+     */
+    public function getTracingNumber(string $refrence_no): string
+    {
+
+
+        $this->body["serviceMethod"] = "gettrackingnumber";
+        $this->body["paramsJson"] = json_encode([
+            'reference_no'=>$refrence_no
+        ], true);
+        try {
+            $result = $this->client->post($this->host . "/webservice/PublicService.asmx/ServiceInterfaceUTF8", [
+                'form_params' => $this->body,
+            ])->getBody();
+            $data = $this->parseResult($result);
+            //var_dump($data);exit;
+            return $data['shipping_method_no']?$data['shipping_method_no']:'';
+        } catch (ExpressException $exception) {
+            throw new ExpressException(sprintf("获取转单号失败: %s", $exception->getMessage()));
+        }
+
+        return "";
+    }
+
+
+
+
     /**
      * @param string $countryCode
      * @return array|Transport[]
@@ -59,7 +90,8 @@ public function createOrder(Order $order): OrderResult
             $orderResult = new OrderResult();
             $orderResult->data = json_encode($resData, true);
             $orderResult->expressNumber = !empty($resData["refrence_no"]) ? $resData["refrence_no"] : "";
-            $orderResult->expressTrackingNumber = !empty($resData["shipping_method_no"]) ? $resData["shipping_method_no"] : "";
+            $orderResult->expressTrackingNumber = !empty($resData["shipping_method_no"]) ? $resData["shipping_method_no"] : "";;
+            $orderResult->expressAgentNumber = !empty($resData["shipping_method_no"]) ? $resData["shipping_method_no"] : "";
             return $orderResult;
         } catch (ExpressException $exception) {
             throw new ExpressException(sprintf("创建包裹失败: %s", $exception->getMessage()));
@@ -129,7 +161,10 @@ public function getOrderAllFee(array $query = []): array
     protected function parseResult(string $result)
     {
         $res = json_decode($result, true);
-        if ($res["success"] == 1) {
+        if(!is_array($res)) {
+            throw new ExpressException('接口返回数据异常');
+        }
+        if (isset($res["success"]) && $res["success"] == 1) {
             return $res["data"];
         } else {
             throw new ExpressException($res["cnmessage"]);

From 38179ea6d759b59373a158b8651e9b26ca4e83a3 Mon Sep 17 00:00:00 2001
From: andy 
Date: Thu, 4 Feb 2021 11:59:26 +0800
Subject: [PATCH 09/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20k5=E5=B7=9D=E6=97=A5?=
 =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=89=A9=E6=B5=81=E6=8A=A5=E9=94=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/platforms/K5Platform.php | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/src/platforms/K5Platform.php b/src/platforms/K5Platform.php
index 9bff43a..1003224 100644
--- a/src/platforms/K5Platform.php
+++ b/src/platforms/K5Platform.php
@@ -255,24 +255,15 @@ protected function formatOrder(Order $orderClass): array
     {
         
         $items = [];
-        $volumes = [];
         foreach ($orderClass->goods as $good) {
             $items[] = [
-                'Sku'=>$good->sku, // 产品 Sku (OrderType 为仓储订单必传)
+                'Sku'=>is_null($good->sku)?'':$good->sku, // 产品 Sku (OrderType 为仓储订单必传)
                 'Cnname'=>$good->cnDescription, //  产品中文名
                 'Enname'=>$good->description, // 产品英文名
                 'Price'=>$good->worth, // 单价
                 'SingleWeight'=>$good->weight, // 单件重量
                 'Num'=>$good->quantity, // 数量
             ];
-            $volumes[] = [
-                'Weight'=> $good->weight, // 实重
-                'Number'=>$good->quantity, //  件数
-                //'Length'=>$good->length, //  长
-                //'Width'=>$good->width, // 宽
-                //'Height'=> $good->height, // 高
-                
-            ];
             
         }
 
@@ -287,10 +278,10 @@ protected function formatOrder(Order $orderClass): array
                 'TotalValue'=>$orderClass->package->declareWorth, // 订单总申报价值
                 'Number'=>$orderClass->package->quantity, // 件数
                 'Recipient'=>[
-                    'Name'=>$orderClass->recipient->name, // 名称
-                    'Company'=>$orderClass->recipient->company,
-                    'Addres1'=>$orderClass->recipient->address, // 电话
-                    'Addres2'=> $orderClass->recipient->doorplate, // 电话
+                    'Name'=>is_null($orderClass->recipient->name)?'':$orderClass->recipient->name, // 名称
+                    'Company'=>is_null($orderClass->recipient->company)?'':$orderClass->recipient->company,
+                    'Addres1'=>is_null($orderClass->recipient->address)?'':$orderClass->recipient->address, // 地址1
+                    'Addres2'=>is_null($orderClass->recipient->doorplate)?'':$orderClass->recipient->doorplate, // 地址2
                     'Tel'=> $orderClass->recipient->phone, // 电话
                     'Province'=>$orderClass->recipient->state, // 省州
                     'City'=>$orderClass->recipient->city, // 城市
@@ -298,8 +289,8 @@ protected function formatOrder(Order $orderClass): array
                 ],
                 'Sender'=>[
                     'Name'=>$orderClass->shipper->name, // 名称
-                    'Company'=>$orderClass->shipper->company,
-                    'Addres'=>$orderClass->shipper->address, // 电话
+                    'Company'=>is_null($orderClass->shipper->company)?'':$orderClass->shipper->company,
+                    'Addres'=>is_null($orderClass->shipper->address)?'':$orderClass->shipper->address, // 地址
                     'Country'=> $orderClass->shipper->countryCode, // 国家
                     'Mobile'=> $orderClass->shipper->phone, // 电话
                     'Tel'=> $orderClass->shipper->phone, // 电话
@@ -310,8 +301,6 @@ protected function formatOrder(Order $orderClass): array
                
                 'OrderItems'=>$items, // 订单明细产品信息
     
-                'Volumes'=>$volumes, // 材积明细 (OrderType 为快递制单必传)   
-
                 'FeePayData'=>[
                     'FeePayType'=>$this->FeePayType, // 支付方式[ PP:预付,CC:到付, TP:第三方]必传
                 ],

From aa709a27666b425fb4b8f864f5200b0597719e6a Mon Sep 17 00:00:00 2001
From: andy 
Date: Fri, 19 Mar 2021 15:50:15 +0800
Subject: [PATCH 10/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9k5=E9=80=82=E9=85=8D=20?=
 =?UTF-8?q?=E5=85=AB=E7=88=AA=E9=B1=BC=E7=89=A9=E6=B5=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/platforms/K5Platform.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/platforms/K5Platform.php b/src/platforms/K5Platform.php
index e0808b7..47b6c7f 100644
--- a/src/platforms/K5Platform.php
+++ b/src/platforms/K5Platform.php
@@ -97,7 +97,6 @@ public function createOrder(Order $order): OrderResult
     {
 
         $parameter = $this->formatOrder($order);
-
         try {
             $result = $this->client->post($this->host . "/PostInterfaceService?method=createOrder", [
                 'body' => json_encode($parameter, true)
@@ -326,6 +325,7 @@ protected function formatOrder(Order $orderClass): array
                     'Province'=>$orderClass->recipient->state, // 省州
                     'City'=>$orderClass->recipient->city, // 城市
                     'Post'=>$orderClass->recipient->zip, // 邮编
+                    'Email'=>$orderClass->recipient->email
                 ],
                 'Sender'=>[
                     'Name'=>$orderClass->shipper->name, // 名称
@@ -337,6 +337,7 @@ protected function formatOrder(Order $orderClass): array
                     'Province'=>$orderClass->shipper->state, // 省州
                     'City'=>$orderClass->shipper->city, // 城市
                     'Post'=>$orderClass->shipper->zip, // 邮编
+                    'Email'=>$orderClass->shipper->email
                 ],
                
                 'OrderItems'=>$items, // 订单明细产品信息