update wa official API

This commit is contained in:
WD - Dev
2025-10-07 21:01:15 +07:00
parent efca8f5f80
commit eb13c69431
55 changed files with 138040 additions and 1543 deletions
+65
View File
@@ -0,0 +1,65 @@
<?php
// include "../manjapro-project/config/connect.php";
include "../config/connect.php";
$stmt = $pdo->prepare("SELECT * FROM whatsapp_cloud_api GROUP BY id_data_server");
$stmt->execute();
$whatsapp = $stmt->fetchAll(PDO::FETCH_ASSOC);
$adaPesan = false;
foreach ($whatsapp as $waKey) {
$stmt = $pdo->prepare("
SELECT id, pesan
FROM master_pesan
WHERE id_data_server = :id_data_server
AND status = 'PENDING'
AND gateway_type = 'official'
LIMIT 1
");
$stmt->execute([':id_data_server' => $waKey['id_data_server']]);
$pesan = $stmt->fetch(PDO::FETCH_ASSOC);
if ($pesan) {
$adaPesan = true;
$access_token = $waKey['token_access'];
$phone_number_id = $waKey['number_id'];
$url = "https://graph.facebook.com/v17.0/$phone_number_id/messages";
$data = json_decode($pesan['pesan'], true);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $access_token",
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
} else {
$responseData = json_decode($response, true); // decode JSON
if (isset($responseData['messages'][0]['id'])) {
$wa_message_id = $responseData['messages'][0]['id'];
$stmt = $pdo->prepare("UPDATE master_pesan SET status = 'PROSES', wa_message_id = :wa_id WHERE id = :id");
$stmt->execute([':wa_id' => $wa_message_id, ':id' => $pesan['id']]);
echo "Pesan ID {$pesan['id']} Cloud API Official berhasil dikirim, WA ID: $wa_message_id<br>";
} else {
echo "Gagal mengirim pesan Cloud API Official ID {$pesan['id']}, response: $response<br>";
}
}
curl_close($ch);
}
}
// if (!$adaPesan) {
// echo "Tidak ada pesan perlu dikirim Cloud API Official";
// }