Files
GEOVizor_PHP/android/accept.php
2023-11-07 19:51:49 +06:00

53 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
//Принять накопившиеся GPS данные с телефона и сохранить в виде файлов во временное хранилище
//Отвечаю только на POST запросы
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
sendError("Request is GET method!");
}
if(!isset($HTTP_RAW_POST_DATA))
{ $HTTP_RAW_POST_DATA = file_get_contents("php://input");
}
$object = json_decode($HTTP_RAW_POST_DATA);
if ($object == null) {
sendError("Request is empty!");
}
$fn = filter_input(INPUT_GET, 'fn', FILTER_VALIDATE_INT, array('options' => array('default' => -1)));
if (isset($_GET['lng'])) $_SESSION["LNG"] = $_GET['lng']; else $_SESSION["LNG"] = 2;//'en';
$result=false;
if ($fn == 1) {
//Данные GPS
$file = fopen('./data/'.time().'_'.$object->imei.'_1.json','w');
fwrite($file, $HTTP_RAW_POST_DATA);
fclose($file);
$result=true;
}elseif ($fn == 2){
//Данные датчиков
$file = fopen('./data/'.time().'_'.$object->imei.'_2.json','w');
fwrite($file, $HTTP_RAW_POST_DATA);
fclose($file);
$result=true;
}
if($result){
$obj = new StdClass();
$obj->errorCode = 0;
$obj->errorMessage = '';
$obj->data = array();
header('Content-Type: application/json');
header("Cache-Control: no-cache, must-revalidate");
echo json_encode($obj);
}else{
$obj = new StdClass();
$obj->errorCode = 1;
$obj->errorMessage = '';
$obj->data = array();
header('Content-Type: application/json');
header("Cache-Control: no-cache, must-revalidate");
echo json_encode($obj);
}