Git Product home page Git Product logo

logistics's Introduction

❤️ Logistics

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

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

介绍

目前已支持四家平台

安装

$ composer require finecho/logistics -vvv	

使用

require __DIR__ .'/vendor/autoload.php';

use Finecho\Logistics\Logistics;

$config = [
    'provider' => 'aliyun', // aliyun/juhe/kd100
    
    'aliyun' => [
        'app_code' => 'xxxxxxxx',
    ],
    
    'juhe' => [
         'app_code' => 'xxxxx',
    ],
    
    'kdniao' => [
             'app_code' => 'xxxxx',
             'customer' => 'xxxxx',
    ],
        
    'kd100' => [
         'app_code' => 'xxxxx',
         'customer' => 'xxxxx',
    ],
];

$logistics = new Logistics($config);

获取物流公司列表

$companies = $logistics->companies();	

示例:

[
    "顺丰",
    "申通",
    "中通",
    "圆通"
]

获取物流信息

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

示例:

{
    "code": 200,
    "msg": "OK",
    "company": "圆通",
    "no": "805741929402797742",
    "status": 4,
    "display_status": "已签收",
    "abstract_status": {
        "has_active" : true,
        "has_ended" : true,
        "has_signed" : true,
        "has_troubled" : false,
        "has_returned" : false
    },
    "list": [
        {
            "datetime": "2019-05-07 18:02:27",
            "remark": "山东省淄博市淄川区三部公司取件人:司健(15553333300)已收件",
            "zone": ""
        },
        {
            "datetime": "2019-05-09 12:44:40",
            "remark": "快件已签收签收人:邮件收发章感谢使用圆通速递,期待再次为您服务",
            "zone": ""
        }
    ],
    "original": {
        "resultcode": "200",
        "reason": "成功的返回",
        "result": {
            "company": "圆通",
            "com": "yt",
            "no": "805741929402797742",
            "status": "1",
            "status_detail": null,
            "list": [
                {
                    "datetime": "2019-05-07 18:02:27",
                    "remark": "山东省淄博市淄川区三部公司取件人:司健(15553333300)已收件",
                    "zone": ""
                },
                {
                    "datetime": "2019-05-09 12:44:40",
                    "remark": "快件已签收签收人:邮件收发章感谢使用圆通速递,期待再次为您服务",
                    "zone": ""
                }
            ]
        },
        "error_code": 0
    }
}

你也可以这样获取:

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

或者这样:

$order->getCode(); // 状态码
$order->getMsg(); // 状态信息
$order->getCompany(); // 物流公司简称
$order->getNo(); // 物流单号
$order->getStatus(); // 当前物流单状态 

// 注:物流状态可能不一定准确

$order->getDisplayStatus(); // 当前物流单状态展示名
$order->getAbstractStatus(); // 当前抽象物流单状态
$order->getCourier(); // 快递员姓名
$order->getCourierPhone(); // 快递员手机号
$order->getList(); // 物流单状态详情
$order->getOriginal(); // 获取接口原始返回信息

参数说明

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

在 Laravel 中使用

生成配置文件

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

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

LOGISTICS_APP_CODE=xxxxxxxxxxxxxxxxx	
LOGISTICS_CUSTOMER=xxxxxxxxxxxxxxxxx	// 快递100 customer

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

方法参数注入

    .	
    .	
    .	
    public function show(Logistics $logistics, $no, $company) 	
    {	
        $order = $logistics->query($no, $company);
        
        return $order;	// $order->getList(); .....
    }	
    .	
    .	
    .	

服务名访问

    .	
    .	
    .	
    public function show($no, $company) 	
    {	
        $response = app('logistics')->query($no, $company);	
    }	
    .	
    .	
    .

参考

感谢

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

License

MIT

logistics's People

Contributors

aliliin avatar assert6 avatar guanguans avatar lw006 avatar overtrue avatar thisliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

logistics's Issues

PHP8 兼容

报错信息:
NOTICE: PHP message: PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Finecho\Logistics\Order::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/php-app/vendor/finecho/logistics/src/Traits/HasAttributes.php:79

希望能兼容下PHP8,最简单就是直接加下#[\ReturnTypeWillChange] 然后发布个新版本

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.