update wa official API
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
require dirname(__DIR__) . "/config/connect.php";
|
||||
|
||||
$input = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
if (!$input) {
|
||||
echo json_encode(["status" => "error", "message" => "Invalid input"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $input['payload'] ?? null;
|
||||
$nama = $input['nama'] ?? null;
|
||||
$SvId = $input['id'] ?? null;
|
||||
|
||||
if (!$payload || !$nama || !$SvId) {
|
||||
echo json_encode(["status" => "error", "message" => "Data tidak lengkap"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$template_name = $payload['template']['name'];
|
||||
|
||||
$pesan_official = json_encode($payload, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// Kalau SvId bisa "2" atau "2,3,4"
|
||||
$svIds = array_map("trim", explode(",", $SvId));
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE master_template_pesan
|
||||
SET pesan_official = :pesan_official, nama_template = :template_name, status_pesan = 'WhatsApp Official API', gateway_type = 'official'
|
||||
WHERE nama = :nama AND id_data_server = :sv_id");
|
||||
|
||||
$updated = 0;
|
||||
foreach ($svIds as $id) {
|
||||
$stmt->execute([
|
||||
":pesan_official" => $pesan_official,
|
||||
":nama" => $nama,
|
||||
":template_name" => $template_name,
|
||||
":sv_id" => $id
|
||||
]);
|
||||
$updated += $stmt->rowCount();
|
||||
}
|
||||
|
||||
if ($updated > 0) {
|
||||
echo json_encode([
|
||||
"status" => "success",
|
||||
"message" => "Data berhasil diupdate untuk " . count($svIds) . " server"
|
||||
]);
|
||||
} else {
|
||||
echo json_encode(["status" => "warning", "message" => "Tidak ada data yang berubah"]);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo json_encode(["status" => "error", "message" => $e->getMessage()]);
|
||||
}
|
||||
Reference in New Issue
Block a user