diff --git a/README.md b/README.md index c417f32..835aebc 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ $data = parcel_track() ups() - United Parcel Service Courier/td> + United Parcel Service Courier setTrackingNumber($refNumber) diff --git a/changelog.md b/changelog.md index 12c1d24..5cac25d 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## 1.2 +- FIx LEL Express changing their URL +- Fix Skynet Because of Changing of the UI + ## 1.11 Add New Courier UPS Express - add United Parcel Service (M) Sdn Bhd (Main) diff --git a/example/index.php b/example/index.php index 940aad9..c6d402d 100644 --- a/example/index.php +++ b/example/index.php @@ -9,7 +9,7 @@ require_once __DIR__ .'/../vendor/autoload.php'; //$response = parcel_track()->gdExpress()->setTrackingNumber("4941410530")->fetch(); -//$response = parcel_track()->skynet()->setTrackingNumber("238216506684")->fetch(); +$response = parcel_track()->skynet()->setTrackingNumber("238216506684")->fetch(); //$response = parcel_track()->abxExpress()->setTrackingNumber("EZP843055940197")->fetch(); //$response = parcel_track()->dhlExpress()->setTrackingNumber("5176011131")->fetch(); //$response = parcel_track()->cityLink()->setTrackingNumber("960307804711915")->fetch(); @@ -20,7 +20,7 @@ //$response = parcel_track()->lelExpress()->setTrackingNumber("MYMP000000573505")->fetch(); //$response = parcel_track()->dhlECommerce()->setTrackingNumber("5218031053514008AAAA")->fetch(); //$response = parcel_track()->ktmd()->setTrackingNumber("103154269")->fetch(); -$response = parcel_track()->ups()->setTrackingNumber("1Z0V255F0498628539")->fetch(); +//$response = parcel_track()->ups()->setTrackingNumber("1Z0V255F0498628539")->fetch(); //$response = parcel_track()->setTrackingNumber("EZP843055940197")->checkCourier(); diff --git a/src/Tracker/LELExpress.php b/src/Tracker/LELExpress.php index e3f3d25..2c2f2ac 100644 --- a/src/Tracker/LELExpress.php +++ b/src/Tracker/LELExpress.php @@ -13,7 +13,7 @@ class LELExpress extends BaseTracker { - protected $url = "http://www.lex.com.my/tracker/"; + protected $url = "https://tracker.lel.asia/"; protected $source = "Lazada E-Logistic Express"; protected $code = "lex"; diff --git a/src/Tracker/SkyNet.php b/src/Tracker/SkyNet.php index 9b00652..6d9234e 100644 --- a/src/Tracker/SkyNet.php +++ b/src/Tracker/SkyNet.php @@ -30,39 +30,94 @@ public function startCrawl($result) { if (isset($result['body'])) { $crawler = new Crawler($result['body']); + $crawlerResult = $crawler->filter('#tr2' . $this->getTrackingNumber()) + ->filter('table tr')->each(function (Crawler $node, $i) { + $result = $node->filter('td')->each(function (Crawler $node, $i) { + return trim_spaces($node->text()); + }); + + return $this->removeAllNullInArray($result, true); + }); + + $currentDate = null; + $dataLast = []; + if (isset($crawlerResult[0][0]) && Carbon::hasFormat($crawlerResult[0][0], 'd M Y')) { + $currentDate = $crawlerResult[0][0].' '.$crawlerResult[1][1]; + $parcel = Carbon::createFromFormat("d M Y g:i A", $currentDate); + $dataLast[] = [ + 'date' => $parcel->toDateTimeString(), + 'timestamp' => $parcel->timestamp, + 'process' => $crawlerResult[1][0], + 'type' => $this->distinguishProcess($crawlerResult[1][0]), + 'event' => ucwords(strtolower($crawlerResult[1][2])), + ]; + } else { + return $this->buildResponse($result, $dataLast); + } + $crawlerResult = $crawler->filter('#tr4' . $this->getTrackingNumber()) ->filter('table tr')->each(function (Crawler $node, $i) { $result = $node->filter('td')->each(function (Crawler $node, $i) { return trim_spaces($node->text()); }); - $data = []; - foreach ($result as $key => $item) { - if ($key == 0) { - $data['date'] = $item; - } - if ($key == 1) { - $data['process'] = $item; - $data['type'] = $this->distinguishProcess($item); - } - if ($key == 2) { - $parcel = Carbon::createFromFormat("d M Y h:i a", $data['date'] . " " . $item); - $data['date'] = $parcel->toDateTimeString(); - $data['timestamp'] = $parcel->timestamp; + $result = $this->removeAllNullInArray($result, true); + if ($result) { + if (isset($result[1])) { + unset($result[1]); + $result = array_values($result); + } + if (Carbon::hasFormat($result[0], 'd M Y')) { + return $result; } - if ($key == 3) { - $data['event'] = $item; + if (Carbon::hasFormat($result[0], 'g:i A')) { + return $result; } } - return $data; + return null; }); - return $this->buildResponse($result, $crawlerResult); + $data = $this->removeAllNullInArray($crawlerResult); + $currentDate = null; + foreach ($data as $item) { + if (isset($item[0]) && Carbon::hasFormat($item[0], 'd M Y')){ + $currentDate = $item[0]; + } + + if (count($item) > 1) { + $parcel = Carbon::createFromFormat("d M Y g:i A", $currentDate . " " . $item[0]); + $dataLast[] = [ + 'date' => $parcel->toDateTimeString(), + 'timestamp' => $parcel->timestamp, + 'process' => $item[1], + 'type' => $this->distinguishProcess($item[1]), + 'event' => ucwords(strtolower($item[2])), + ]; + } + } + + return $this->buildResponse($result, $dataLast); } return $this->buildResponse($result, []); + } + + private function removeAllNullInArray($array, $removeDuplicate = false) + { + $newData = []; + $array = array_values(array_filter($array)); + foreach ($array as $item) { + if ($item != null) { + $newData[] = $item; + } + } + + if ($removeDuplicate) { + $newData = array_unique($array, SORT_REGULAR); + } + return $newData; } } \ No newline at end of file