addition API BV
This commit is contained in:
@@ -1,50 +1,24 @@
|
||||
|
||||
<?php
|
||||
require_once dirname(__DIR__, 2) . '/vendor/autoload.php'; // Torna al livello di public per trovare vendor/
|
||||
require_once dirname(__FILE__) . '/class/VisualLimsApiClient.class.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// Ottieni il token da auth_proxy.php
|
||||
$auth_url = 'http://localhost/auth_proxy.php'; // Assicurati che il percorso sia corretto
|
||||
$ch = curl_init($auth_url);
|
||||
// Disabilita la visualizzazione degli errori PHP per evitare output HTML
|
||||
ini_set('display_errors', '0');
|
||||
error_reporting(E_ALL);
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disabilita verifica SSL
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Disabilita verifica host
|
||||
try {
|
||||
$api = VisualLimsApiClient::getInstance();
|
||||
$data = $api->get("Cliente"); // Recupera i clienti
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
// Salva la risposta in un file per debug
|
||||
file_put_contents(__DIR__ . '/clienti_response.json', json_encode($data));
|
||||
|
||||
if ($http_code != 200) {
|
||||
echo json_encode(['error' => 'Errore nell\'autenticazione', 'http_code' => $http_code, 'response' => $response]);
|
||||
exit;
|
||||
echo json_encode($data);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
|
||||
$token = trim($response); // Rimuove spazi o newline dal token
|
||||
|
||||
// Usa il token per richiedere la lista dei clienti
|
||||
$clienti_url = 'https://93.43.5.102/limsapi/api/odata/Cliente';
|
||||
$ch = curl_init($clienti_url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPGET, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Authorization: Bearer ' . $token,
|
||||
'Accept: application/json',
|
||||
'Host: iftm.it'
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disabilita verifica SSL
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Disabilita verifica host
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curl_error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($http_code != 200) {
|
||||
echo json_encode(['error' => 'Errore nella richiesta dei clienti', 'http_code' => $http_code, 'curl_error' => $curl_error, 'response' => $response]);
|
||||
} else {
|
||||
echo $response; // Restituisce la lista completa dei clienti in JSON
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user