update wa official API
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
// get_onu_detail.php
|
||||
require __DIR__ . "/../config/encrypt.php";
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$id = isset($_POST['id']) ? $_POST['id'] : null;
|
||||
|
||||
$datadecrypt = decrypt_url($id);
|
||||
$dataurl = json_decode($datadecrypt, true);
|
||||
|
||||
// Ambil parameter dari request
|
||||
$tenant_id = $dataurl[0] ?? null;
|
||||
$sn = $dataurl[1] ?? null;
|
||||
$mac = $dataurl[2] ?? null;
|
||||
|
||||
if (!$tenant_id || (!$sn && !$mac)) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'tenant_id dan salah satu SN/MAC harus diisi'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fungsi helper untuk request ke API
|
||||
*/
|
||||
function call_api($tenant_id, $param) {
|
||||
$api_url = "http://manjapro.net:20263/api/v1/onu/?tenant_id={$tenant_id}&macsn={$param}";
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $api_url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
if (curl_errno($ch)) {
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
return ['error' => $error];
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return ['http_code' => $http_code, 'response' => $response];
|
||||
}
|
||||
|
||||
// 1️⃣ Coba pakai SN dulu
|
||||
$result = null;
|
||||
if ($sn) {
|
||||
$result = call_api($tenant_id, $sn);
|
||||
if ($result['http_code'] == 200 && !empty($result['response']) && $result['response'] !== '[]') {
|
||||
$data = json_decode($result['response'], true);
|
||||
|
||||
// 🚀 Timpa kolom onu_mac dengan nilai dari $mac
|
||||
foreach ($data as &$row) {
|
||||
$row['onu_mac'] = $mac; // atau substr($mac, 0, -1) kalau mau custom
|
||||
}
|
||||
|
||||
echo json_encode($data);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// 2️⃣ Kalau SN gagal / kosong, coba pakai MAC
|
||||
if ($mac) {
|
||||
$result = call_api($tenant_id, substr($mac, 0, -1));
|
||||
if ($result['http_code'] == 200 && !empty($result['response']) && $result['response'] !== '[]') {
|
||||
$data = json_decode($result['response'], true);
|
||||
|
||||
// 🚀 Timpa kolom onu_mac dengan nilai dari $mac
|
||||
foreach ($data as &$row) {
|
||||
$row['onu_mac'] = $mac; // atau bisa diubah custom sesuai kebutuhan
|
||||
}
|
||||
|
||||
echo json_encode($data);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Jika dua-duanya gagal
|
||||
if (isset($result['error'])) {
|
||||
echo json_encode([[
|
||||
'status' => 'error',
|
||||
'message' => $result['error'],
|
||||
'onu_mac' => $mac
|
||||
]]);
|
||||
} else {
|
||||
echo json_encode([[
|
||||
'status' => 'error',
|
||||
'message' => "Data ONU tidak ditemukan dengan SN maupun MAC",
|
||||
'onu_mac' => $mac
|
||||
]]);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -31,7 +31,7 @@ $orderDir = $_POST['order'][0]['dir'] ?? 'asc';
|
||||
$search = $_POST['search']['value'] ?? '';
|
||||
$where = "WHERE $SqlSvData status = 'aktif'";
|
||||
if(!empty($search)) {
|
||||
$where .= " AND (nama LIKE :search OR nik LIKE :search OR akun LIKE :search OR status_koneksi LIKE :search OR nomor_whatsapp LIKE :search OR nama_paket LIKE :search OR nama_server LIKE :search OR alamat LIKE :search OR time_start LIKE :search)";
|
||||
$where .= " AND (nama LIKE :search OR nik LIKE :search OR akun LIKE :search OR status_koneksi LIKE :search OR nomor_whatsapp LIKE :search OR nama_paket LIKE :search OR nama_server LIKE :search OR alamat LIKE :search OR time_start LIKE :search OR mac_address LIKE :search)";
|
||||
}
|
||||
|
||||
// Hitung total
|
||||
@@ -41,7 +41,7 @@ $recordsTotal = $totalStmt->fetchColumn();
|
||||
// Query data
|
||||
$sql = "SELECT id,akun,user_hotspot,nama,alamat,latitude,longitude,nomor_whatsapp,email,nik,
|
||||
nama_server,nama_paket,time_start,status_koneksi,nama_mikrotik,id_setting_mikrotik,
|
||||
time_update,ip_address
|
||||
time_update,ip_address,mac_address,serial_number,uuid
|
||||
FROM v_pelanggan $where
|
||||
ORDER BY $orderCol $orderDir
|
||||
LIMIT :limit OFFSET :offset";
|
||||
@@ -62,6 +62,22 @@ foreach($data as $row) {
|
||||
: "<a href='https://google.com/maps/?q={$row['latitude']},{$row['longitude']}' target='_blank'>{$row['latitude']}, {$row['longitude']}</a>";
|
||||
|
||||
$wa = "{$row['nomor_whatsapp']} <a href='https://wa.me/{$row['nomor_whatsapp']}' target='_blank' class='btn btn-sm btn-success' style='border-radius:20px;'><i class='fab fa-whatsapp'></i></a><br>{$row['email']}";
|
||||
|
||||
|
||||
$dataId = encrypt_url(json_encode([$row['uuid'],$row['serial_number'],$row['mac_address']]));
|
||||
$server = $row['nama_server'] . '<br><i class="text-secondary"><small>' . $row['nama_mikrotik'] . '</small></i>';
|
||||
|
||||
$buttonmodem = '<a href="javascript:void(0)"
|
||||
class="btn btn-secondary btn-sm rounded-circle openModal"
|
||||
data-toggle="modal"
|
||||
data-target="#exampleModal"
|
||||
data-id="' . $dataId . '"
|
||||
style="width:25px; height:25px; display:flex; align-items:center; justify-content:center;">
|
||||
<i class="fa fa-cog"></i>
|
||||
</a>
|
||||
<i class="text-secondary"><small>' . $row['mac_address'] . '</small></i>
|
||||
<i class="text-secondary"><small>' . $row['serial_number'] . '</small></i>
|
||||
';
|
||||
|
||||
$status = $row['status_koneksi'];
|
||||
if($status == 'On') {
|
||||
@@ -86,8 +102,8 @@ foreach($data as $row) {
|
||||
$rowData[] = $row['alamat'];
|
||||
$rowData[] = $latlong;
|
||||
$rowData[] = $wa;
|
||||
$rowData[] = $row['nama_server'];
|
||||
$rowData[] = $row['nama_mikrotik'];
|
||||
$rowData[] = $server;
|
||||
$rowData[] = $buttonmodem;
|
||||
$rowData[] = $row['nama_paket'];
|
||||
$rowData[] = $status;
|
||||
$rowData[] = $row['time_start'];
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
include '../config/connect.php';
|
||||
|
||||
// Ambil parameter DataTables
|
||||
|
||||
@@ -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