Perbaiki .gitignore agar log dan file sensitif tidak ikut commit
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
require __DIR__ . "/../config/connect.php";
|
||||
require __DIR__ . "/../config/encrypt.php";
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$id = $_GET['id'] ?? null;
|
||||
if (!$id) {
|
||||
echo json_encode(['error' => 'Parameter kosong']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Dekripsi dan parsing
|
||||
$datadecrypt = decrypt_url($id);
|
||||
$dataurl = json_decode($datadecrypt, true);
|
||||
|
||||
$ids = $dataurl[0] ?? null; // hasilnya: "2,3,4,7"
|
||||
$filter = $dataurl[1] ?? null; // hasilnya: "informasi"
|
||||
|
||||
if (!$ids) {
|
||||
echo json_encode(['error' => 'Parameter tidak boleh kosong']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Ubah string ID jadi array angka
|
||||
$idArray = array_map('intval', explode(',', $ids));
|
||||
|
||||
// Buat placeholder dinamis
|
||||
$placeholders = implode(',', array_fill(0, count($idArray), '?'));
|
||||
|
||||
// Query database
|
||||
$sql = "SELECT * FROM whatsapp_cloud_api WHERE id_data_server IN ($placeholders) LIMIT 1";
|
||||
$stmt3 = $pdo->prepare($sql);
|
||||
$stmt3->execute($idArray);
|
||||
$wacapi = $stmt3->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$wacapi) {
|
||||
echo json_encode(['error' => 'Data API WhatsApp Cloud tidak ditemukan.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Ambil token dan ID
|
||||
$accessToken = $wacapi['token_access'];
|
||||
$phoneNumberId = $wacapi['waba_id'];
|
||||
|
||||
// Panggil API WhatsApp
|
||||
$url = "https://graph.facebook.com/v17.0/$phoneNumberId/message_templates";
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_HTTPHEADER => ["Authorization: Bearer $accessToken"],
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 15
|
||||
]);
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
echo json_encode(['error' => curl_error($ch)]);
|
||||
exit;
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
// Decode hasil API
|
||||
$data = json_decode($response, true);
|
||||
if (!isset($data['data'])) {
|
||||
echo json_encode(['error' => 'Tidak ada data template ditemukan.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Filter hanya template dengan awalan "informasi_"
|
||||
$templates = array_values(array_filter($data['data'], function ($tpl) {
|
||||
return isset($tpl['name']) && strpos($tpl['name'], 'informasi_') === 0;
|
||||
}));
|
||||
|
||||
// Kirim hasil JSON ke fetch
|
||||
echo json_encode(['templates' => $templates], JSON_UNESCAPED_UNICODE);
|
||||
Reference in New Issue
Block a user