A flexible and shipment tracking library for multi carriers.
$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());
}
All shipment trackers must implement Slince\ShipmentTracking\Foundation\TrackerInterface
, and will usually extend Slince\ShipmentTracking\Foundation\HttpAwareTracker
for basic functionality if the carrier's api is based on
HTTP
namespace My\Tracker;
use Slince\ShipmentTracking\Foundation\HttpAwareTracker;
use Slince\ShipmentTracking\Foundation\Shipment;
class MyTracker extends HttpAwareTracker
{
/**
* {@inheritdoc}
*/
public function track($trackingNumber)
{
$response = $this->getHttpClient()->get('/../endpoint', [
'query' => [
'tracking_number' => $trackingNumber
]
]);
return static::buildShipment($response):
}
/**
* @return Shipment
*/
public function buildShipment($response)
{
//....
}
}
$tracker = new MyTracker();
$shipment = $tracker->track('foo-tracking-number');
print_r($shipment):
You can extend all existing classes if you need.
The following carriers are available:
Tracker | Composer Package | Maintainer |
---|---|---|
DHL eCommerce | slince/shipment-tracking | Tao |
Yanwen Exprerss(燕文物流) | slince/shipment-tracking | Tao |
快递100 | slince/shipment-tracking | Tao |
E邮宝/E包裹/E特快/国际EMS | slince/shipment-tracking | Tao |
The MIT license. See MIT