PHP code example of sockball / logistics

1. Go to this page and download the library: Download sockball/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/ */

    

sockball / logistics example snippets


use sockball\logstics\Logistics;
use sockball\logistics\base\Trace;

// 圆通
$waybillNo = 'YT4234858984188';

$logistics = new Logistics();
$response = $logistics->query(Logistics::TYPE_YTO, $waybillNo);

if ($response->isSuccess())
{
    foreach ($response as $trace)
    {
        /** @var Trace $trace */
        // echo $trace->timestamp;
        // echo $trace->state;
        echo $trace->info . "\n";
    }
    // print_r($response->getLatest());
    // print_r($response->getAll());
    // print_r($response->getRaw());
}
else if ($response->isFailed())
{
    echo $response->getMsg();
}
else
{
    echo $response->getError();
}

// '暂无信息'
$response->getError();

// 直接读取最新的物流信息
$response->timestamp;
$response->info;

// 遍历物流信息 或 getAll() 后再遍历
foreach ($response as $trace)
{
    echo $trace->info;
}

// 获取原请求数据
$response->getRaw();