<?php
// API Token yang Anda miliki
$apiToken = "aat.NTA.eyJ2IjoxLCJ1Ijo2MzQ1NjksImQiOjg2MzYwNSwiYWkiOjQ4NTAwLCJhayI6ImYwYzA3NjI1LWM4MTktNDM2NS05NWFjLTFjZWZkNDE5Y2IyMSIsImFuIjoid2lzZWxpZS5jby5pZCIsImFwIjoiZmFkNDljMWUtYWU3Zi00YzdjLWI3ZDQtMGUyZGU3ZDg3OTQxIiwidCI6MTcyMTcyNjM1MTYyMn0.YyCkMs8+wbB0Q7rxQwAW0TG5sjelEaFUbyW5FkAn92ln+UU09ZuC/kqwDaCR41Aa0laaFsxbgiPf07E+tFJRYJFSF4XZbkg/vyzbORsrOgNOP1Ttt8aJxOS5GKRD5UArI8vbaKZiAzsB/LV5YtPKenxHZvOJEjQI42xCOHmYz9ZEC6D20bKryO7H+KCRM3v+/3VJaVjl7Ok=.7fcFxUzkMGmLkBIkCFKrVlY8FZ+ttlK2U2f2Jk1Tkzg";

// Signature Secret
$signatureSecret = "fPvWlLX0QvIPepZSDWuZEINbSw7oxUI6gdtvxzTOdEotyFnFnAa0TS6BmogYvS3R";

// URL dasar API
$baseUrl = "https://account.accurate.id/api";

// Fungsi untuk membuat permintaan GET ke endpoint API
function makeApiRequest($endpoint, $apiToken, $signatureSecret) {
    global $baseUrl; // Mengakses $baseUrl dari luar fungsi

    // Buat URL lengkap untuk permintaan API
    $url = $baseUrl . $endpoint;

    // Ambil timestamp UTC
    $timestamp = gmdate('Y-m-d\TH:i:s\Z');

    // Buat signature
    $signature = hash_hmac('sha256', $timestamp, $signatureSecret);

    // Inisialisasi cURL
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Set headers
    $headers = array(
        "Authorization: Bearer $apiToken",
        "X-Api-Timestamp: $timestamp",
        "X-Api-Signature: $signature", // Signature yang diperlukan
    );
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    // Eksekusi cURL
    $response = curl_exec($ch);
    if (curl_errno($ch)) {
        die("cURL Error: " . curl_error($ch));
    }
    curl_close($ch);

    // Decode dan return respons JSON
    return json_decode($response, true);
}

// Permintaan ke endpoint db-list.do
$endpoint = '/db-list.do';
$response = makeApiRequest($endpoint, $apiToken, $signatureSecret);

// Menampilkan respons
echo "<h3>Response from $endpoint</h3>";
echo "<pre>";
print_r($response);
echo "</pre>";
?>
