项目作者: finecho

项目描述 :
Logistics query extension package
高级语言: PHP
项目地址: git://github.com/finecho/logistics.git
创建时间: 2019-05-05T15:13:23Z
项目社区:https://github.com/finecho/logistics

开源协议:MIT License

下载


❤️ Logistics

快递物流查询-快递查询接口组件。

Build Status
Latest Stable Version
Total Downloads
Latest Unstable Version
License

介绍

目前已支持四家平台

安装

  1. $ composer require finecho/logistics -vvv

使用

  1. require __DIR__ .'/vendor/autoload.php';
  2. use Finecho\Logistics\Logistics;
  3. $config = [
  4. 'provider' => 'aliyun', // aliyun/juhe/kd100
  5. 'aliyun' => [
  6. 'app_code' => 'xxxxxxxx',
  7. ],
  8. 'juhe' => [
  9. 'app_code' => 'xxxxx',
  10. ],
  11. 'kdniao' => [
  12. 'app_code' => 'xxxxx',
  13. 'customer' => 'xxxxx',
  14. ],
  15. 'kd100' => [
  16. 'app_code' => 'xxxxx',
  17. 'customer' => 'xxxxx',
  18. ],
  19. ];
  20. $logistics = new Logistics($config);

获取物流公司列表

  1. $companies = $logistics->companies();

示例:

  1. [
  2. "顺丰",
  3. "申通",
  4. "中通",
  5. "圆通"
  6. ]

获取物流信息

  1. $order = $logistics->query('805741929402797742', '圆通');

示例:

  1. {
  2. "code": 200,
  3. "msg": "OK",
  4. "company": "圆通",
  5. "no": "805741929402797742",
  6. "status": 4,
  7. "display_status": "已签收",
  8. "abstract_status": {
  9. "has_active" : true,
  10. "has_ended" : true,
  11. "has_signed" : true,
  12. "has_troubled" : false,
  13. "has_returned" : false
  14. },
  15. "list": [
  16. {
  17. "datetime": "2019-05-07 18:02:27",
  18. "remark": "山东省淄博市淄川区三部公司取件人:司健(15553333300)已收件",
  19. "zone": ""
  20. },
  21. {
  22. "datetime": "2019-05-09 12:44:40",
  23. "remark": "快件已签收签收人:邮件收发章感谢使用圆通速递,期待再次为您服务",
  24. "zone": ""
  25. }
  26. ],
  27. "original": {
  28. "resultcode": "200",
  29. "reason": "成功的返回",
  30. "result": {
  31. "company": "圆通",
  32. "com": "yt",
  33. "no": "805741929402797742",
  34. "status": "1",
  35. "status_detail": null,
  36. "list": [
  37. {
  38. "datetime": "2019-05-07 18:02:27",
  39. "remark": "山东省淄博市淄川区三部公司取件人:司健(15553333300)已收件",
  40. "zone": ""
  41. },
  42. {
  43. "datetime": "2019-05-09 12:44:40",
  44. "remark": "快件已签收签收人:邮件收发章感谢使用圆通速递,期待再次为您服务",
  45. "zone": ""
  46. }
  47. ]
  48. },
  49. "error_code": 0
  50. }
  51. }

你也可以这样获取:

  1. $order['company']; // '圆通' (因为各个平台对公司的名称有所不一致,所以查询结果或许会有些许差别)
  2. $order['list']; // ....
  3. $order['original']; // 获取接口原始返回信息
  4. ...

或者这样:

  1. $order->getCode(); // 状态码
  2. $order->getMsg(); // 状态信息
  3. $order->getCompany(); // 物流公司简称
  4. $order->getNo(); // 物流单号
  5. $order->getStatus(); // 当前物流单状态
  6. // 注:物流状态可能不一定准确
  7. $order->getDisplayStatus(); // 当前物流单状态展示名
  8. $order->getAbstractStatus(); // 当前抽象物流单状态
  9. $order->getCourier(); // 快递员姓名
  10. $order->getCourierPhone(); // 快递员手机号
  11. $order->getList(); // 物流单状态详情
  12. $order->getOriginal(); // 获取接口原始返回信息

参数说明

  1. string order(string $no, string $company = null)
  • $no - 物流单号
  • $company - 快递公司名(通过 $companies = $logistics->companies(); 获取)
  • aliyun$company 可选
  • juhe : $company 必填
  • kd100 : $company 可选(建议必填,不填查询结果不一定准确)
  • kdniao : $company 可选(建议必填,不填查询结果不一定准确)

在 Laravel 中使用

生成配置文件

  1. php artisan vendor:publish --provider="Finecho\Logistics\ServiceProvider"

然后在 .env 中配置 LOGISTICS_APP_CODE ,同时修改 config/logistics.php 中配置信息:

  1. LOGISTICS_APP_CODE=xxxxxxxxxxxxxxxxx
  2. LOGISTICS_CUSTOMER=xxxxxxxxxxxxxxxxx // 快递100 customer

可以用两种方式来获取 Finecho\Logistics\Logistics; 实例:

方法参数注入

  1. .
  2. .
  3. .
  4. public function show(Logistics $logistics, $no, $company)
  5. {
  6. $order = $logistics->query($no, $company);
  7. return $order; // $order->getList(); .....
  8. }
  9. .
  10. .
  11. .

服务名访问

  1. .
  2. .
  3. .
  4. public function show($no, $company)
  5. {
  6. $response = app('logistics')->query($no, $company);
  7. }
  8. .
  9. .
  10. .

参考

感谢

  • 感谢 超哥icecho 为我第一个扩展包的悉心指导。

License

MIT