29 lines
781 B
PHP
29 lines
781 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
header('Content-Type: application/json');
|
|
|
|
// Mets ta clé directement ici pour tester
|
|
$API_KEY = 'cee5df47-3c1a-4885-a5df-473c1aa885e2';
|
|
|
|
$siret = preg_replace('/\D/', '', $_GET['siret'] ?? '');
|
|
if (strlen($siret) !== 14) {
|
|
echo json_encode(['exists' => false, 'http' => 0, 'why' => 'bad_length']);
|
|
exit;
|
|
}
|
|
|
|
$url = "https://api.insee.fr/api-sirene/3.11/siret/$siret";
|
|
|
|
$ch = curl_init($url);
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_HTTPHEADER => ["X-INSEE-Api-Key-Integration: $API_KEY", "Accept: application/json"],
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TIMEOUT => 10,
|
|
]);
|
|
curl_exec($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
echo json_encode(['exists' => ($code === 200), 'http' => $code]);
|
|
|
|
|