<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

echo "=== TESTE API FAZENDA RJ ===\n\n";

$renavam = "01005706384";
$url = "https://darj-ipva-api.fazenda.rj.gov.br/darj-ipva-api/api/publico/darj/dados-veiculo/{$renavam}";

echo "URL: $url\n\n";

$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
    CURLOPT_HTTPHEADER => [
        'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
        'Accept: application/json',
        'Origin: https://darj-ipva-web.fazenda.rj.gov.br',
        'Referer: https://darj-ipva-web.fazenda.rj.gov.br/',
    ],
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

echo "HTTP Code: $httpCode\n";
echo "Erro cURL: " . ($error ?: "Nenhum") . "\n";
echo "Resposta (500 chars): \n" . substr($response, 0, 500) . "\n";
