Skip to content

Commit

Permalink
Merge pull request #19 from finecho/analysis-8QnGgO
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
thisliu authored May 29, 2019
2 parents 2e2a6bd + 0331720 commit 56db29b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 60 deletions.
128 changes: 73 additions & 55 deletions src/Providers/Kdniao.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,51 +36,72 @@ class Kdniao extends AbstractProvider

const LOGISTICS_COM_CODE_URL = 'http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx';

const SUCCESS_STATUS = 200;
const STATUS_ERROR = -1;
const STATUS_NO_TRACK = 0;
const STATUS_PACKAGE = 1;
const STATUS_ON_THE_WAY = 2;
const STATUS_SIGNING = 3;
const STATUS_QUESTION_PACKAGE = 4;
const STATUS_IN_THE_CITY = 201;
const STATUS_IN_THE_PACKAGE = 202;
const STATUS_DIEPOSIT_ARK = 211;
const STATUS_NORMAL_SIGNING = 301;
const STATUS_ABNORMAL_SIGNING = 302;
const STATUS_ISSUING_SIGNING = 304;
const STATUS_ARK_SIGNING = 311;
const STATUS_NO_DELIVERY_INFO = 401;
const SUCCESS_STATUS = 200;

const STATUS_ERROR = -1;

const STATUS_NO_TRACK = 0;

const STATUS_PACKAGE = 1;

const STATUS_ON_THE_WAY = 2;

const STATUS_SIGNING = 3;

const STATUS_QUESTION_PACKAGE = 4;

const STATUS_IN_THE_CITY = 201;

const STATUS_IN_THE_PACKAGE = 202;

const STATUS_DIEPOSIT_ARK = 211;

const STATUS_NORMAL_SIGNING = 301;

const STATUS_ABNORMAL_SIGNING = 302;

const STATUS_ISSUING_SIGNING = 304;

const STATUS_ARK_SIGNING = 311;

const STATUS_NO_DELIVERY_INFO = 401;

const STATUS_TIMEOUT_NOT_SIGNING = 402;
const STATUS_TIMEOUT_NOT_UPDATE = 403;
const STATUS_RETURN_PACKAGE = 404;
const STATUS_PACKAGE_ERROR = 405;
const STATUS_RETURN_SINGNING = 406;

const STATUS_TIMEOUT_NOT_UPDATE = 403;

const STATUS_RETURN_PACKAGE = 404;

const STATUS_PACKAGE_ERROR = 405;

const STATUS_RETURN_SINGNING = 406;

const STATUS_RETURN_NOT_SINGNING = 407;
const STATUS_ARK_NOT_SINGNING = 412;

const STATUS_ARK_NOT_SINGNING = 412;

const STATUS_LABELS = [
self::STATUS_ERROR => '异常',
self::STATUS_NO_TRACK => '无轨迹',
self::STATUS_PACKAGE => '已揽收',
self::STATUS_SIGNING => '已签收',
self::STATUS_ON_THE_WAY => '在途中',
self::STATUS_QUESTION_PACKAGE => '问题件',
self::STATUS_IN_THE_CITY => '到达派件城市',
self::STATUS_IN_THE_PACKAGE => '派件中',
self::STATUS_DIEPOSIT_ARK => '已放入快递柜或驿站',
self::STATUS_NORMAL_SIGNING => '正常签收',
self::STATUS_ABNORMAL_SIGNING => '派件异常后最终签收',
self::STATUS_ISSUING_SIGNING => '代收签收',
self::STATUS_ARK_SIGNING => '快递柜或驿站签收',
self::STATUS_NO_DELIVERY_INFO => '发货无信息',
self::STATUS_ERROR => '异常',
self::STATUS_NO_TRACK => '无轨迹',
self::STATUS_PACKAGE => '已揽收',
self::STATUS_SIGNING => '已签收',
self::STATUS_ON_THE_WAY => '在途中',
self::STATUS_QUESTION_PACKAGE => '问题件',
self::STATUS_IN_THE_CITY => '到达派件城市',
self::STATUS_IN_THE_PACKAGE => '派件中',
self::STATUS_DIEPOSIT_ARK => '已放入快递柜或驿站',
self::STATUS_NORMAL_SIGNING => '正常签收',
self::STATUS_ABNORMAL_SIGNING => '派件异常后最终签收',
self::STATUS_ISSUING_SIGNING => '代收签收',
self::STATUS_ARK_SIGNING => '快递柜或驿站签收',
self::STATUS_NO_DELIVERY_INFO => '发货无信息',
self::STATUS_TIMEOUT_NOT_SIGNING => '超时未签收',
self::STATUS_TIMEOUT_NOT_UPDATE => '超时未更新',
self::STATUS_RETURN_PACKAGE => '拒收(退件)',
self::STATUS_PACKAGE_ERROR => '派件异常',
self::STATUS_RETURN_SINGNING => '退货签收',
self::STATUS_TIMEOUT_NOT_UPDATE => '超时未更新',
self::STATUS_RETURN_PACKAGE => '拒收(退件)',
self::STATUS_PACKAGE_ERROR => '派件异常',
self::STATUS_RETURN_SINGNING => '退货签收',
self::STATUS_RETURN_NOT_SINGNING => '退货未签收',
self::STATUS_ARK_NOT_SINGNING => '快递柜或驿站超时未取',
self::STATUS_ARK_NOT_SINGNING => '快递柜或驿站超时未取',
];

