slince/shipment-tracking-dhl-ecommerce

适用于DHL电子商务的灵活的货运跟踪库。

1.0.0 2017-07-28 01:37 UTC

This package is not auto-updated.

Last update: 2024-09-21 00:34:31 UTC


README

Build Status Coverage Status Latest Stable Version Scrutinizer

适用于DHL电子商务和DHL电子商务(注册)的灵活的货运跟踪库

安装

通过composer安装

$ composer require slince/shipment-tracking-dhl-ecommerce

基本用法

$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\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\Exception\TrackException $exception) {
    exit('Track error: ' . $exception->getMessage());
}

许可证

MIT许可证。查看 MIT