data.netsyms.net/endpoints/logistics.tracking.php

34 lines
875 B
PHP
Raw Normal View History

2021-05-21 18:50:46 -06:00
<?php
$trackinginfo;
2021-05-21 19:11:40 -06:00
$code = $VARS["code"];
$carrier = "";
if (!empty($VARS["carrier"])) {
$carrier = $VARS["carrier"];
}
2021-05-21 18:50:46 -06:00
try {
2021-05-21 19:11:40 -06:00
$cacheresp = $memcache->get("logistics.tracking.$code.$carrier");
if ($cacheresp !== false && empty($VARS["nocache"])) {
exitWithJson(json_decode($cacheresp, true));
2021-05-21 18:50:46 -06:00
}
2021-05-21 19:11:40 -06:00
$trackinginfo = Tracking::track($code, $carrier);
2021-05-21 18:50:46 -06:00
} catch (TrackingException $ex) {
2021-05-21 19:11:40 -06:00
$output = [
"status" => "ERROR",
"msg" => $ex->getMessage()
];
$memcache->set("logistics.tracking.$code.$carrier", json_encode($output), 60 * 10);
exitWithJson($output);
2021-05-21 18:50:46 -06:00
}
if (is_null($trackinginfo)) {
sendJsonResp("Could not find any results for that tracking code.", "ERROR");
}
2021-05-21 19:11:40 -06:00
$output = $trackinginfo->toObject();
$memcache->set("logistics.tracking.$code.$carrier", json_encode($output), 60 * 60);
exitWithJson($output);