使用阿里云 [云市场] 做物流查询
文档
创建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 协议》,转载必须注明作者和本文链接