You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.9 KiB
75 lines
2.9 KiB
4 years ago
|
<?php
|
||
|
|
||
|
function callAPI($url){
|
||
|
$curl = curl_init($url);
|
||
|
curl_setopt($curl, CURLOPT_FAILONERROR, true);
|
||
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||
|
'x-api-key: bpEUTJEBTf74oGRWxaIcW7aeZMzDDODe1yBoSxi2',
|
||
|
'Content-Type: application/json',
|
||
|
)); // set the api key
|
||
|
curl_setopt($curl, CURLOPT_USERAGENT,'ProductionRelease/3.8.2 (app.tier.sharing; build:3.8.2.0; iOS 12.4.4) Alamofire/4.9.1'); // set user-agent to that of the Tier.app, sniffed by burpsuite
|
||
|
|
||
|
$result = curl_exec($curl);
|
||
|
//echo $result;
|
||
|
if(!$result){return 'api connection failed'.PHP_EOL;}
|
||
|
curl_close($curl);
|
||
|
return $result;
|
||
|
};
|
||
|
|
||
|
function getactiveSooters(){
|
||
|
$berlin = 'https://platform.tier-services.io/v1/vehicle?zoneId=BERLIN';
|
||
|
$getJSON = callAPI($berlin); //abstract callAPI for neater reuse
|
||
|
$saveData = file_put_contents("activescooters.json", $getJSON);
|
||
|
if (file_put_contents("activescooters.json", $getJSON))
|
||
|
echo "JSON file created successfully...";
|
||
|
else
|
||
|
echo "Oops! Error creating json file...";
|
||
|
return $saveData; //return array
|
||
|
};
|
||
|
|
||
|
function parseJSON($id){
|
||
|
$readJSON = file_get_contents('./activescooters.json'); //read latest data
|
||
|
$latestData = json_decode($readJSON, true);
|
||
|
$scooter = $latestData["data"][$id];
|
||
|
$scooter_UUID = $scooter["id"];
|
||
|
return $scooter_UUID;
|
||
|
};
|
||
|
|
||
|
function append_UUID(){
|
||
|
$filename = "./scooter_UUID.json";
|
||
|
$scooterUUID_JSON = file_get_contents($filename);
|
||
|
$scooterUUID_Array = json_decode($scooterUUID_JSON,true);
|
||
|
//print_r($scooterUUID_Array);
|
||
|
$activescooterJSON = file_get_contents('./activescooters.json'); //read latest data
|
||
|
$activescooterArray = json_decode($activescooterJSON, true);
|
||
|
//print_r($activescooterArray);
|
||
|
$scooters = $activescooterArray["data"];
|
||
|
//print_r($scooters);
|
||
|
$id = 0; //start id
|
||
|
//$api_call = "https://platform.tier-services.io/v1/vehicle/";
|
||
|
foreach ($scooters as $item) {
|
||
|
$UUID = parseJSON($id);
|
||
|
$UUID_Entry = array('UUID' => $UUID);
|
||
|
if (in_array($UUID_Entry, $scooterUUID_Array)) {
|
||
|
echo "matched".PHP_EOL;
|
||
|
} else {
|
||
|
$additionalUUID = array('UUID' => $UUID);
|
||
|
$scooterUUID_Array[] = $additionalUUID ;
|
||
|
$jsonData = json_encode($scooterUUID_Array);
|
||
|
file_put_contents('./scooter_UUID.json', $jsonData);
|
||
|
echo "new Entry added".PHP_EOL;
|
||
|
}
|
||
|
//$json_entry = "{" . "\"URL\":" . "\"" . $api_call . $UUID . "\"" . "},";
|
||
|
//file_put_contents($filename, $json_entry, FILE_APPEND | LOCK_EX);
|
||
|
$id++;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
getactiveSooters();
|
||
|
append_UUID();
|
||
|
|
||
|
?>
|