daley / logistics
通用快递查询SDK, 支持多家快递查询渠道
1.0.1
2020-06-27 09:54 UTC
Requires
- php: >=5.6
- ext-json: *
- guzzlehttp/guzzle: 6.x || 7.x
Requires (Dev)
- mockery/mockery: ^1.1
- phpunit/phpunit: ~5 || ~7
This package is auto-updated.
Last update: 2024-09-06 13:37:13 UTC
README
一个简单便捷查询运单快递信息的SDK.
支持查询接口平台
- 爱查快递、百度快递为抓取接口,无法保证数据准确性与稳定性. 无法查询顺丰快递.
环境需求
- PHP >= 5.6
安装
$ composer require daley/logistics
使用
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) { // 其他异常 }
参数说明
array query(string $code [, mixed $company = null, string $phone])
- $code - 运单号
- $company - 快递公司编码 参考各渠道提供的渠道列表 不填为自动抓取 不保证准确性 多公司时使用数组 如
['kuaidi100' => 'zhongtong', 'kuaidibird' => 'ZTO']
- $phone - 寄件 / 收件 手机号码 查询顺丰时需要用到
更换查询渠道
// 不设置默认使用快递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' => '数据不完整', ], ]
- 所有渠道返回格式均一致
Laravel 中使用
- 发布配置
$ php artisan vendor:publish --provider=Daley\Logistics\Laravel\LogisticsServiceProvider --tag=logistics
- 随后,请在
config
文件夹中完善配置信息。 - 方法参数注入
public function edit(Logistics $logistics) { $response = $logistics->setChannel('kuaiDi100')->query('73129084446868', 'zhongtong'); }
- 服务名访问
public function edit() { $response = app('logistics')->setChannel('kuaiDi100')->query('73129084446868', 'zhongtong'); }
License
MIT