文件
建立ExpressQuery.php
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
trait ExpressQuery
{
protected $express_api_url = 'http://wuliu.market.alicloudapi.com/kdi';
protected $appCode;
protected $params = [];
//設定運單號
protected function setNo($no)
{
$this->params['no'] = $no;
return $this;
}
//設定物流公司
protected function setType($type)
{
$this->params['type'] = $type;
return $this;
}
protected function setAppCode($appCode)
{
$this->appCode = 'APPCODE '.$appCode;
return $this;
}
protected function query()
{
$res = Http::WithHeaders([
'Authorization' => $this->appCode
])->get($this->express_api_url,$this->params)
->getBody()
->getContents();
return json_decode($res);
}
}
測試
扯淡
因為要做物流查詢,看了快遞100、愛快遞查詢、快鳥,好麻煩(又是一堆申請、認證)。
感謝阿里云云市場,直接購買就好了,方便多了。
本作品採用《CC 協議》,轉載必須註明作者和本文連結