56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
namespace App\Logistics;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
/**
|
|
* 阿里云全国物流快递查询
|
|
*/
|
|
class Logistic
|
|
{
|
|
protected $baseUrl = 'https://cexpress.market.alicloudapi.com/';
|
|
protected $appCode = '2c5ebf8a97d24a26b5b18f17a6df7fd5';
|
|
protected $params = [];
|
|
protected $no;
|
|
protected $type;
|
|
|
|
public function getMessage($type, $no)
|
|
{
|
|
$apiUrl = $this->baseUrl . 'cexpress';
|
|
$headers = ['Authorization' => "APPCODE " . $this->appCode];
|
|
$this->setParams($type, $no);
|
|
$result = $this->dopost($apiUrl, $headers);
|
|
if ($result->code == 'OK') {
|
|
return [
|
|
'code' => $result->code,
|
|
'name' => $result->name,
|
|
'logo' => $result->logo,
|
|
'no' => $result->no,
|
|
'list' => $result->list,
|
|
];
|
|
} else {
|
|
return ['code' => $result->code, 'msg' => $result->msg];
|
|
}
|
|
}
|
|
|
|
public function setParams($type, $no)
|
|
{
|
|
$this->params = [
|
|
'no' => $no,
|
|
'type' => $type,
|
|
];
|
|
}
|
|
|
|
private function dopost($url, array $headers)
|
|
{
|
|
try {
|
|
$Client = new Client();
|
|
$response = $Client->get($url, ['query' => $this->params, 'headers' => $headers]);
|
|
$result = json_decode($response->getBody()->getContents());
|
|
return $result;
|
|
} catch (\Exception $e) {
|
|
return $e->getmessage();
|
|
}
|
|
}
|
|
}
|