PHP code example of daley / logistics
1. Go to this page and download the library: Download daley/logistics library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
daley / logistics example snippets
use Daley\Logistics\Logistics;
// 使用不到的渠道不传即可
$logistics = new Logistics([
// 快递100配置
'kuaidi100' => [
'app_key' => '',
'app_secret' => '',
],
// 快递鸟配置
'kuaidibird' => [
'app_key' => '', // 用户ID
'app_secret' => '', // API key
'vip' => false, // 是否付费用户
],
// 急速快递配置
'jisu' => [
'app_key' => ''
],
]);
// 查询物流
try {
var_dump($logistics->query('73129084446868', 'zhongtong'));
} catch (\Daley\Logistics\Exceptions\HttpException $exception) {
// HTTP请求异常
} catch (\Daley\Logistics\Exceptions\InvalidArgumentException $exception) {
// 参数异常
} catch (\Daley\Logistics\Exceptions\NoAvailableException $exception) {
// 没有成功数据
} catch (Exception $exception) {
// 其他异常
}
// 不设置默认使用快递100
$logistics->setChannel('kuaiDiBird')->query('73129084446868');
// 查询多渠道
$logistics->setChannel(['kuaiDi100', 'kuaiDiBird'])->query('73129084446868');
// 成功返回
[
'kuaidi100' => [
'channel' => 'kuaiDi100',
'status' => 'success',
'result' => [
[
'status' => 1,
'message' => 'ok',
'error_code' => 0,
'data' => [
['time' => '2020-06-25 00:00:00', 'description' => '仓库-已签收'],
['time' => '2020-06-25 00:00:00', 'description' => '广东XX服务点'],
['time' => '2020-06-25 00:00:00', 'description' => '广东XX转运中心'],
],
'logistics_company' => 'zhongtong',
],
]
]
]
// 失败返回
[
'kuaidi100' => [
'channel' => 'kuaiDi100',
'status' => 'failure',
'exception' => '数据不完整',
],
]
public function edit(Logistics $logistics)
{
$response = $logistics->setChannel('kuaiDi100')->query('73129084446868', 'zhongtong');
}
public function edit()
{
$response = app('logistics')->setChannel('kuaiDi100')->query('73129084446868', 'zhongtong');
}
shell
$ php artisan vendor:publish --provider=Daley\Logistics\Laravel\LogisticsServiceProvider --tag=logistics