PHP code example of slince / shipment-tracking

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

    

slince / shipment-tracking example snippets



$tracker = new Slince\ShipmentTracking\DHLECommerce\DHLECommerceTracker(CLIENT_ID, PASSWORD);

try {
   $shipment = $tracker->track('CNAQV100168101');
   
   if ($shipment->isDelivered()) {
       echo "Delivered";
   }
   echo $shipment->getOrigin();
   echo $shipment->getDestination();
   print_r($shipment->getEvents());  //print the shipment events
   
} catch (Slince\ShipmentTracking\Foundation\Exception\TrackException $exception) {
    exit('Track error: ' . $exception->getMessage());
}


$shipment = $tacker->track('CNAQV100168101);
$accessToken = $tracker->getAccessToken(); //You can save this for the next query

//... to do

try{
    $tracker->setAccessToken($accessToken); //Set the access token; the tracker will not send requst for the access token
    $shipment = $tacker->track('CNAQV100168101);
} catch (Slince\ShipmentTracking\DHLECommerce\Exception\InvalidAccessTokenException $exception) {
     $accessToken = $tracker->getAccessToken(true); // If the access token is invalid, refresh it.
     $shipment = $tacker->track('CNAQV100168101);
     //... to do
} catch (Slince\ShipmentTracking\Foundation\Exception\TrackException $exception) {
    exit('Track error: ' . $exception->getMessage());
}


$tracker = new Slince\ShipmentTracking\YanWenExpress\YanWenTracker(KEY, 'en');

try {
   $shipment = $tracker->track('CNAQV100168101');
   
   if ($shipment->isDelivered()) {
       echo "Delivered";
   }
   echo $shipment->getOrigin();
   echo $shipment->getDestination();
   print_r($shipment->getEvents());  //print the shipment events
   
} catch (Slince\ShipmentTracking\Foundation\Exception\TrackException $exception) {
    exit('Track error: ' . $exception->getMessage());
}



$tracker = new Slince\ShipmentTracking\EMS\EMSTracker(AUTHENTICATE, 'en');

try {
   $shipment = $tracker->track('CNAQV100168101');
   
   print_r($shipment->getEvents());  //print the shipment events
   
} catch (Slince\ShipmentTracking\Foundation\Exception\TrackException $exception) {
    exit('Track error: ' . $exception->getMessage());
}



$tracker = new Slince\ShipmentTracking\KuaiDi100\KuaiDi100Tracker(APPKEY, 'shunfeng'); //承运商名称并不是标准的承运商代码,实际承运商代码请到kuaidi100.com查看

try {
   $shipment = $tracker->track('CNAQV100168101');
   
   if ($shipment->isDelivered()) {
       echo "Delivered";
   }
   print_r($shipment->getEvents());  //print the shipment events
   
} catch (Slince\ShipmentTracking\Foundation\Exception\TrackException $exception) {
    exit('Track error: ' . $exception->getMessage());
}



$tracker = new Slince\ShipmentTracking\USPS\USPSTracker(USER_ID);

try {
   $shipment = $tracker->track('CNAQV100168101');
   
   if ($shipment->isDelivered()) {
       echo "Delivered";
   }
   print_r($shipment->getEvents());  //print the shipment events
   
} catch (Slince\ShipmentTracking\Foundation\Exception\TrackException $exception) {
    exit('Track error: ' . $exception->getMessage());
}



$tracker = new Slince\ShipmentTracking\FourPartyExpress\FourPartyExpressTracker(APPKEY, APPSECRET);

try {
   $shipment = $tracker->track('CNAQV100168101');
   
   print_r($shipment->getEvents());  //print the shipment events
   
} catch (Slince\ShipmentTracking\Foundation\Exception\TrackException $exception) {
    exit('Track error: ' . $exception->getMessage());
}