Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

纵横物流 增加获取跟踪号 方法 #40

Merged
merged 1 commit into from
Dec 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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