slince / shipment-tracking
一个灵活且出色的多承运商物流跟踪库,包括DHL eCommerce、USPS、燕文快递、Epacket、E包裹、E特快、国际EMS、快递100等
2.2.4
2017-11-20 02:40 UTC
Requires
- php: >=5.6.0
- nesbot/carbon: ^1.0
- rinvex/country: ^2.0|^3.0
- slince/shipment-tracking-foundation: ^1.1
Requires (Dev)
- phpunit/phpunit: ^5.0|^6.0
This package is auto-updated.
Last update: 2024-09-08 18:19:18 UTC
README
一个灵活且出色的多承运商物流跟踪库,包括DHL eCommerce、燕文快递、Epacket、E包裹、E特快、国际EMS、快递100等
安装
通过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\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()); }
中国邮政
适用于中邮旗下的E邮宝(Epacket、EUP)、E包裹、E特快、国际EMS产品
$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()); }
注意:该库不支持查询国内EMS包裹信息,相关文档主页http://shipping.ems.com.cn/apiIndex
快递100
$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()); }
快递100的key需要自行申请,免费版的key在查询申通顺丰之类的单号时会受限,需要企业版才可以;附上快递100文档
USPS
$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()); }
您可以在以下url上获取您的用户id。
https://www.usps.com/business/web-tools-apis/welcome.htm
递四方
$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()); }
APPKEY和APPSECRET 需要到递四方官网注册APP,审核之后即可获取到该参数;
许可证
MIT许可证。见 MIT