<?php
function track($path, $action, $meta) {
    $url = "http://127.0.0.1/{$path}/track.php";
    $meta['api_key'] = getApiKey($path);
    
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['action' => $action, 'metadata' => $meta]));
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json', "X-Forwarded-For: 189.100.50." . rand(1, 255)]);
    $res = curl_exec($ch);
    curl_close($ch);
    return $res;
}

function getApiKey($path) {
    $keys = [
        'mg' => 'sk_2b0b286cbbbc3471afd8f7f8fabd629e',
        'rj' => 'sk_1d41b7a41218854dd740d4bdfb05dce1',
        'rs' => 'sk_625413ec171d3f6d302b1c257c5cb6b7',
        'df' => 'sk_a94cfaab9db35f9dab17432b00176522',
        'ms' => 'sk_44a6f2bcd139f8a03d93fba22836e770'
    ];
    return $keys[$path];
}

// 1. MG (Renavam 00688384404)
echo "MG... ";
track('mg', 'consulta_placa', ['placa' => 'MMM0000', 'renavam' => '00688384404', 'valor' => 1500.50]); 
echo "OK\n";

// 2. RJ (Renavam 00887775063)
echo "RJ... ";
track('rj', 'consulta_placa', ['placa' => 'RRR0000', 'renavam' => '00887775063', 'valor' => 890.00]);
echo "OK\n";

// 3. RS (Placa IGP0A50, Renavam 00681622830)
echo "RS... ";
track('rs', 'consulta_placa', ['placa' => 'IGP0A50', 'renavam' => '00681622830', 'valor' => 2100.00]);
echo "OK\n";

// 4. DF (Placa JHQ2375)
echo "DF... ";
track('df', 'consulta_placa', ['placa' => 'JHQ2375', 'valor' => 560.75]);
echo "OK\n";

// 5. MS (Placa QAZ8C17, Renavam 01264498559)
echo "MS... ";
track('ms', 'consulta_placa', ['placa' => 'QAZ8C17', 'renavam' => '01264498559', 'valor' => 3200.90]);
echo "OK\n";
