-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobile-api.php
More file actions
68 lines (56 loc) · 2.02 KB
/
mobile-api.php
File metadata and controls
68 lines (56 loc) · 2.02 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
58
59
60
61
62
63
64
65
66
67
<?php
require_once 'config.php';
session_start();
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit;
}
error_log("=== Mobile API Request ===");
error_log("Method: " . $_SERVER['REQUEST_METHOD']);
error_log("GET params: " . print_r($_GET, true));
error_log("Session ID: " . session_id());
error_log("Session data: " . print_r($_SESSION, true));
if (isset($_GET['check_token']) && isset($_GET['mobile_id'])) {
$mobile_id = $_GET['mobile_id'];
$temp_file = sys_get_temp_dir() . '/supaco_mobile_' . $mobile_id . '.json';
error_log("Verificando token para mobile_id: " . $mobile_id);
error_log("Arquivo: " . $temp_file);
if (file_exists($temp_file)) {
$file_age = time() - filemtime($temp_file);
if ($file_age > 300) {
error_log("Arquivo expirado (idade: " . $file_age . "s)");
unlink($temp_file);
http_response_code(410);
echo json_encode([
'success' => false,
'error' => 'token_expired',
'message' => 'Token expirou. Faça login novamente.'
]);
exit;
}
$data = json_decode(file_get_contents($temp_file), true);
error_log("Token encontrado - retornando para mobile");
unlink($temp_file);
echo json_encode($data);
exit;
} else {
error_log("Arquivo não encontrado - ainda aguardando");
http_response_code(404);
echo json_encode([
'success' => false,
'error' => 'token_not_found',
'message' => 'Aguardando autenticação'
]);
exit;
}
}
http_response_code(400);
echo json_encode([
'success' => false,
'error' => 'invalid_request',
'message' => 'Parâmetro inválido'
]);