/**
Expand All @@ -95,7 +116,6 @@ class Kdniao extends AbstractProvider
*/
public function order($no, $company = null)
{

if (empty($company)) {
$query['LogisticCode'] = $no;

Expand All @@ -113,9 +133,8 @@ public function order($no, $company = null)

$param['ShipperCode'] = $response['Shippers'][0]['ShipperCode'];
} else {

$param['ShipperCode'] = $this->getLogisticsCompanyAliases($company);
$this->company = $company;
$this->company = $company;
}

$param['LogisticCode'] = $no;
Expand All @@ -125,7 +144,7 @@ public function order($no, $company = null)
$response = $this->sendRequestPost(self::LOGISTICS_INFO_URL, $params, [], self::SUCCESS_STATUS);

// 处理未付费用户
if ($response && $response['Success'] == false) {
if ($response && false == $response['Success']) {
$params['RequestType'] = self::KDNIAO_NOT_PAY;

$response = $this->sendRequestPost(
Expand All @@ -140,20 +159,19 @@ public function order($no, $company = null)
}

/**
* @param $requestData
* @param $requestType
* @param $requestData
* @param $requestType
*
* @return array
*
*/
private function getRequestParams($requestData, $requestType = self::KDNIAO_PAY)
{
return [
'EBusinessID' => $this->config[\strtolower(self::PROVIDER_NAME)]['customer'],
'DataType' => self::KDNIAO_DATA_TYPE,
'DataType' => self::KDNIAO_DATA_TYPE,
'RequestType' => $requestType,
'RequestData' => \urlencode(\json_encode($requestData)),
'DataSign' => $this->generateSign($requestData, $this->config[\strtolower(self::PROVIDER_NAME)]['app_code']),
'DataSign' => $this->generateSign($requestData, $this->config[\strtolower(self::PROVIDER_NAME)]['app_code']),
];
}

Expand Down Expand Up @@ -199,12 +217,12 @@ protected function mapLogisticsOrderToObject($logisticsOrder)
$list = $this->resetList($logisticsOrder['Traces']);

return new Order([
'code' => self::GLOBAL_SUCCESS_CODE,
'msg' => self::GLOBAL_SUCCESS_MSG,
'company' => $this->company ?: $logisticsOrder['ShipperCode'],
'no' => $logisticsOrder['LogisticCode'],
'status' => \in_array($status, \array_keys(self::STATUS_LABELS)) ? self::STATUS_LABELS[$status] : self::STATUS_LABELS[self::STATUS_ERROR],
'list' => $list,
'code' => self::GLOBAL_SUCCESS_CODE,
'msg' => self::GLOBAL_SUCCESS_MSG,
'company' => $this->company ?: $logisticsOrder['ShipperCode'],
'no' => $logisticsOrder['LogisticCode'],
'status' => \in_array($status, \array_keys(self::STATUS_LABELS)) ? self::STATUS_LABELS[$status] : self::STATUS_LABELS[self::STATUS_ERROR],
'list' => $list,
'original' => $logisticsOrder,
]);
}
Expand Down Expand Up @@ -265,6 +283,6 @@ public function getProviderName()
*/
protected function generateSign($param, $key)
{
return urlencode(base64_encode(md5(\json_encode($param) . $key)));
return urlencode(base64_encode(md5(\json_encode($param).$key)));
}
}
10 changes: 5 additions & 5 deletions tests/Providers/KdniaoProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public function testGetLogisticsInfo()
$config = [
'provider' => 'kdniao',

'kdniao' => [
'kdniao' => [
'app_code' => 'd7696d82-95d5-4922-ab95-4e0adee0fe8c',
'customer' => '1270293',
]];
], ];

$response = '{
"LogisticCode": "805741929402797742",
Expand Down Expand Up @@ -84,16 +84,16 @@ public function testGetLogisticsInfo()

$response = json_decode($response, true);

$Kdniao = \Mockery::mock(Kdniao::class . '[post]', [$config])->shouldAllowMockingProtectedMethods();
$Kdniao = \Mockery::mock(Kdniao::class.'[post]', [$config])->shouldAllowMockingProtectedMethods();

$param = ['ShipperCode' => 'YTO', 'LogisticCode' => '805741929402797742'];

$params = [
'EBusinessID' => $config['kdniao']['customer'],
'RequestType' => 8001,
'DataType' => 2,
'DataType' => 2,
'RequestData' => \urlencode(\json_encode($param)),
'DataSign' => urlencode(base64_encode(md5(\json_encode($param) . $config['kdniao']['app_code']))),
'DataSign' => urlencode(base64_encode(md5(\json_encode($param).$config['kdniao']['app_code']))),
];

$Kdniao->shouldReceive('post')->with(
Expand Down

0 comments on commit 56db29b

Please sign in to comment.