royal mail tracking api
1.0.2
为了能够通过Royal Mail API跟踪项目,您需要成为皇家邮件帐户持有人,并通过https://developer.royalmail.net/批准通过Royal Mail开发人员Portal访问跟踪API
composer require nomisoft/royal-mail-tracking-api
您需要您希望检索的项目的跟踪参考编号以及客户ID,客户秘密和应用ID(全部可从Royal Mail开发人员Portal中获得)
use Nomisoft RoyalMailTrackingApi RoyalMail ;
use Nomisoft RoyalMailTrackingApi RoyalMailException ;
$ rm = RoyalMail :: init ( ' CLIENT_ID ' , ' CLIENT_SECRET ' , ' APP_ID ' );
try {
$ response = $ rm -> getSingleItemSummary ( ' XX12345678XX ' );
} catch ( SoapFault $ e ) {
echo $ e -> getMessage ();
} catch ( RoyalMailException $ e ) {
echo $ e -> getMessage () . ' - ' . $ e -> getCause ();
}
返回的响应是一个包含DateTime对象的数组,状态和摘要文本
Array
(
[datetime] => DateTime Object
(
[date] => 2016 - 06 - 01 12 : 30 : 00
[timezone_type] => 3
[timezone] => Europe / London
)
[status] => Delivered
[summary] => Item XX12345678XX was collected and signed for by the addressee on the 2016 - 06 - 01 from Kidderminster DO .
)
use Nomisoft RoyalMailTrackingApi RoyalMail ;
$ rm = RoyalMail :: init ( ' CLIENT_ID ' , ' CLIENT_SECRET ' , ' APP_ID ' );
$ response = $ rm -> getSingleItemHistory ( ' XX12345678XX ' );
返回的响应是多维阵列。每个交货状态更新都包含DateTime对象,位置和状态
Array
(
[ 0 ] => Array
(
[datetime] => DateTime Object
(
[date] => 2016 - 06 - 01 12 : 30 : 00
[timezone_type] => 3
[timezone] => Europe / London
)
[location] => Kidderminster DO
[status] => Delivered
)
[ 1 ] => Array
(
[datetime] => DateTime Object
(
[date] => 2016 - 05 - 31 15 : 30 : 00
[timezone_type] => 3
[timezone] => Europe / London
)
[location] => Kidderminster DO
[status] => We have your item
)
[ 2 ] => Array
(
[datetime] => DateTime Object
(
[date] => 2016 - 05 - 31 12 : 30 : 00
[timezone_type] => 3
[timezone] => Europe / London
)
[location] => Kidderminster DO
[status] => Delivery attempted
)
[ 3 ] => Array
(
[datetime] => DateTime Object
(
[date] => 2016 - 05 - 28 10 : 00 : 00
[timezone_type] => 3
[timezone] => Europe / London
)
[location] => Medway Mail Centre
[status] => It 's on its way.
)
)
use Nomisoft RoyalMailTrackingApi RoyalMail ;
$ rm = RoyalMail :: init ( ' CLIENT_ID ' , ' CLIENT_SECRET ' , ' APP_ID ' );
$ response = $ rm -> getMultiItemSummary ( array ( ' XX12345678XX ' , ' ZZ12345678ZZ ' ));
返回的响应是一个多维数组,其跟踪参考号作为键。每个项目都包含DateTime对象,状态和摘要
Array
(
[ XX12345678XX ] => Array
(
[datetime] => DateTime Object
(
[date] => 2016 - 06 - 01 12 : 30 : 00
[timezone_type] => 3
[timezone] => Europe / London
)
[status] => Delivered
[summary] => Item XX12345678XX was collected and signed for by the addressee on the 2016 - 06 - 01 from Kidderminster DO .
)
[ ZZ12345678ZZ ] => Array
(
[datetime] => DateTime Object
(
[date] => 2016 - 06 - 01 12 : 30 : 00
[timezone_type] => 3
[timezone] => Europe / London
)
[status] => Delivered
[summary] => We have a record of item ZZ12345678ZZ as being delivered from Fort William DO on 2016 - 06 - 01.
)
)
use Nomisoft RoyalMailTrackingApi RoyalMail ;
$ rm = RoyalMail :: init ( ' CLIENT_ID ' , ' CLIENT_SECRET ' , ' APP_ID ' );
$ response = $ rm -> getProofOfDelivery ( ' XX12345678XX ' );
返回的响应是一个包含DateTime对象的数组和签名包裹的人的名称
Array
(
[datetime] => DateTime Object
(
[date] => 2016 - 06 - 01 12 : 30 : 00
[timezone_type] => 3
[timezone] => Europe / London
)
[name] => Smith
)
如果从API收到错误响应,则会引发RoyalMailMailException例外。调用getMessage()函数将返回皇家邮件的错误描述。还有一个额外的getCause()函数,它将返回API返回的“原因”字段的值
try {
$ response = $ rm -> getSingleItemSummary ( ' XX12345678XX ' );
} catch ( RoyalMailException $ e ) {
echo $ e -> getMessage ();
echo $ e -> getCause ();
}
如果该物品在30天前交付
Tracking data are not available for barcode reference XX12345678XX
It is not possible to provide information about events that occurred more than 30 days ago