diff --git a/src/Exceptions/Exception.php b/src/Exceptions/Exception.php index 5c36902..86503a8 100644 --- a/src/Exceptions/Exception.php +++ b/src/Exceptions/Exception.php @@ -1,19 +1,25 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Overbeck\Logistics\Exceptions; - /** - * 异常基类 + * 异常基类. * * Class Exception * Author ShuQingZai * DateTime 2020/7/31 16:07 - * - * @package Overbeck\Logistics\Exceptions */ class Exception extends \Exception { -} \ No newline at end of file +} diff --git a/src/Exceptions/GatewayAvailableException.php b/src/Exceptions/GatewayAvailableException.php index efc0815..98ec14a 100644 --- a/src/Exceptions/GatewayAvailableException.php +++ b/src/Exceptions/GatewayAvailableException.php @@ -1,22 +1,27 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Overbeck\Logistics\Exceptions; - use Overbeck\Logistics\Interfaces\GatewayAvailableInterface; use Throwable; - /** - * 网关可用异常 + * 网关可用异常. * * Class GatewayAvailableException * Author ShuQingZai * DateTime 2020/7/31 16:07 - * - * @package Overbeck\Logistics\Exceptions */ class GatewayAvailableException extends Exception implements GatewayAvailableInterface { @@ -26,24 +31,18 @@ class GatewayAvailableException extends Exception implements GatewayAvailableInt public function __construct(array $results = [], $code = 0, Throwable $previous = null) { - $this->results = $results; + $this->results = $results; $this->exceptions = \array_column($results, 'exception', 'gateway'); parent::__construct('The gateways have failed. You can check "\Overbeck\Logistics\Interfaces\GatewayAvailableInterface" to get the results', $code, $previous); } - - /** - * @return array - */ public function getResults(): array { return $this->results; } /** - * @param string $gateway - * * @return mixed|null */ public function getException(string $gateway) @@ -51,9 +50,6 @@ public function getException(string $gateway) return isset($this->exceptions[$gateway]) ? $this->exceptions[$gateway] : null; } - /** - * @return array - */ public function getExceptions(): array { return $this->exceptions; @@ -66,5 +62,4 @@ public function getLastException() { return end($this->exceptions); } - -} \ No newline at end of file +} diff --git a/src/Exceptions/GatewayErrorException.php b/src/Exceptions/GatewayErrorException.php index f30ee22..43cfc5d 100644 --- a/src/Exceptions/GatewayErrorException.php +++ b/src/Exceptions/GatewayErrorException.php @@ -1,18 +1,24 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Overbeck\Logistics\Exceptions; - /** - * 网关发生错误异常 + * 网关发生错误异常. * * Class GatewayErrorException * Author ShuQingZai * DateTime 2020/7/31 16:08 - * - * @package Overbeck\Logistics\Exceptions */ class GatewayErrorException extends Exception { @@ -25,11 +31,8 @@ public function __construct(string $message, int $code = 0, array $raw = []) parent::__construct($message, $code); } - /** - * @return array - */ public function getRaw(): array { return $this->raw; } -} \ No newline at end of file +} diff --git a/src/Exceptions/InvalidArgumentException.php b/src/Exceptions/InvalidArgumentException.php index 6843bb9..88d380c 100644 --- a/src/Exceptions/InvalidArgumentException.php +++ b/src/Exceptions/InvalidArgumentException.php @@ -1,20 +1,25 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Overbeck\Logistics\Exceptions; - /** - * 参数异常 + * 参数异常. * * Class InvalidArgumentException * Author ShuQingZai * DateTime 2020/7/31 16:08 - * - * @package Overbeck\Logistics\Exceptions */ class InvalidArgumentException extends Exception { - -} \ No newline at end of file +} diff --git a/src/Gateways/GatewayAbstract.php b/src/Gateways/GatewayAbstract.php index 9e5efe6..9f5a6d5 100644 --- a/src/Gateways/GatewayAbstract.php +++ b/src/Gateways/GatewayAbstract.php @@ -1,10 +1,18 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Overbeck\Logistics\Gateways; - use Psr\Http\Message\ResponseInterface; use Overbeck\Logistics\Exceptions\GatewayErrorException; use Overbeck\Logistics\Exceptions\InvalidArgumentException; @@ -13,15 +21,12 @@ use Overbeck\Logistics\Supports\Config; use Overbeck\Logistics\Traits\HasHttpRequest; - /** - * 网关基类 + * 网关基类. * * Class GatewayAbstract * Author ShuQingZai * DateTime 2020/7/31 16:08 - * - * @package Overbeck\Logistics\Gateways */ abstract class GatewayAbstract implements GatewayInterface { @@ -54,106 +59,95 @@ abstract class GatewayAbstract implements GatewayInterface const LOGISTICS_DELIVERY_FAILED = 10; const LOGISTICS_DESCRIPTION = [ - self::LOGISTICS_ERROR => '快递查询异常', - self::LOGISTICS_TAKING => '快递收件(揽件)', - self::LOGISTICS_IN_TRANSIT => '运输中', - self::LOGISTICS_DELIVERING => '派件中', - self::LOGISTICS_SIGNED => '已签收', - self::LOGISTICS_PROBLEM => '疑难件', - self::LOGISTICS_RETURN_RECEIPT => '退件签收', - self::LOGISTICS_REJECTED => '拒签', - self::LOGISTICS_SEND_RETURN => '退回', - self::LOGISTICS_TIMEOUT => '超时件', + self::LOGISTICS_ERROR => '快递查询异常', + self::LOGISTICS_TAKING => '快递收件(揽件)', + self::LOGISTICS_IN_TRANSIT => '运输中', + self::LOGISTICS_DELIVERING => '派件中', + self::LOGISTICS_SIGNED => '已签收', + self::LOGISTICS_PROBLEM => '疑难件', + self::LOGISTICS_RETURN_RECEIPT => '退件签收', + self::LOGISTICS_REJECTED => '拒签', + self::LOGISTICS_SEND_RETURN => '退回', + self::LOGISTICS_TIMEOUT => '超时件', self::LOGISTICS_DELIVERY_FAILED => '派送失败', ]; /** - * 配置 + * 配置. * - * @var Config $config - * DateTime 2020/7/29 15:17 - * @package Overbeck\Logistics\Gateways\Gateway + * @var Config + * DateTime 2020/7/29 15:17 */ protected $config; /** - * guzzleHttp配置信息 + * guzzleHttp配置信息. * - * @var array $httpOptions - * DateTime 2020/7/29 15:20 - * @package Overbeck\Logistics\Gateways\Gateway + * @var array + * DateTime 2020/7/29 15:20 */ protected $httpOptions; /** - * 请求超时时间 + * 请求超时时间. * - * @var $timeout + * @var * DateTime 2020/7/29 15:49 - * @package Overbeck\Logistics\Gateways\Gateway */ protected $timeout; /** - * 响应超时时间 + * 响应超时时间. * - * @var $connectTimeout + * @var * DateTime 2020/7/29 15:53 - * @package Overbeck\Logistics\Gateways\Gateway */ protected $connectTimeout; /** - * 物流公司名称 + * 物流公司名称. * - * @var string $companyName - * DateTime 2020/7/30 15:27 - * @package Overbeck\Logistics\Gateways\GatewayAbstract + * @var string + * DateTime 2020/7/30 15:27 */ protected $companyName = ''; /** - * 物流公司列表 + * 物流公司列表. * - * @var array $companyList - * DateTime 2020/7/30 17:11 - * @package Overbeck\Logistics\Gateways\GatewayAbstract + * @var array + * DateTime 2020/7/30 17:11 */ protected $companyList = []; /** - * 格式化响应数据 + * 格式化响应数据. * * Author ShuQingZai * DateTime 2020/7/30 14:22 * * @param ResponseInterface|array|string $response 原始响应数据 - * @return array + * * @throws GatewayErrorException */ abstract protected function formatData($response): array; /** - * 统一格式化物流状态code + * 统一格式化物流状态code. * * Author ShuQingZai * DateTime 2020/7/30 11:28 * * @param int|string $originalStatus 请求响应中返回的状态 - * @return int */ abstract protected function formatStatus($originalStatus): int; - public function __construct(array $config) { $this->setConfig($config) ->setHttpOptions($this->config->get('http', [])); } - /** - * @return Config - */ public function getConfig(): Config { return $this->config; @@ -161,6 +155,7 @@ public function getConfig(): Config /** * @param array|Config $config + * * @return GatewayAbstract */ public function setConfig($config) @@ -170,24 +165,18 @@ public function setConfig($config) return $this; } - /** - * @return array - */ public function getHttpOptions(): array { return $this->httpOptions; } - /** - * @return array - */ public function getGuzzleOptions(): array { return $this->getHttpOptions(); } /** - * 获取请求超时时间 + * 获取请求超时时间. * * Author ShuQingZai * DateTime 2020/7/29 16:05 @@ -200,12 +189,11 @@ public function getTimeout() } /** - * 设置请求超时时间 + * 设置请求超时时间. * * Author ShuQingZai * DateTime 2020/7/29 16:05 * - * @param float $timeout * @return $this */ public function setTimeout(float $timeout) @@ -216,7 +204,7 @@ public function setTimeout(float $timeout) } /** - * 获取响应超时时间 + * 获取响应超时时间. * * Author ShuQingZai * DateTime 2020/7/29 16:06 @@ -229,12 +217,11 @@ public function getConnectTimeout() } /** - * 设置响应超时时间 + * 设置响应超时时间. * * Author ShuQingZai * DateTime 2020/7/29 16:03 * - * @param float $connectTimeout * @return $this */ public function setConnectTimeout(float $connectTimeout) @@ -244,9 +231,7 @@ public function setConnectTimeout(float $connectTimeout) return $this; } - /** - * @param array $httpOptions * @return GatewayAbstract */ public function setHttpOptions(array $httpOptions) @@ -258,16 +243,14 @@ public function setHttpOptions(array $httpOptions) public function getGatewayName(): string { - return \strtolower(\str_replace([__NAMESPACE__ . '\\', 'Gateway'], '', \get_class($this))); + return \strtolower(\str_replace([__NAMESPACE__.'\\', 'Gateway'], '', \get_class($this))); } /** - * 获取物流公司信息 + * 获取物流公司信息. * * Author ShuQingZai * DateTime 2020/7/31 17:29 - * - * @return array */ public function getCompanyList(): array { @@ -275,13 +258,10 @@ public function getCompanyList(): array } /** - * 设置物流公司信息 + * 设置物流公司信息. * * Author ShuQingZai * DateTime 2020/7/31 17:26 - * - * @param array $companyList - * @return GatewayInterface */ public function setCompanyList(array $companyList): GatewayInterface { @@ -290,15 +270,11 @@ public function setCompanyList(array $companyList): GatewayInterface return $this; } - /** - * 获取物流状态描述名称 + * 获取物流状态描述名称. * * Author ShuQingZai * DateTime 2020/7/30 11:30 - * - * @param int $status - * @return string */ protected function getStatusName(int $status): string { @@ -306,13 +282,11 @@ protected function getStatusName(int $status): string } /** - * 根据快递公司名称从配置文件中获取code + * 根据快递公司名称从配置文件中获取code. * * Author ShuQingZai * DateTime 2020/7/30 8:40 * - * @param string $company - * @return string * @throws InvalidArgumentException */ protected function getCompanyCodeByCompanyList(string $company): string @@ -332,13 +306,10 @@ protected function getCompanyCodeByCompanyList(string $company): string } /** - * 根据物流公司code获取物流公司名称 + * 根据物流公司code获取物流公司名称. * * Author ShuQingZai * DateTime 2020/8/2 11:01 - * - * @param string $code - * @return string */ protected function getCompanyNameByCode(string $code): string { @@ -348,5 +319,4 @@ protected function getCompanyNameByCode(string $code): string return $company[0]['name'] ?? $code; } - -} \ No newline at end of file +} diff --git a/src/Gateways/Kuaidi100Gateway.php b/src/Gateways/Kuaidi100Gateway.php index 30cb9ec..4ce6764 100644 --- a/src/Gateways/Kuaidi100Gateway.php +++ b/src/Gateways/Kuaidi100Gateway.php @@ -1,23 +1,28 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Overbeck\Logistics\Gateways; - use Psr\Http\Message\ResponseInterface; use Overbeck\Logistics\Exceptions\GatewayErrorException; use Overbeck\Logistics\Exceptions\InvalidArgumentException; - /** - * 快递100 + * 快递100. * * Class Kuaidi100Gateway * Author ShuQingZai * DateTime 2020/7/31 16:08 - * - * @package Overbeck\Logistics\Gateways */ class Kuaidi100Gateway extends GatewayAbstract { @@ -26,14 +31,14 @@ class Kuaidi100Gateway extends GatewayAbstract const API_QUERY_CODE_URL = 'http://www.kuaidi100.com/autonumber/auto'; /** - * 查询物流信息 + * 查询物流信息. * * Author ShuQingZai * DateTime 2020/7/31 17:55 * * @param string $logisticNumber 物流单号 * @param string|null $company 物流公司名称 - * @return array + * * @throws GatewayErrorException * @throws InvalidArgumentException */ @@ -45,16 +50,16 @@ public function query(string $logisticNumber, ?string $company = null): array throw new InvalidArgumentException('Error obtaining courier code'); } - $param = [ - 'com' => $companyCode, - 'num' => $logisticNumber, - 'resultv2' => 1 + $param = [ + 'com' => $companyCode, + 'num' => $logisticNumber, + 'resultv2' => 1, ]; $appSecret = $this->config->get('customer'); - $params = [ + $params = [ 'customer' => $appSecret, - 'param' => \json_encode($param), - 'sign' => $this->generateSign($param, $this->config->get('key'), $appSecret), + 'param' => \json_encode($param), + 'sign' => $this->generateSign($param, $this->config->get('key'), $appSecret), ]; $response = $this->post(self::API_QUERY_URL, $params); @@ -63,13 +68,13 @@ public function query(string $logisticNumber, ?string $company = null): array } /** - * 请求API获取快递公司code + * 请求API获取快递公司code. * * Author ShuQingZai * DateTime 2020/7/29 17:19 * * @param string $logisticNumber 快递单号 - * @return string + * * @throws GatewayErrorException */ protected function queryCompanyCode(string $logisticNumber): string @@ -87,17 +92,17 @@ protected function queryCompanyCode(string $logisticNumber): string $code = \current($response)['comCode'] ?? null; if (empty($response) || \is_null($code)) { - throw new GatewayErrorException('Could not find this company code.', 404, (array)$response); + throw new GatewayErrorException('Could not find this company code.', 404, (array) $response); } - $code = \strtolower($code); + $code = \strtolower($code); $this->companyName = $this->getCompanyNameByCode($code); return $code; } /** - * 签名 + * 签名. * * Author ShuQingZai * DateTime 2020/7/29 16:18 @@ -105,21 +110,22 @@ protected function queryCompanyCode(string $logisticNumber): string * @param array $params 签名参数 * @param string $appKey 密匙 ( key ) * @param string $appSecret 密钥 ( customer ) + * * @return string */ protected function generateSign(array $params, string $appKey, string $appSecret) { - return \strtoupper(\md5(\json_encode($params) . $appKey . $appSecret)); + return \strtoupper(\md5(\json_encode($params).$appKey.$appSecret)); } /** - * 格式化响应数据 + * 格式化响应数据. * * Author ShuQingZai * DateTime 2020/7/30 14:22 * * @param ResponseInterface|array|string $response 原始响应数据 - * @return array + * * @throws GatewayErrorException */ protected function formatData($response): array @@ -129,51 +135,49 @@ protected function formatData($response): array } if (empty($response)) { - throw new GatewayErrorException('Failed to find data.', 404, (array)$response); + throw new GatewayErrorException('Failed to find data.', 404, (array) $response); } $list = []; if (200 === \intval($response['status'] ?? 500)) { - $code = 1; + $code = 1; $originalStatus = $response['state']; - $companyCode = $response['com']; + $companyCode = $response['com']; $logisticNumber = $response['nu']; foreach ($response['data'] as $item) { $list[] = [ - 'context' => $item['context'], + 'context' => $item['context'], 'date_time' => $item['ftime'], ]; } - } - else { - $code = 0; + } else { + $code = 0; $originalStatus = 99; - $companyCode = ''; + $companyCode = ''; $logisticNumber = ''; } $status = $this->formatStatus($originalStatus); return [ - 'code' => $code, - 'status' => $status, - 'status_name' => $this->getStatusName($status), - 'company_code' => $companyCode, - 'company_name' => $this->companyName, + 'code' => $code, + 'status' => $status, + 'status_name' => $this->getStatusName($status), + 'company_code' => $companyCode, + 'company_name' => $this->companyName, 'tracking_number' => $logisticNumber, - 'list' => $list, - 'original_data' => \json_encode($response) + 'list' => $list, + 'original_data' => \json_encode($response), ]; } /** - * 统一格式化物流状态code + * 统一格式化物流状态code. * * Author ShuQingZai * DateTime 2020/7/30 11:28 * * @param int|string $originalStatus 请求响应中返回的状态 - * @return int */ protected function formatStatus($originalStatus): int { @@ -213,4 +217,4 @@ protected function formatStatus($originalStatus): int return $status; } -} \ No newline at end of file +} diff --git a/src/Gateways/KuaidiniaoGateway.php b/src/Gateways/KuaidiniaoGateway.php index 194f194..6aa2dbf 100644 --- a/src/Gateways/KuaidiniaoGateway.php +++ b/src/Gateways/KuaidiniaoGateway.php @@ -1,22 +1,28 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ +namespace Overbeck\Logistics\Gateways; use Psr\Http\Message\ResponseInterface; use Overbeck\Logistics\Exceptions\GatewayErrorException; use Overbeck\Logistics\Exceptions\InvalidArgumentException; - /** * 快递鸟 * * Class Kuaidiniao * Author ShuQingZai * DateTime 2020/8/2 5:27 - * - * @package Logistics */ class KuaidiniaoGateway extends GatewayAbstract { @@ -29,14 +35,14 @@ class KuaidiniaoGateway extends GatewayAbstract const REQUEST_TYPE_QUERY_CODE = '2002'; /** - * 查询物流信息 + * 查询物流信息. * * Author ShuQingZai * DateTime 2020/7/31 17:55 * * @param string $logisticNumber 物流单号 * @param string|null $company 物流公司名称 - * @return array + * * @throws GatewayErrorException * @throws InvalidArgumentException */ @@ -48,31 +54,29 @@ public function query(string $logisticNumber, ?string $company = null): array throw new InvalidArgumentException('Error obtaining courier code'); } - $params = [ - 'ShipperCode' => $companyCode, - 'LogisticCode' => $logisticNumber + $params = [ + 'ShipperCode' => $companyCode, + 'LogisticCode' => $logisticNumber, ]; $baseParams = $this->getBaseParams($params); - $response = $this->post(self::API_QUERY_URL, $baseParams); + $response = $this->post(self::API_QUERY_URL, $baseParams); return $this->formatData($response); } /** - * 请求API获取快递公司code + * 请求API获取快递公司code. * * Author ShuQingZai * DateTime 2020/8/2 12:28 * - * @param string $logisticNumber - * @return string * @throws GatewayErrorException */ protected function queryCompanyCode(string $logisticNumber): string { - $params = ['LogisticCode' => $logisticNumber]; + $params = ['LogisticCode' => $logisticNumber]; $baseParams = $this->getBaseParams($params, self::REQUEST_TYPE_QUERY_CODE); - $response = $this->post(self::API_QUERY_CODE_URL, $baseParams); + $response = $this->post(self::API_QUERY_CODE_URL, $baseParams); if (!\is_array($response)) { $response = \json_decode($response, true); @@ -81,7 +85,7 @@ protected function queryCompanyCode(string $logisticNumber): string $code = $response['Shipper'][0]['ShipperCode'] ?? null; if (empty($response) || \is_null($code)) { - throw new GatewayErrorException('Could not find this company code.', 404, (array)$response); + throw new GatewayErrorException('Could not find this company code.', 404, (array) $response); } $this->companyName = $response['Shipper'][0]['ShipperName'] ?? $this->getCompanyNameByCode($code); @@ -90,13 +94,12 @@ protected function queryCompanyCode(string $logisticNumber): string } /** - * 统一格式化物流状态code + * 统一格式化物流状态code. * * Author ShuQingZai * DateTime 2020/7/30 11:28 * * @param int|string $originalStatus 请求响应中返回的状态 - * @return int */ protected function formatStatus($originalStatus): int { @@ -119,13 +122,13 @@ protected function formatStatus($originalStatus): int } /** - * 格式化响应数据 + * 格式化响应数据. * * Author ShuQingZai * DateTime 2020/7/30 14:22 * * @param ResponseInterface|array|string $response 原始响应数据 - * @return array + * * @throws GatewayErrorException */ protected function formatData($response): array @@ -135,67 +138,61 @@ protected function formatData($response): array } if (empty($response)) { - throw new GatewayErrorException('Failed to find data.', 404, (array)$response); + throw new GatewayErrorException('Failed to find data.', 404, (array) $response); } $list = []; if (true === \boolval($response['Success'] ?? false)) { - $code = 1; + $code = 1; $originalStatus = $response['State']; - $companyCode = $response['ShipperCode']; + $companyCode = $response['ShipperCode']; $logisticNumber = $response['LogisticCode']; foreach ($response['Traces'] as $item) { $list[] = [ - 'context' => $item['AcceptStation'], + 'context' => $item['AcceptStation'], 'date_time' => $item['AcceptTime'], ]; } - } - else { - $code = 0; + } else { + $code = 0; $originalStatus = 99; - $companyCode = ''; + $companyCode = ''; $logisticNumber = ''; } $status = $this->formatStatus($originalStatus); return [ - 'code' => $code, - 'status' => $status, - 'status_name' => $this->getStatusName($status), - 'company_code' => $companyCode, - 'company_name' => $this->companyName, + 'code' => $code, + 'status' => $status, + 'status_name' => $this->getStatusName($status), + 'company_code' => $companyCode, + 'company_name' => $this->companyName, 'tracking_number' => $logisticNumber, - 'list' => $list, - 'original_data' => \json_encode($response) + 'list' => $list, + 'original_data' => \json_encode($response), ]; } /** - * 签名 + * 签名. * * Author ShuQingZai * DateTime 2020/8/2 5:28 - * - * @param array $param - * @param string $appKey - * @return string */ protected function generateSign(array $param, string $appKey): string { - return \urlencode(\base64_encode(\md5(\json_encode($param) . $appKey))); + return \urlencode(\base64_encode(\md5(\json_encode($param).$appKey))); } /** - * 组装请求参数 + * 组装请求参数. * * Author ShuQingZai * DateTime 2020/8/2 11:49 * * @param array $params 请求参数 * @param string $requestType 请求类型 - * @return array */ private function getBaseParams(array $params, string $requestType = self::REQUEST_TYPE_QUERY): array { @@ -203,8 +200,8 @@ private function getBaseParams(array $params, string $requestType = self::REQUES 'RequestData' => \urlencode(\json_encode($params)), 'EBusinessID' => $this->config->get('EBusinessID'), 'RequestType' => $requestType, - 'DataSign' => $this->generateSign($params, $this->config->get('appKey')), - 'DataType' => '2' + 'DataSign' => $this->generateSign($params, $this->config->get('appKey')), + 'DataType' => '2', ]; } -} \ No newline at end of file +} diff --git a/src/Interfaces/ArrayableInterface.php b/src/Interfaces/ArrayableInterface.php index dfaa139..bf7f6a4 100644 --- a/src/Interfaces/ArrayableInterface.php +++ b/src/Interfaces/ArrayableInterface.php @@ -1,12 +1,20 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Overbeck\Logistics\Interfaces; use ArrayAccess; - interface ArrayableInterface extends ArrayAccess { /** diff --git a/src/Interfaces/GatewayAvailableInterface.php b/src/Interfaces/GatewayAvailableInterface.php index 3be3f95..ddf9014 100644 --- a/src/Interfaces/GatewayAvailableInterface.php +++ b/src/Interfaces/GatewayAvailableInterface.php @@ -1,47 +1,48 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Overbeck\Logistics\Interfaces; /** - * 网关可用异常接口 + * 网关可用异常接口. * * Interface GatewayAvailableInterface * Author ShuQingZai * DateTime 2020/7/31 16:09 - * - * @package Overbeck\Logistics\Interfaces */ interface GatewayAvailableInterface { /** - * 获取结果 - * - * @return array + * 获取结果. */ public function getResults(): array; /** - * 获取单一网关异常 - * - * @param string $gateway + * 获取单一网关异常. * * @return mixed|null */ public function getException(string $gateway); /** - * 获取所有网关异常 - * - * @return array + * 获取所有网关异常. */ public function getExceptions(): array; /** - * 获取以后一个异常 + * 获取以后一个异常. * * @return mixed */ public function getLastException(); -} \ No newline at end of file +} diff --git a/src/Interfaces/GatewayInterface.php b/src/Interfaces/GatewayInterface.php index 6b57941..6a29b43 100644 --- a/src/Interfaces/GatewayInterface.php +++ b/src/Interfaces/GatewayInterface.php @@ -1,61 +1,59 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Overbeck\Logistics\Interfaces; - /** - * 网关接口 + * 网关接口. * * Interface GatewayInterface * Author ShuQingZai * DateTime 2020/7/31 16:09 - * - * @package Overbeck\Logistics\Interfaces */ interface GatewayInterface { /** - * 获取服务标识名称 + * 获取服务标识名称. * * Author ShuQingZai * DateTime 2020/7/29 17:54 - * - * @return string */ public function getGatewayName(): string; /** - * 查询物流信息 + * 查询物流信息. * * Author ShuQingZai * DateTime 2020/7/31 17:55 * * @param string $logisticNumber 物流单号 * @param string|null $company 物流公司名称 - * @return array */ public function query(string $logisticNumber, ?string $company = null): array; /** - * 设置物流公司信息 + * 设置物流公司信息. * * Author ShuQingZai * DateTime 2020/7/31 17:26 - * - * @param array $companyList - * @return GatewayInterface */ public function setCompanyList(array $companyList): GatewayInterface; /** - * 获取物流公司信息 + * 获取物流公司信息. * * Author ShuQingZai * DateTime 2020/7/31 17:28 - * - * @return array */ public function getCompanyList(): array; -} \ No newline at end of file +} diff --git a/src/Interfaces/LogisticsInterface.php b/src/Interfaces/LogisticsInterface.php index 89258dd..efe3c7a 100644 --- a/src/Interfaces/LogisticsInterface.php +++ b/src/Interfaces/LogisticsInterface.php @@ -1,22 +1,27 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Overbeck\Logistics\Interfaces; use Overbeck\Logistics\Exceptions\GatewayAvailableException; use Overbeck\Logistics\Exceptions\GatewayErrorException; -use Overbeck\Logistics\Logistics; - /** - * 物流接口 + * 物流接口. * * Interface LogisticsInterface * Author ShuQingZai * DateTime 2020/7/31 16:09 - * - * @package Overbeck\Logistics\Interfaces */ interface LogisticsInterface { @@ -29,40 +34,33 @@ interface LogisticsInterface * @param string $logisticNumber 物流单号 * @param string|null $company 物流公司名称 * @param array|string $gateways 需要使用的网关,如果不指定,则使用所有可用的网关 - * @return array + * * @throws GatewayErrorException * @throws GatewayAvailableException */ public function query(string $logisticNumber, ?string $company = null, $gateways = []): array; /** - * 获取物流公司信息 + * 获取物流公司信息. * * Author ShuQingZai * DateTime 2020/7/31 16:18 - * - * @return array */ public function getCompanyList(): array; /** - * 设置物流公司信息 + * 设置物流公司信息. * * Author ShuQingZai * DateTime 2020/7/31 16:18 - * - * @param array $companyList - * @return LogisticsInterface */ public function setCompanyList(array $companyList): LogisticsInterface; /** - * 获取默认的物流公司列表 + * 获取默认的物流公司列表. * * Author ShuQingZai * DateTime 2020/8/1 18:12 - * - * @return array */ public function getDefaultCompanyList(): array; -} \ No newline at end of file +} diff --git a/src/Laravel/Logistics.php b/src/Laravel/Logistics.php index 18d2bd9..1c16211 100644 --- a/src/Laravel/Logistics.php +++ b/src/Laravel/Logistics.php @@ -1,26 +1,35 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ +namespace Overbeck\Logistics\Laravel; use Illuminate\Support\Facades\Facade; /** - * Laravel 门面 + * Laravel 门面. * * Class Facade * Author ShuQingZai * DateTime 2020/8/2 14:01 * * @mixin \Overbeck\Logistics\Logistics + * * @see \Overbeck\Logistics\Logistics - * @package Overbeck\Logistics */ class Logistics extends Facade { /** - * 获取门面标识 + * 获取门面标识. * * Author ShuQingZai * DateTime 2020/8/2 14:02 diff --git a/src/Laravel/ServiceProvider.php b/src/Laravel/ServiceProvider.php index ed30433..aa218f5 100644 --- a/src/Laravel/ServiceProvider.php +++ b/src/Laravel/ServiceProvider.php @@ -1,34 +1,40 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ +namespace Overbeck\Logistics\Laravel; use Illuminate\Foundation\Application as LaravelApplication; use Overbeck\Logistics\Logistics; /** - * 集成于Laravel + * 集成于Laravel. * * Class ServiceProvider * Author ShuQingZai * DateTime 2020/8/2 13:17 - * - * @package Overbeck\Logistics */ class ServiceProvider extends \Illuminate\Support\ServiceProvider { /** - * 标记着提供器是延迟加载的 + * 标记着提供器是延迟加载的. * * @var bool */ protected $defer = true; - public function boot() { - $source = \realpath(__DIR__ . '/../config/config.php'); + $source = \realpath(__DIR__.'/../config/config.php'); if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { $this->publishes([$source => config_path('logistics.php')], 'logistics'); @@ -38,7 +44,7 @@ public function boot() } /** - * 注册服务提供者 + * 注册服务提供者. * * @return void */ @@ -60,4 +66,4 @@ public function provides() { return [Logistics::class, 'logistics']; } -} \ No newline at end of file +} diff --git a/src/Logistics.php b/src/Logistics.php index 66d028b..cd70fb5 100644 --- a/src/Logistics.php +++ b/src/Logistics.php @@ -1,10 +1,18 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Overbeck\Logistics; - use Overbeck\Logistics\Exceptions\GatewayAvailableException; use Overbeck\Logistics\Exceptions\InvalidArgumentException; use Overbeck\Logistics\Interfaces\LogisticsInterface; @@ -12,15 +20,13 @@ use Overbeck\Logistics\Supports\ParseContentToArray; /** - * 物流API - * + * 物流API. * * Class Logistics * Author ShuQingZai * DateTime 2020/7/31 17:37 * * @mixin LogisticsGatewayManager - * @package Overbeck\Logistics */ class Logistics implements LogisticsInterface { @@ -28,36 +34,32 @@ class Logistics implements LogisticsInterface const STATUS_FAILURE = 'failure'; /** - * 物流网关管理 + * 物流网关管理. * - * @var LogisticsGatewayManager $logisticsGatewayManager - * DateTime 2020/7/29 11:29 - * @package Overbeck\Logistics\Logistics + * @var LogisticsGatewayManager + * DateTime 2020/7/29 11:29 */ protected $logisticsGatewayManager; /** - * 物流公司列表 + * 物流公司列表. * - * @var array $companyList - * DateTime 2020/7/31 16:11 - * @package Overbeck\Logistics\Logistics + * @var array + * DateTime 2020/7/31 16:11 */ protected $companyList = []; /** * Logistics constructor. * - * @param array $config * @throws Exceptions\InvalidArgumentException */ public function __construct(array $config) { $this->logisticsGatewayManager = new LogisticsGatewayManager($config, $this); - $this->companyList = $this->initCompanyFiles(); + $this->companyList = $this->initCompanyFiles(); } - /** * 查询物流 * @@ -67,7 +69,7 @@ public function __construct(array $config) * @param string $logisticNumber 物流单号 * @param string|null $company 物流公司名称 * @param array|string $gateways 需要使用的网关,如果不指定,则使用所有可用的网关 - * @return array + * * @throws GatewayAvailableException * @throws InvalidArgumentException */ @@ -78,12 +80,11 @@ public function query(string $logisticNumber, ?string $company = null, $gateways } $gatewaysConfig = $this->logisticsGatewayManager->getGateways(); - $results = []; - $errResults = 0; + $results = []; + $errResults = 0; foreach ($gatewaysConfig as $gateway => $config) { - if (!empty($gateways) && !\in_array($gateway, $gateways)) { - throw new InvalidArgumentException('The gateway "' . $gateway . '" is unavailable'); + throw new InvalidArgumentException('The gateway "'.$gateway.'" is unavailable'); } if ($this->logisticsGatewayManager->hasDefaultGateway() && $gateway !== $this->logisticsGatewayManager->getDefaultGateway()) { @@ -97,15 +98,15 @@ public function query(string $logisticNumber, ?string $company = null, $gateways try { $results[$gateway] = new Collection([ 'gateway' => $gateway, - 'status' => self::STATUS_SUCCESS, - 'result' => $this->logisticsGatewayManager->gateway($gateway) + 'status' => self::STATUS_SUCCESS, + 'result' => $this->logisticsGatewayManager->gateway($gateway) ->setCompanyList($this->getCompanyList()) ->query($logisticNumber, $company), ]); } catch (\Throwable $e) { $results[$gateway] = new Collection([ - 'gateway' => $gateway, - 'status' => self::STATUS_FAILURE, + 'gateway' => $gateway, + 'status' => self::STATUS_FAILURE, 'exception' => $e, ]); ++$errResults; @@ -120,12 +121,10 @@ public function query(string $logisticNumber, ?string $company = null, $gateways } /** - * 获取物流公司信息 + * 获取物流公司信息. * * Author ShuQingZai * DateTime 2020/7/31 16:18 - * - * @return array */ public function getCompanyList(): array { @@ -135,13 +134,10 @@ public function getCompanyList(): array } /** - * 设置物流公司信息 + * 设置物流公司信息. * * Author ShuQingZai * DateTime 2020/7/31 16:18 - * - * @param array $companyList - * @return LogisticsInterface */ public function setCompanyList(array $companyList): LogisticsInterface { @@ -151,36 +147,35 @@ public function setCompanyList(array $companyList): LogisticsInterface } /** - * 获取默认的物流公司列表 + * 获取默认的物流公司列表. * * Author ShuQingZai * DateTime 2020/8/1 18:12 - * - * @return array */ public function getDefaultCompanyList(): array { - return include __DIR__ . '/config/company.php'; + return include __DIR__.'/config/company.php'; } /** - * 初始化配置文件的物流公司列表 + * 初始化配置文件的物流公司列表. * * Author ShuQingZai * DateTime 2020/8/1 18:15 * * @return array + * * @throws Exceptions\InvalidArgumentException */ protected function initCompanyFiles() { - $companyFiles = $this->getConfig()->get('company_file', []); - $companyFiles = \is_array($companyFiles) ? $companyFiles : \explode(',', $companyFiles); + $companyFiles = $this->getConfig()->get('company_file', []); + $companyFiles = \is_array($companyFiles) ? $companyFiles : \explode(',', $companyFiles); $companyFilesList = []; foreach ($companyFiles as $file) { - if (\is_file((string)$file)) { - $type = \pathinfo($file, PATHINFO_EXTENSION); - $fileArr = ParseContentToArray::parseContent($file, $type); + if (\is_file((string) $file)) { + $type = \pathinfo($file, PATHINFO_EXTENSION); + $fileArr = ParseContentToArray::parseContent($file, $type); $companyFilesList = \array_merge($companyFilesList, $fileArr); } } @@ -191,17 +186,17 @@ protected function initCompanyFiles() } /** - * 魔术方法 + * 魔术方法. * * Author ShuQingZai * DateTime 2020/7/31 17:32 * - * @param string $name - * @param mixed $avg + * @param mixed $avg + * * @return mixed */ public function __call(string $name, $avg) { return call_user_func_array([$this->logisticsGatewayManager, $name], $avg); } -} \ No newline at end of file +} diff --git a/src/LogisticsGatewayManager.php b/src/LogisticsGatewayManager.php index 7b1c041..5ec6e34 100644 --- a/src/LogisticsGatewayManager.php +++ b/src/LogisticsGatewayManager.php @@ -1,92 +1,87 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Overbeck\Logistics; - use RuntimeException; use Overbeck\Logistics\Exceptions\InvalidArgumentException; use Overbeck\Logistics\Gateways\GatewayAbstract; use Overbeck\Logistics\Interfaces\GatewayInterface; use Overbeck\Logistics\Supports\Config; - /** - * 物流网关管理 + * 物流网关管理. * * Class LogisticsGatewayManager * Author ShuQingZai * DateTime 2020/8/1 18:41 - * - * @package Overbeck\Logistics */ class LogisticsGatewayManager { - /** - * 配置 + * 配置. * - * @var Config $config - * DateTime 2020/7/29 9:41 - * @package Overbeck\Logistics\Logistics + * @var Config + * DateTime 2020/7/29 9:41 */ protected $config; /** - * 默认网关 + * 默认网关. * - * @var string $defaultGateway - * DateTime 2020/7/29 9:57 - * @package Overbeck\Logistics\Logistics + * @var string + * DateTime 2020/7/29 9:57 */ protected $defaultGateway; /** - * 网关服务集合 + * 网关服务集合. * - * @var array $gateways - * DateTime 2020/7/28 16:47 - * @package Overbeck\Logistics\Factory + * @var array + * DateTime 2020/7/28 16:47 */ protected $gateways = []; /** - * 自定义网关集合 + * 自定义网关集合. * - * @var array $customGateway - * DateTime 2020/7/29 14:11 - * @package Overbeck\Logistics\LogisticsGatewayManager + * @var array + * DateTime 2020/7/29 14:11 */ protected $customGateway = []; /** - * 禁用的网关 + * 禁用的网关. * - * @var array $disableGateways - * DateTime 2020/7/31 10:01 - * @package Overbeck\Logistics\LogisticsGatewayManager + * @var array + * DateTime 2020/7/31 10:01 */ protected $disableGateways = []; /** - * @var Logistics $logistics - * DateTime 2020/8/1 19:12 - * @package Overbeck\Logistics\LogisticsGatewayManager + * @var Logistics + * DateTime 2020/8/1 19:12 */ protected $logistics; public function __construct(array $config, Logistics $logistics) { - $this->config = new Config($config); + $this->config = new Config($config); $this->logistics = $logistics; $this->config->has('default') && $this->setDefaultGateway($this->config->get('default')); $this->config->has('disable') && $this->setDisableGateways($this->config->get('disable')); } - /** - * @return array - */ public function getGateways(): array { empty($this->gateways) && $this->config->has('gateways') && $this->gateways = $this->config->get('gateways'); @@ -95,13 +90,11 @@ public function getGateways(): array } /** - * 获取网关实例 + * 获取网关实例. * * Author ShuQingZai * DateTime 2020/7/29 11:32 * - * @param string|null $name - * @return GatewayInterface * @throws InvalidArgumentException */ public function gateway(?string $name = null): GatewayInterface @@ -116,12 +109,11 @@ public function gateway(?string $name = null): GatewayInterface } /** - * 获取默认网关 + * 获取默认网关. * * Author ShuQingZai * DateTime 2020/7/29 10:59 * - * @return string * @throws \RuntimeException 没有配置默认网关 */ public function getDefaultGateway(): string @@ -134,12 +126,10 @@ public function getDefaultGateway(): string } /** - * 是否设置默认网关 + * 是否设置默认网关. * * Author ShuQingZai * DateTime 2020/7/29 13:46 - * - * @return bool */ public function hasDefaultGateway(): bool { @@ -147,13 +137,10 @@ public function hasDefaultGateway(): bool } /** - * 设置默认网关 + * 设置默认网关. * * Author ShuQingZai * DateTime 2020/7/30 8:53 - * - * @param string $defaultGateway - * @return Logistics */ public function setDefaultGateway(string $defaultGateway): Logistics { @@ -162,26 +149,16 @@ public function setDefaultGateway(string $defaultGateway): Logistics return $this->logistics; } - /** - * @return Config - */ public function getConfig(): Config { return $this->config; } - /** - * @return array - */ public function getDisableGateways(): array { return $this->disableGateways; } - /** - * @param array $disableGateways - * @return Logistics - */ public function setDisableGateways(array $disableGateways): Logistics { $this->disableGateways = $disableGateways; @@ -189,22 +166,19 @@ public function setDisableGateways(array $disableGateways): Logistics return $this->logistics; } - /** - * 注销网关服务实例 + * 注销网关服务实例. * * Author ShuQingZai * DateTime 2020/7/7 11:35 * * @param string|null $name 指定服务标识注销 - * @return Logistics */ public function unregisterAppInstance(?string $name = null): Logistics { if (\is_null($name)) { $this->gateways = []; - } - elseif (isset($this->gateways[$name])) { + } elseif (isset($this->gateways[$name])) { unset($this->gateways[$name]); } @@ -212,14 +186,10 @@ public function unregisterAppInstance(?string $name = null): Logistics } /** - * 注册自定义网关 + * 注册自定义网关. * * Author ShuQingZai * DateTime 2020/7/29 14:13 - * - * @param string $name - * @param \Closure $closure - * @return Logistics */ public function registerCustomGateway(string $name, \Closure $closure): Logistics { @@ -234,28 +204,25 @@ public function registerCustomGateway(string $name, \Closure $closure): Logistic * Author ShuQingZai * DateTime 2020/7/29 9:12 * - * @param string $name - * @return GatewayInterface * @throws InvalidArgumentException */ protected function makeGateway(string $name): GatewayInterface { - $config = $this->config->get('gateways.' . $name, []); + $config = $this->config->get('gateways.'.$name, []); if (!isset($config['http'])) { $config['http'] = $this->config->get('http', []); } - $config['http']['timeout'] = $config['http']['timeout'] ?: GatewayAbstract::DEFAULT_TIMEOUT; + $config['http']['timeout'] = $config['http']['timeout'] ?: GatewayAbstract::DEFAULT_TIMEOUT; $config['http']['connect_timeout'] = $config['http']['connect_timeout'] ?: GatewayAbstract::DEFAULT_CONNECT_TIMEOUT; if (isset($this->customGateway[$name])) { $appInstance = $this->callCustomCreator($name, $config); - } - else { + } else { $className = $this->formatGatewayClassName($name); try { - $app = new \ReflectionClass($className); + $app = new \ReflectionClass($className); $appInstance = $app->newInstance($config); } catch (\ReflectionException $e) { throw new InvalidArgumentException($e->getMessage()); @@ -266,7 +233,7 @@ protected function makeGateway(string $name): GatewayInterface throw new InvalidArgumentException(sprintf('Gateway "%s" must implement interface %s.', $name, GatewayInterface::class)); } - /** @var GatewayInterface $appInstance */ + /* @var GatewayInterface $appInstance */ return $appInstance; } @@ -275,24 +242,17 @@ protected function makeGateway(string $name): GatewayInterface * * Author ShuQingZai * DateTime 2020/7/29 14:17 - * - * @param string $gateway - * @param array $config - * @return GatewayInterface */ protected function callCustomCreator(string $gateway, array $config = []): GatewayInterface { - return \call_user_func($this->customGateway[$gateway], $config ?: $this->config->get('gateways.' . $gateway, [])); + return \call_user_func($this->customGateway[$gateway], $config ?: $this->config->get('gateways.'.$gateway, [])); } /** - * 格式化网关类名称 + * 格式化网关类名称. * * Author ShuQingZai * DateTime 2020/7/30 8:47 - * - * @param string $name - * @return string */ protected function formatGatewayClassName(string $name): string { @@ -302,6 +262,6 @@ protected function formatGatewayClassName(string $name): string $name = \ucfirst(\str_replace(['-', '_', ''], '', $name)); - return __NAMESPACE__ . '\\Gateways\\' . $name . 'Gateway'; + return __NAMESPACE__.'\\Gateways\\'.$name.'Gateway'; } -} \ No newline at end of file +} diff --git a/src/Supports/Arr.php b/src/Supports/Arr.php index cc87349..304d025 100644 --- a/src/Supports/Arr.php +++ b/src/Supports/Arr.php @@ -1,8 +1,17 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ +namespace Overbeck\Logistics\Supports; /** * Array helper from Illuminate\Support\Arr. @@ -12,7 +21,6 @@ class Arr /** * Add an element to an array using "dot" notation if it doesn't exist. * - * @param array $array * @param string $key * @param mixed $value * @@ -58,7 +66,6 @@ public static function crossJoin(...$arrays) /** * Divide an array into two arrays. One with keys and the other with values. * - * @param array $array * @return array */ public static function divide(array $array) @@ -69,7 +76,6 @@ public static function divide(array $array) /** * Flatten a multi-dimensional associative array with dots. * - * @param array $array * @param string $prepend * * @return array @@ -92,7 +98,6 @@ public static function dot(array $array, $prepend = '') /** * Get all of the given array except for a specified array of items. * - * @param array $array * @param array|string $keys * * @return array @@ -107,7 +112,6 @@ public static function except(array $array, $keys) /** * Determine if the given key exists in the provided array. * - * @param array $array * @param string|int $key * * @return bool @@ -120,9 +124,7 @@ public static function exists(array $array, $key) /** * Return the first element in an array passing a given truth test. * - * @param array $array - * @param callable|null $callback - * @param mixed $default + * @param mixed $default * * @return mixed */ @@ -150,9 +152,7 @@ public static function first(array $array, callable $callback = null, $default = /** * Return the last element in an array passing a given truth test. * - * @param array $array - * @param callable|null $callback - * @param mixed $default + * @param mixed $default * * @return mixed */ @@ -168,8 +168,7 @@ public static function last(array $array, callable $callback = null, $default = /** * Flatten a multi-dimensional array into a single level. * - * @param array $array - * @param int $depth + * @param int $depth * * @return array */ @@ -191,7 +190,6 @@ public static function flatten(array $array, $depth = INF) /** * Remove one or many array items from a given array using "dot" notation. * - * @param array $array * @param array|string $keys */ public static function forget(array &$array, $keys) @@ -234,7 +232,6 @@ public static function forget(array &$array, $keys) /** * Get an item from an array using "dot" notation. * - * @param array $array * @param string $key * @param mixed $default * @@ -264,7 +261,6 @@ public static function get(array $array, $key, $default = null) /** * Check if an item or items exist in an array using "dot" notation. * - * @param array $array * @param string|array $keys * * @return bool @@ -281,7 +277,7 @@ public static function has(array $array, $keys) return false; } - if ($keys === []) { + if ([] === $keys) { return false; } @@ -309,7 +305,6 @@ public static function has(array $array, $keys) * * An array is "associative" if it doesn't have sequential numerical keys beginning with zero. * - * @param array $array * @return bool */ public static function isAssoc(array $array) @@ -322,7 +317,6 @@ public static function isAssoc(array $array) /** * Get a subset of the items from the given array. * - * @param array $array * @param array|string $keys * * @return array @@ -335,7 +329,6 @@ public static function only(array $array, $keys) /** * Push an item onto the beginning of an array. * - * @param array $array * @param mixed $value * @param mixed $key * @@ -355,7 +348,6 @@ public static function prepend(array $array, $value, $key = null) /** * Get a value from the array, and remove it. * - * @param array $array * @param string $key * @param mixed $default * @@ -373,10 +365,7 @@ public static function pull(array &$array, $key, $default = null) /** * Get a 1 value from an array. * - * @param array $array - * @param int|null $amount * @return mixed - * */ public static function random(array $array, int $amount = null) { @@ -400,9 +389,7 @@ public static function random(array $array, int $amount = null) * * If no key is given to the method, the entire array will be replaced. * - * @param array $array - * @param string $key - * @param mixed $value + * @param mixed $value * * @return array */ @@ -431,8 +418,6 @@ public static function set(array &$array, string $key, $value) /** * Filter the array using the given callback. * - * @param array $array - * @param callable $callback * @return array */ public static function where(array $array, callable $callback) diff --git a/src/Supports/Collection.php b/src/Supports/Collection.php index 1997f95..c118b38 100644 --- a/src/Supports/Collection.php +++ b/src/Supports/Collection.php @@ -1,6 +1,16 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Overbeck\Logistics\Supports; use ArrayIterator; @@ -24,8 +34,6 @@ class Collection implements Countable, IteratorAggregate, JsonSerializable, Seri /** * set data. - * - * @param array $items */ public function __construct(array $items = []) { @@ -47,7 +55,6 @@ public function all() /** * Return specific items. * - * @param array $keys * @return \Overbeck\Logistics\Supports\Collection */ public function only(array $keys) @@ -112,7 +119,6 @@ public function has($key) /** * Run a filter over each of the items. * - * @param callable|null $callback * @return static */ public function filter(callable $callback = null) @@ -194,17 +200,17 @@ public function forget($key) } /** - * Whether the collection is empty + * Whether the collection is empty. * * @param bool + * * @return bool */ public function isEmpty() { - return $this->count() === 0; + return 0 === $this->count(); } - /** * Build to array. * diff --git a/src/Supports/Config.php b/src/Supports/Config.php index 122664f..637d0f1 100644 --- a/src/Supports/Config.php +++ b/src/Supports/Config.php @@ -1,8 +1,17 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ +namespace Overbeck\Logistics\Supports; class Config extends Collection { diff --git a/src/Supports/ParseContentToArray.php b/src/Supports/ParseContentToArray.php index ea05156..64e165b 100644 --- a/src/Supports/ParseContentToArray.php +++ b/src/Supports/ParseContentToArray.php @@ -1,31 +1,34 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ +namespace Overbeck\Logistics\Supports; use Overbeck\Logistics\Exceptions\InvalidArgumentException; /** - * 解析内容为数组并返回 + * 解析内容为数组并返回. * * Class companyFiles * Author ShuQingZai * DateTime 2020/8/1 16:34 - * - * @package Overbeck\Logistics\Supports */ class ParseContentToArray { - /** - * 解析php文件 + * 解析php文件. * * Author ShuQingZai * DateTime 2020/8/1 16:41 - * - * @param string $file - * @return array */ public static function parsePhp(string $file): array { @@ -33,51 +36,43 @@ public static function parsePhp(string $file): array } /** - * 解析json + * 解析json. * * Author ShuQingZai * DateTime 2020/8/1 16:41 - * - * @param string $file - * @return array */ public static function parseJson(string $file): array { if (\is_file($file)) { $file = \file_get_contents($file); } + return \json_decode($file, true); } /** - * 解析xml + * 解析xml. * * Author ShuQingZai * DateTime 2020/8/1 16:41 - * - * @param string $file - * @return array */ public static function parseXml(string $file): array { - $result = (array)(\is_file($file) ? \simplexml_load_file($file) : \simplexml_load_string($file)); + $result = (array) (\is_file($file) ? \simplexml_load_file($file) : \simplexml_load_string($file)); foreach ($result as $key => $val) { if (\is_object($val)) { - $result[$key] = (array)$val; + $result[$key] = (array) $val; } } + return $result; } - /** - * 解析ini + * 解析ini. * * Author ShuQingZai * DateTime 2020/8/1 16:51 - * - * @param string $file - * @return array */ public static function parseIni(string $file): array { @@ -85,14 +80,14 @@ public static function parseIni(string $file): array } /** - * 解析内容 + * 解析内容. * * Author ShuQingZai * DateTime 2020/8/1 17:00 * * @param string $content 需要解析的内容 可以是一个文件 * @param string $type 内容类型 - * @return array + * * @throws InvalidArgumentException */ public static function parseContent(string $content, string $type = 'php'): array @@ -116,4 +111,4 @@ public static function parseContent(string $content, string $type = 'php'): arra return $res; } -} \ No newline at end of file +} diff --git a/src/Traits/HasHttpRequest.php b/src/Traits/HasHttpRequest.php index 0a8c10f..d067a9b 100644 --- a/src/Traits/HasHttpRequest.php +++ b/src/Traits/HasHttpRequest.php @@ -1,12 +1,21 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Overbeck\Logistics\Traits; use GuzzleHttp\Client; use Psr\Http\Message\ResponseInterface; - /** * Trait HasHttpRequest. */ @@ -15,33 +24,25 @@ trait HasHttpRequest /** * Make a get request. * - * @param string $endpoint - * @param array $query - * @param array $headers - * * @return array */ protected function get(string $endpoint, array $query = [], array $headers = []) { return $this->request('get', $endpoint, [ 'headers' => $headers, - 'query' => $query, + 'query' => $query, ]); } /** * Make a post request. * - * @param string $endpoint - * @param array $params - * @param array $headers - * * @return array */ protected function post(string $endpoint, array $params = [], array $headers = []) { return $this->request('post', $endpoint, [ - 'headers' => $headers, + 'headers' => $headers, 'form_params' => $params, ]); } @@ -49,26 +50,20 @@ protected function post(string $endpoint, array $params = [], array $headers = [ /** * Make a post request with json params. * - * @param string $endpoint - * @param array $params - * @param array $headers - * * @return array */ protected function postJson(string $endpoint, array $params = [], array $headers = []) { return $this->request('post', $endpoint, [ 'headers' => $headers, - 'json' => $params, + 'json' => $params, ]); } /** * Make a http request. * - * @param string $method - * @param string $endpoint - * @param array $options http://docs.guzzlephp.org/en/latest/request-options.html + * @param array $options http://docs.guzzlephp.org/en/latest/request-options.html * * @return array */ @@ -87,8 +82,8 @@ protected function getBaseOptions() $options = \method_exists($this, 'getGuzzleOptions') ? $this->getGuzzleOptions() : []; return \array_merge($options, [ - 'base_uri' => \method_exists($this, 'getBaseUri') ? $this->getBaseUri() : '', - 'timeout' => \method_exists($this, 'getTimeout') ? $this->getTimeout() : 5.0, + 'base_uri' => \method_exists($this, 'getBaseUri') ? $this->getBaseUri() : '', + 'timeout' => \method_exists($this, 'getTimeout') ? $this->getTimeout() : 5.0, 'connect_timeout' => \method_exists($this, 'getConnectTimeout') ? $this->getConnectTimeout() : 5.0, ]); } @@ -96,8 +91,6 @@ protected function getBaseOptions() /** * Return http client. * - * @param array $options - * * @return \GuzzleHttp\Client * * @codeCoverageIgnore @@ -110,19 +103,16 @@ protected function getHttpClient(array $options = []) /** * Convert response contents to json. * - * @param \Psr\Http\Message\ResponseInterface $response - * * @return ResponseInterface|array|string */ protected function unwrapResponse(ResponseInterface $response) { $contentType = $response->getHeaderLine('Content-Type'); - $contents = $response->getBody()->getContents(); + $contents = $response->getBody()->getContents(); if (false !== \stripos($contentType, 'json') || \stripos($contentType, 'javascript')) { return \json_decode($contents, true); - } - elseif (false !== stripos($contentType, 'xml')) { + } elseif (false !== stripos($contentType, 'xml')) { return \json_decode(\json_encode(\simplexml_load_string($contents)), true); } diff --git a/src/config/company.php b/src/config/company.php index fef0743..53b0901 100644 --- a/src/config/company.php +++ b/src/config/company.php @@ -1,584 +1,528 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. */ - return [ [ 'name' => '顺丰速运', - 'code' => - [ - 'aliyun' => 'SFEXPRESS', - 'juhe' => 'sf', + 'code' => [ + 'aliyun' => 'SFEXPRESS', + 'juhe' => 'sf', 'kuaidi100' => 'shunfeng', - 'kdniao' => 'SF', + 'kdniao' => 'SF', ], ], [ 'name' => '申通快递', - 'code' => - [ - 'aliyun' => 'STO', - 'juhe' => 'sto', + 'code' => [ + 'aliyun' => 'STO', + 'juhe' => 'sto', 'kuaidi100' => 'shentong', - 'kdniao' => 'STO', + 'kdniao' => 'STO', ], ], [ 'name' => '中通快递', - 'code' => - [ - 'aliyun' => 'ZTO', - 'juhe' => 'zto', + 'code' => [ + 'aliyun' => 'ZTO', + 'juhe' => 'zto', 'kuaidi100' => 'zhongtong', - 'kdniao' => 'ZTO', + 'kdniao' => 'ZTO', ], ], [ 'name' => '中通快运', - 'code' => - [ - 'aliyun' => 'ZTO56', - 'juhe' => 'ztoky', + 'code' => [ + 'aliyun' => 'ZTO56', + 'juhe' => 'ztoky', 'kuaidi100' => 'zhongtongkuaiyun', - 'kdniao' => 'ZTO', + 'kdniao' => 'ZTO', ], ], [ 'name' => '圆通速递', - 'code' => - [ - 'aliyun' => 'YTO', - 'juhe' => 'yt', + 'code' => [ + 'aliyun' => 'YTO', + 'juhe' => 'yt', 'kuaidi100' => 'yuantong', - 'kdniao' => 'YTO', + 'kdniao' => 'YTO', ], ], [ 'name' => '韵达速递', - 'code' => - [ - 'aliyun' => 'YUNDA', - 'juhe' => 'yd', + 'code' => [ + 'aliyun' => 'YUNDA', + 'juhe' => 'yd', 'kuaidi100' => 'yunda', - 'kdniao' => 'YD', + 'kdniao' => 'YD', ], ], [ 'name' => '天天快递', - 'code' => - [ - 'aliyun' => 'TTKDEX', - 'juhe' => 'tt', + 'code' => [ + 'aliyun' => 'TTKDEX', + 'juhe' => 'tt', 'kuaidi100' => 'tiantian', - 'kdniao' => 'HHTT', + 'kdniao' => 'HHTT', ], ], [ 'name' => 'EMS', - 'code' => - [ - 'aliyun' => 'EMS', - 'juhe' => 'ems', + 'code' => [ + 'aliyun' => 'EMS', + 'juhe' => 'ems', 'kuaidi100' => 'ems', - 'kdniao' => 'EMS', + 'kdniao' => 'EMS', ], ], [ 'name' => 'EMS国际', - 'code' => - [ - 'aliyun' => 'EMS', - 'juhe' => 'emsg', + 'code' => [ + 'aliyun' => 'EMS', + 'juhe' => 'emsg', 'kuaidi100' => 'emsguoji', - 'kdniao' => 'EMSGJ', + 'kdniao' => 'EMSGJ', ], ], [ 'name' => '马来西亚EMS', - 'code' => - [ - 'aliyun' => '', - 'juhe' => 'malaysiaems', + 'code' => [ + 'aliyun' => '', + 'juhe' => 'malaysiaems', 'kuaidi100' => 'malaysiaems', - 'kdniao' => 'IMLXYEMS', + 'kdniao' => 'IMLXYEMS', ], ], [ 'name' => '邮政国内标快', - 'code' => - [ - 'aliyun' => '', - 'juhe' => 'yzgn', + 'code' => [ + 'aliyun' => '', + 'juhe' => 'yzgn', 'kuaidi100' => 'youzhengguonei', - 'kdniao' => 'YZBK', + 'kdniao' => 'YZBK', ], ], [ 'name' => '汇通', - 'code' => - [ - 'aliyun' => '', - 'juhe' => 'ht', + 'code' => [ + 'aliyun' => '', + 'juhe' => 'ht', 'kuaidi100' => 'huitongkuaidi', - 'kdniao' => '', + 'kdniao' => '', ], ], [ 'name' => '全峰', - 'code' => - [ - 'aliyun' => 'QFKD', - 'juhe' => 'qf', + 'code' => [ + 'aliyun' => 'QFKD', + 'juhe' => 'qf', 'kuaidi100' => 'quanfengkuaidi', - 'kdniao' => '', + 'kdniao' => '', ], ], [ 'name' => '德邦快递', - 'code' => - [ - 'aliyun' => 'DEPPON', - 'juhe' => 'db', + 'code' => [ + 'aliyun' => 'DEPPON', + 'juhe' => 'db', 'kuaidi100' => 'debangwuliu', - 'kdniao' => 'DBL', + 'kdniao' => 'DBL', ], ], [ 'name' => '国通快递', - 'code' => - [ - 'aliyun' => 'GTO', - 'juhe' => 'gt', + 'code' => [ + 'aliyun' => 'GTO', + 'juhe' => 'gt', 'kuaidi100' => 'guotongkuaidi', - 'kdniao' => '', + 'kdniao' => '', ], ], [ 'name' => '如风达', - 'code' => - [ - 'aliyun' => 'RFD', - 'juhe' => 'rfd', + 'code' => [ + 'aliyun' => 'RFD', + 'juhe' => 'rfd', 'kuaidi100' => 'rufengda', - 'kdniao' => 'RFD', + 'kdniao' => 'RFD', ], ], [ 'name' => '京东快递', - 'code' => - [ - 'aliyun' => 'JD', - 'juhe' => 'jd', + 'code' => [ + 'aliyun' => 'JD', + 'juhe' => 'jd', 'kuaidi100' => 'jd', - 'kdniao' => 'JD', + 'kdniao' => 'JD', ], ], [ 'name' => '宅急送', - 'code' => - [ - 'aliyun' => 'ZJS', - 'juhe' => 'zjs', + 'code' => [ + 'aliyun' => 'ZJS', + 'juhe' => 'zjs', 'kuaidi100' => 'zhaijisong', - 'kdniao' => 'ZJS', + 'kdniao' => 'ZJS', ], ], [ 'name' => 'Fedex', - 'code' => - [ - 'aliyun' => 'FEDEXIN', - 'juhe' => 'fedex', + 'code' => [ + 'aliyun' => 'FEDEXIN', + 'juhe' => 'fedex', 'kuaidi100' => 'fedexcn', - 'kdniao' => 'FEDEX', + 'kdniao' => 'FEDEX', ], ], [ 'name' => 'Fedex国际', - 'code' => - [ - 'aliyun' => 'FEDEXIN', - 'juhe' => 'fedex', + 'code' => [ + 'aliyun' => 'FEDEXIN', + 'juhe' => 'fedex', 'kuaidi100' => 'fedex', - 'kdniao' => 'FEDEX_GJ', + 'kdniao' => 'FEDEX_GJ', ], ], [ 'name' => 'UPS', - 'code' => - [ - 'aliyun' => 'UPS', - 'juhe' => 'ups', + 'code' => [ + 'aliyun' => 'UPS', + 'juhe' => 'ups', 'kuaidi100' => 'ups', - 'kdniao' => 'UPS', + 'kdniao' => 'UPS', ], ], [ 'name' => '中铁物流', - 'code' => - [ - 'aliyun' => '', - 'juhe' => '', + 'code' => [ + 'aliyun' => '', + 'juhe' => '', 'kuaidi100' => 'zhongtiewuliu', - 'kdniao' => 'ZHWL', + 'kdniao' => 'ZHWL', ], ], [ 'name' => '中铁快运', - 'code' => - [ - 'aliyun' => 'CRE', - 'juhe' => 'ztky', + 'code' => [ + 'aliyun' => 'CRE', + 'juhe' => 'ztky', 'kuaidi100' => 'ztky', - 'kdniao' => 'ZTKY', + 'kdniao' => 'ZTKY', ], ], [ 'name' => '佳吉快运', - 'code' => - [ - 'aliyun' => 'JIAJI', - 'juhe' => 'jiaji', + 'code' => [ + 'aliyun' => 'JIAJI', + 'juhe' => 'jiaji', 'kuaidi100' => 'jiajiwuliu', - 'kdniao' => 'CNEX', + 'kdniao' => 'CNEX', ], ], [ 'name' => '速尔快递', - 'code' => - [ - 'aliyun' => 'SURE', - 'juhe' => 'suer', + 'code' => [ + 'aliyun' => 'SURE', + 'juhe' => 'suer', 'kuaidi100' => 'suer', - 'kdniao' => 'SURE', + 'kdniao' => 'SURE', ], ], [ 'name' => '信丰物流', - 'code' => - [ - 'aliyun' => 'XFEXPRESS', - 'juhe' => 'xfwl', + 'code' => [ + 'aliyun' => 'XFEXPRESS', + 'juhe' => 'xfwl', 'kuaidi100' => 'xinfengwuliu', - 'kdniao' => 'XFEX', + 'kdniao' => 'XFEX', ], ], [ 'name' => '优速快递', - 'code' => - [ - 'aliyun' => 'UC56', - 'juhe' => 'yousu', + 'code' => [ + 'aliyun' => 'UC56', + 'juhe' => 'yousu', 'kuaidi100' => 'youshuwuliu', - 'kdniao' => 'UC', + 'kdniao' => 'UC', ], ], [ 'name' => '中邮物流', - 'code' => - [ - 'aliyun' => 'ZYWL', - 'juhe' => 'zhongyou', + 'code' => [ + 'aliyun' => 'ZYWL', + 'juhe' => 'zhongyou', 'kuaidi100' => 'zhongyouwuliu', - 'kdniao' => 'ZYWL', + 'kdniao' => 'ZYWL', ], ], [ 'name' => '中邮快递', - 'code' => - [ - 'aliyun' => '', - 'juhe' => '', + 'code' => [ + 'aliyun' => '', + 'juhe' => '', 'kuaidi100' => 'wondersyd', - 'kdniao' => 'ZYKD', + 'kdniao' => 'ZYKD', ], ], [ 'name' => '天地华宇', - 'code' => - [ - 'aliyun' => 'HOAU', - 'juhe' => 'tdhy', + 'code' => [ + 'aliyun' => 'HOAU', + 'juhe' => 'tdhy', 'kuaidi100' => 'tiandihuayu', - 'kdniao' => 'HOAU', + 'kdniao' => 'HOAU', ], ], [ 'name' => '安信达', - 'code' => - [ - 'aliyun' => 'ANXINDA', - 'juhe' => 'axd', + 'code' => [ + 'aliyun' => 'ANXINDA', + 'juhe' => 'axd', 'kuaidi100' => 'anxindakuaixi', - 'kdniao' => '', + 'kdniao' => '', ], ], [ 'name' => '快捷快递', - 'code' => - [ - 'aliyun' => 'FASTEXPRESS', - 'juhe' => 'kuaijie', + 'code' => [ + 'aliyun' => 'FASTEXPRESS', + 'juhe' => 'kuaijie', 'kuaidi100' => 'kuaijiesudi', - 'kdniao' => 'DJKJWL', + 'kdniao' => 'DJKJWL', ], ], [ 'name' => 'AAE全球专递', - 'code' => - [ - 'aliyun' => 'AAEWEB', - 'juhe' => 'aae', + 'code' => [ + 'aliyun' => 'AAEWEB', + 'juhe' => 'aae', 'kuaidi100' => 'aae', - 'kdniao' => 'AAE', + 'kdniao' => 'AAE', ], ], [ 'name' => 'DHL国内件', - 'code' => - [ - 'aliyun' => 'DHL', - 'juhe' => 'dhl', + 'code' => [ + 'aliyun' => 'DHL', + 'juhe' => 'dhl', 'kuaidi100' => 'dhl', - 'kdniao' => 'DHL_C', + 'kdniao' => 'DHL_C', ], ], [ 'name' => 'DHL国际件', - 'code' => - [ - 'aliyun' => 'DHL_EN', - 'juhe' => 'dhl', + 'code' => [ + 'aliyun' => 'DHL_EN', + 'juhe' => 'dhl', 'kuaidi100' => 'dhlen', - 'kdniao' => 'DHL_GLB', + 'kdniao' => 'DHL_GLB', ], ], [ 'name' => 'DPEX国际', - 'code' => - [ - 'aliyun' => 'DPEX', - 'juhe' => 'dpex', + 'code' => [ + 'aliyun' => 'DPEX', + 'juhe' => 'dpex', 'kuaidi100' => 'dpex', - 'kdniao' => 'DPEX', + 'kdniao' => 'DPEX', ], ], [ 'name' => 'D速物流', - 'code' => - [ - 'aliyun' => 'DEXP', - 'juhe' => 'ds', + 'code' => [ + 'aliyun' => 'DEXP', + 'juhe' => 'ds', 'kuaidi100' => 'dsukuaidi', - 'kdniao' => 'DSWL', + 'kdniao' => 'DSWL', ], ], [ 'name' => 'FEDEX国内', - 'code' => - [ - 'aliyun' => 'FEDEX', - 'juhe' => 'fedexcn', + 'code' => [ + 'aliyun' => 'FEDEX', + 'juhe' => 'fedexcn', 'kuaidi100' => 'fedexcn', - 'kdniao' => 'FEDEX', + 'kdniao' => 'FEDEX', ], ], [ 'name' => 'FEDEX国际', - 'code' => - [ - 'aliyun' => 'FEDEXIN', - 'juhe' => 'fedexcn', + 'code' => [ + 'aliyun' => 'FEDEXIN', + 'juhe' => 'fedexcn', 'kuaidi100' => 'fedex', - 'kdniao' => 'FEDEX_GJ', + 'kdniao' => 'FEDEX_GJ', ], ], [ 'name' => 'OCS', - 'code' => - [ - 'aliyun' => '', - 'juhe' => 'ocs', + 'code' => [ + 'aliyun' => '', + 'juhe' => 'ocs', 'kuaidi100' => 'ocs', - 'kdniao' => 'OCS', + 'kdniao' => 'OCS', ], ], [ 'name' => 'TNT', - 'code' => - [ - 'aliyun' => 'TNT', - 'juhe' => 'tnt', + 'code' => [ + 'aliyun' => 'TNT', + 'juhe' => 'tnt', 'kuaidi100' => 'tnt', - 'kdniao' => 'TNT', + 'kdniao' => 'TNT', ], ], [ 'name' => 'COE东方快递', - 'code' => - [ - 'aliyun' => 'COE', - 'juhe' => 'coe', + 'code' => [ + 'aliyun' => 'COE', + 'juhe' => 'coe', 'kuaidi100' => 'coe', - 'kdniao' => 'COE', + 'kdniao' => 'COE', ], ], [ 'name' => '传喜物流', - 'code' => - [ - 'aliyun' => '', - 'juhe' => 'cxwl', + 'code' => [ + 'aliyun' => '', + 'juhe' => 'cxwl', 'kuaidi100' => 'chuanxiwuliu', - 'kdniao' => 'CXHY', + 'kdniao' => 'CXHY', ], ], [ 'name' => '城市100', - 'code' => - [ - 'aliyun' => 'CITY100', - 'juhe' => 'cs', + 'code' => [ + 'aliyun' => 'CITY100', + 'juhe' => 'cs', 'kuaidi100' => 'city100', - 'kdniao' => 'CITY100', + 'kdniao' => 'CITY100', ], ], [ 'name' => '安捷快递', - 'code' => - [ - 'aliyun' => 'ANJELEX', - 'juhe' => 'aj', + 'code' => [ + 'aliyun' => 'ANJELEX', + 'juhe' => 'aj', 'kuaidi100' => 'anjie88', - 'kdniao' => 'AJ', + 'kdniao' => 'AJ', ], ], [ 'name' => '百福东方', - 'code' => - [ - 'aliyun' => 'EES', - 'juhe' => 'bfdf', + 'code' => [ + 'aliyun' => 'EES', + 'juhe' => 'bfdf', 'kuaidi100' => 'baifudongfang', - 'kdniao' => 'BFDF', + 'kdniao' => 'BFDF', ], ], [ 'name' => '程光物流', - 'code' => - [ - 'aliyun' => 'FLYWAYEX', - 'juhe' => 'chengguang', + 'code' => [ + 'aliyun' => 'FLYWAYEX', + 'juhe' => 'chengguang', 'kuaidi100' => 'chengguangkuaidi', - 'kdniao' => 'CG', + 'kdniao' => 'CG', ], ], [ 'name' => '递四方速递', - 'code' => - [ - 'aliyun' => 'D4PX', - 'juhe' => 'dsf', + 'code' => [ + 'aliyun' => 'D4PX', + 'juhe' => 'dsf', 'kuaidi100' => 'disifang', - 'kdniao' => 'D4PX', + 'kdniao' => 'D4PX', ], ], [ 'name' => '飞豹快递', - 'code' => - [ - 'aliyun' => '', - 'juhe' => 'feibao', + 'code' => [ + 'aliyun' => '', + 'juhe' => 'feibao', 'kuaidi100' => 'feibaokuaidi', - 'kdniao' => 'FBKD', + 'kdniao' => 'FBKD', ], ], [ 'name' => '安能物流', - 'code' => - [ - 'aliyun' => 'ANE', - 'juhe' => 'ane66', + 'code' => [ + 'aliyun' => 'ANE', + 'juhe' => 'ane66', 'kuaidi100' => 'annengwuliu', - 'kdniao' => 'ANE', + 'kdniao' => 'ANE', ], ], [ 'name' => '远成物流', - 'code' => - [ - 'aliyun' => 'YCGWL', - 'juhe' => 'ycgky', + 'code' => [ + 'aliyun' => 'YCGWL', + 'juhe' => 'ycgky', 'kuaidi100' => 'yuanchengwuliu', - 'kdniao' => 'YCWL', + 'kdniao' => 'YCWL', ], ], [ 'name' => '邮政快递包裹', - 'code' => - [ - 'aliyun' => 'CHINAPOST', - 'juhe' => 'youzheng', + 'code' => [ + 'aliyun' => 'CHINAPOST', + 'juhe' => 'youzheng', 'kuaidi100' => 'youzhengbk', - 'kdniao' => 'YZPY', + 'kdniao' => 'YZPY', ], ], [ 'name' => '百世快递', - 'code' => - [ - 'aliyun' => 'BSKY', - 'juhe' => 'bsky', + 'code' => [ + 'aliyun' => 'BSKY', + 'juhe' => 'bsky', 'kuaidi100' => 'huitongkuaidi', - 'kdniao' => 'HTKY', + 'kdniao' => 'HTKY', ], ], [ 'name' => '苏宁物流', - 'code' => - [ - 'aliyun' => 'SUNING', - 'juhe' => 'suning', + 'code' => [ + 'aliyun' => 'SUNING', + 'juhe' => 'suning', 'kuaidi100' => 'suning', - 'kdniao' => 'SNWL', + 'kdniao' => 'SNWL', ], ], [ 'name' => '九曳供应链', - 'code' => - [ - 'aliyun' => 'JIUYESCM', - 'juhe' => 'jiuye', + 'code' => [ + 'aliyun' => 'JIUYESCM', + 'juhe' => 'jiuye', 'kuaidi100' => 'jiuyescm', - 'kdniao' => 'JIUYE', + 'kdniao' => 'JIUYE', ], ], [ 'name' => '亚马逊物流', - 'code' => - [ - 'aliyun' => '', - 'juhe' => '', + 'code' => [ + 'aliyun' => '', + 'juhe' => '', 'kuaidi100' => 'yamaxunwuliu', - 'kdniao' => 'AMAZON', + 'kdniao' => 'AMAZON', ], ], [ 'name' => '环球速运', - 'code' => - [ - 'aliyun' => '', - 'juhe' => '', + 'code' => [ + 'aliyun' => '', + 'juhe' => '', 'kuaidi100' => 'huanqiu', - 'kdniao' => 'HQSY', + 'kdniao' => 'HQSY', ], ], -]; \ No newline at end of file +]; diff --git a/src/config/config.php b/src/config/config.php index d8a0d26..956ac56 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -1,43 +1,53 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + return [ /* * 全局 http * 请求配置 参考 https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html */ - 'http' => [ - 'timeout' => 5.0, - 'connect_timeout' => 5.0 + 'http' => [ + 'timeout' => 5.0, + 'connect_timeout' => 5.0, ], /* * 默认网关配置,如果设置此项,则只会使用该网关请求,否则会循环 gateways 调用请求不同的网关 */ - 'default' => '', + 'default' => '', /* * 禁用网关,默认情况下会循环调用 gateways 下的所有可用网关,你可以添加网关名称到此禁用 */ - 'disable' => [], + 'disable' => [], /* * 网关配置 */ - 'gateways' => [ + 'gateways' => [ 'kuaidi100' => [ - 'key' => env('LOGISTICS_APP_KEY_KD100'), // key + 'key' => env('LOGISTICS_APP_KEY_KD100'), // key 'customer' => env('LOGISTICS_SECRET_KD100'), // customer /* * 可以单独为指定的网关配置 http 请求信息,未设置则读取全局 */ - 'http' => [ - 'timeout' => 15.0, - 'connect_timeout' => 15.0 + 'http' => [ + 'timeout' => 15.0, + 'connect_timeout' => 15.0, ], ], - 'kdniao' => [ - 'appKey' => env('LOGISTICS_APP_KEY_KDNIAN'), // appKey + 'kdniao' => [ + 'appKey' => env('LOGISTICS_APP_KEY_KDNIAN'), // appKey 'EBusinessID' => env('LOGISTICS_SECRET_KDNIAN'), // EBusinessID ], // ... @@ -46,5 +56,5 @@ /* * 格外配置物流公司列表 */ - 'company_file' => [] -]; \ No newline at end of file + 'company_file' => [], +];