api to temp logic
This commit is contained in:
parent
d99e9c4c29
commit
c3ecf1f774
61
public/userarea/apilogic/api-to-temp.php
Normal file
61
public/userarea/apilogic/api-to-temp.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// Connessione al database
|
||||
include('../../Connections/repnew.php');
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
// Verifica la connessione
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Controlla se il JSON è stato ricevuto tramite POST
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Riceve il JSON dal laboratorio
|
||||
$json_data = file_get_contents('php://input');
|
||||
|
||||
// Decodifica il JSON per la validazione (facoltativa)
|
||||
$decoded_data = json_decode($json_data, true);
|
||||
|
||||
// Se il JSON è valido
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
// Genera un UUID per identificare univocamente il record
|
||||
$uuid = uniqid(); // Alternativamente puoi usare UUID() in MySQL
|
||||
|
||||
// ID del laboratorio dal quale proviene il JSON (puoi aggiungere autenticazione)
|
||||
$lab_id = isset($_POST['lab_id']) ? $_POST['lab_id'] : 'Unknown Lab'; // Modifica a seconda della tua logica
|
||||
|
||||
// Query per inserire i dati nella tabella temp_json_queue
|
||||
$stmt = $conn->prepare("INSERT INTO temp_json_queue (uuid, lab_id, json_data) VALUES (?, ?, ?)");
|
||||
$stmt->bind_param("sss", $uuid, $lab_id, $json_data);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode([
|
||||
"status" => "success",
|
||||
"message" => "Data successfully saved.",
|
||||
"uuid" => $uuid
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
"status" => "error",
|
||||
"message" => "Failed to save data."
|
||||
]);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
} else {
|
||||
// Se il JSON è invalido
|
||||
echo json_encode([
|
||||
"status" => "error",
|
||||
"message" => "Invalid JSON format."
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
echo json_encode([
|
||||
"status" => "error",
|
||||
"message" => "Invalid request method."
|
||||
]);
|
||||
}
|
||||
|
||||
// Chiude la connessione al database
|
||||
$conn->close();
|
||||
Loading…
x
Reference in New Issue
Block a user