Skip to content

Commit

Permalink
Merge pull request #40 from liushuai/feat-k5
Browse files Browse the repository at this point in the history
纵横物流 增加获取跟踪号 方法
  • Loading branch information
icowan authored Dec 31, 2020
2 parents bfe5dad + e1ac460 commit d055968
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/platforms/CourierbutlerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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()));
Expand Down Expand Up @@ -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"]);
Expand Down

0 comments on commit d055968

Please sign in to comment.