PHP code example of track123 / open-api

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

    

track123 / open-api example snippets


use Track123\OpenApi\Config;

$config = new Config('your-access-token'); // 替换为你的 token


use Track123\OpenApi\System\Request\OceanCargo\RegisterOceanCargoTrackingRequest;

$request = new RegisterOceanCargoTrackingRequest();
//单个添加
$request->addTracking('T001', 'CMA', 1)
        ->addTracking('T002', 'COSCO', 2);
$response = Track123::system($config)->registerOceanTrackings($request);
print_r($response -> getAcceptedData());
if($response -> hasRejectedData()){
    echo $response->getRejectedMessages();
}

use Track123\OpenApi\System\Request\OceanCargo\GetOceanCargoTrackingsRequest;
use Track123\OpenApi\Track123;

$request = new GetOceanCargoTrackingsRequest();
$request->setTracking('order123', 'ONEYSZPF55508400', 2); // bill of lading
//或批量添加 
//$request->setTrackings($trackings);

$response = Track123::system($config)->getOceanCargoTrackings($request);

print_r($response->getAcceptedData());

if ($response->hasRejectedData()) {
    echo $response->getRejectedMessages();
}