-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.php
More file actions
57 lines (44 loc) · 1.78 KB
/
data.php
File metadata and controls
57 lines (44 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
require_once 'config.php';
if(defined('SHOW_ERR') && SHOW_ERR) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
$api_url = (ENV == 'production' ? 'http://localhost:5000/Traccar/Get_Token_InfoAsync' : 'https://gps.bataviarent.com/prime/iot/v1/api/Traccar/Get_Token_InfoAsync');
$api_key = 'fmUSLneh99jhTEd27ptO1Lx5nARtx4wIcvSdahSi';
$api_secret = 'AMfSKPBosWYddEyWYtZiWirBeFTbggfL8xY05Rcm';
if(isset($_POST['token'])) {
$lang = 'en';
$token = $_POST['token'];
$arr_params = array(
'lang' => 'en',
'token' => $token
);
$json_params = json_encode($arr_params);
$curl = curl_init($api_url);
curl_setopt_array($curl, array(
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $json_params,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Content-Length: '.strlen($json_params),
'api_key: '.$api_key,
'api_secret: '.$api_secret
)
));
$response = curl_exec($curl);
$err = curl_error($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if($http_code == '401') $json = array('result' => false, 'msg' => 'Unauthorized');
if($err) $json = array('resut' => false, 'msg' => 'Unknown Error Occured');
else $json = json_decode($response, TRUE);
header('Content-Type: application/json');
echo json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} else {
$json = array('success' => false, 'message' => 'No token found');
header('Content-Type: application/json');
echo json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}