1
1
<?php
2
+ //include config
3
+ include_once ("config.php " );
2
4
// set headers
3
5
header ('Content-Type: text/event-stream ' );
4
6
header ('Cache-Control: no-cache ' );
5
7
header ('Connection: keep-alive ' );
6
8
7
9
//get the session cookie
8
- $ session = json_encode (get_TraccarSession ("http://127.0.0.1:8082/api/session?token=hdbtrsy6576hyw84567cSiOuqqhA " ));
10
+ $ session = json_encode (get_TraccarSession ("http://127.0.0.1:8082/api/session?token= $ TraccarAPIToken " ));
9
11
10
12
$ api_result = json_decode ($ session , true );
11
13
$ JSESSIONID = $ api_result ['JSESSIONID ' ];
12
14
13
15
//get the Traccar positions
14
- $ positions = get_TraccarPosition ("http://127.0.0.1:8082/api/positions?token=hdbtrsy6576hyw84567cSiOuqqhA " ,$ JSESSIONID );
16
+ $ positions = get_TraccarPosition ("http://127.0.0.1:8082/api/positions?token= $ TraccarAPIToken " ,$ JSESSIONID );
15
17
16
18
$ json = json_decode ($ positions );
17
19
@@ -76,20 +78,13 @@ function get_TraccarPosition($url,$JSESSIONID) {
76
78
)
77
79
);
78
80
79
- $ context = stream_context_create ($ opts );
80
-
81
81
// Open the file using the HTTP headers set above
82
- $ file = file_get_contents ($ url , false , $ context );
82
+ $ file = file_get_contents ($ url , false , stream_context_create ( $ opts ) );
83
83
return $ file ;
84
84
}
85
85
86
- function get_FTSAPI ($ id , $ latitude , $ longitude ) {
86
+ function get_FTSAPI ($ id , $ latitude , $ longitude, $ FreeTakServerAPIToken ) {
87
87
88
- //http://127.0.0.1:19023/ManagePresence/putPresence
89
- //http://127.0.0.1:19023/ManagePresence/postPresence
90
- $ url = "http://127.0.0.1:19023/ManagePresence/postPresence " ;
91
- //FTS Bearer token
92
- $ token = "Bearer token " ;
93
88
//generate GUID
94
89
$ guid = vsprintf ('%s%s-%s-4000-8%.3s-%s%s%s0 ' ,str_split (dechex ( microtime (true ) * 1000 ) . bin2hex ( random_bytes (8 ) ),4 ));
95
90
@@ -104,22 +99,19 @@ function get_FTSAPI($id, $latitude, $longitude) {
104
99
"team " => "Red "
105
100
);
106
101
107
- // for sending data as json type
108
- $ fields = json_encode ($ postData );
109
-
110
- $ ch = curl_init ($ url );
102
+ $ ch = curl_init ("http://127.0.0.1:19023/ManagePresence/postPresence " );
111
103
//set cURL options
112
104
curl_setopt (
113
105
$ ch ,
114
106
CURLOPT_HTTPHEADER ,
115
107
array (
116
108
'Content-Type: application/json ' ,
117
- 'Authorization: ' .$ token
109
+ 'Authorization: ' .$ FreeTakServerAPIToken
118
110
)
119
111
);
120
112
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
121
113
curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , 2 );
122
- curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ fields );
114
+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , json_encode ( $ postData ) );
123
115
//execute cURL call
124
116
$ result = curl_exec ($ ch );
125
117
curl_close ($ ch );
0 commit comments