更新代码
This commit is contained in:
55
app/Logistics/Logistic.php
Normal file
55
app/Logistics/Logistic.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
app/Logistics/LogisticFacade.php
Normal file
13
app/Logistics/LogisticFacade.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Logistics;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class LogisticFacade extends Facade
|
||||
{
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return Logistic::class;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user