value) * - int $timeout : batas waktu request dalam detik (default 30) * - bool $verifySSL: verifikasi SSL (true untuk produksi) * * Return: * - string|false : raw response dari server, atau false jika cURL error & tidak ada respons */ function connect($endpoint, array $post, int $timeout = 30, bool $verifySSL = true) { // Susun body form-urlencoded yang aman $body = http_build_query($post, '', '&', PHP_QUERY_RFC3986); // Siapkan cURL $ch = curl_init($endpoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // ambil response sebagai string curl_setopt($ch, CURLOPT_POST, 1); // pakai metode POST curl_setopt($ch, CURLOPT_POSTFIELDS, $body); // body form-urlencoded curl_setopt($ch, CURLOPT_HEADER, 0); // sembunyikan header respons curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // ikuti redirect jika ada curl_setopt($ch, CURLOPT_USERAGENT, 'Simple PHP Client/1.0'); // user-agent sederhana curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'Content-Type: application/x-www-form-urlencoded' ]); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // batas waktu request curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifySSL); // verifikasi sertifikat SSL curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verifySSL ? 2 : 0); // verifikasi host SSL // Eksekusi $result = curl_exec($ch); // Jika ada error berat & response kosong, kembalikan false agar mudah dideteksi if (curl_errno($ch) != 0 && empty($result)) { $result = false; } curl_close($ch); return $result; } /* =========================================================== * 1) CONTOH API * (inti contoh adalah fungsi connect() di atas) * =========================================================== */ // Tidak ada pemanggilan khusus di sini; cukup gunakan connect($url, $data) seperti blok-blok di bawah. /* =========================================================== * 2) CONTOH MENAMPILKAN LAYANAN (POST ke /api/layanan.php) * Parameter minimal: key, action=layanan * =========================================================== */ $api_url = rtrim($BASE_API, '/').'/layanan.php'; $post_data = [ 'key' => $API_KEY, 'action' => 'layanan' ]; $resp = connect($api_url, $post_data); $services = json_decode($resp); echo "=== DAFTAR LAYANAN ===\n"; print_r($services); // item umumnya: id, name, price, min, max, note, category, refill, cancel /* =========================================================== * 3) CONTOH MEMBUAT PESANAN (POST ke /api/order.php) * Parameter minimal: key, action=order, service, target, quantity * =========================================================== */ $api_url = rtrim($BASE_API, '/').'/order.php'; $post_data = [ 'key' => $API_KEY, 'action' => 'order', 'service' => 1, // Ganti dengan ID layanan nyata dari daftar layanan 'target' => 'username_or_url', // Ganti sesuai kebutuhan layanan (username/url/id/link) 'quantity' => 100 // Sesuaikan dengan min/max layanan ]; $resp = connect($api_url, $post_data); $order = json_decode($resp); echo "\n=== BUAT ORDER ===\n"; print_r($order); // sukses tipikal: {"status":true,"data":{"id":"1107"}} $order_id = isset($order->data->id) ? $order->data->id : '1107'; // fallback contoh /* =========================================================== * 4) CONTOH MENGECEK STATUS PESANAN (POST ke /api/status.php) * Parameter minimal: key, action=status, id * =========================================================== */ $api_url = rtrim($BASE_API, '/').'/status.php'; $post_data = [ 'key' => $API_KEY, 'action' => 'status', 'id' => (string)$order_id // gunakan ID dari langkah buat pesanan ]; $resp = connect($api_url, $post_data); $status = json_decode($resp); echo "\n=== CEK STATUS ===\n"; print_r($status); // sukses tipikal: {"status":true,"data":{"id":"1107","start_count":...,"remains":...,"status":"Success"}} /* =========================================================== * 5) CONTOH MENGECEK PROFIL AKUN (POST ke /api/profile.php) * Parameter minimal: key, action=profile * =========================================================== */ $api_url = rtrim($BASE_API, '/').'/profile.php'; $post_data = [ 'key' => $API_KEY, 'action' => 'profile' ]; $resp = connect($api_url, $post_data); $profile = json_decode($resp); echo "\n=== PROFIL AKUN ===\n"; print_r($profile); // sukses tipikal: email, username, full_name, balance, level, api_key