39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
// Menangkap data JSON dari webhook
|
|
$data = file_get_contents('php://input');
|
|
|
|
// Decode JSON untuk membaca isinya
|
|
$json_data = json_decode($data, true);
|
|
|
|
// Validasi payload JSON
|
|
if (isset($json_data['results']['apiKey'])) {
|
|
$apiKey = $json_data['results']['apiKey'];
|
|
|
|
// Periksa jika bukan pesan grup
|
|
if (isset($json_data['results']['isGroupMsg']) && $json_data['results']['isGroupMsg'] === false) {
|
|
// Nama file log berdasarkan apiKey
|
|
$log_file = $apiKey . ".log";
|
|
|
|
// Menambahkan data baru dengan waktu (opsional)
|
|
$log_entry = "[" . date('Y-m-d H:i:s') . "] " . $data . PHP_EOL;
|
|
|
|
// Simpan ke file log sesuai apiKey
|
|
if (file_put_contents($log_file, $log_entry, FILE_APPEND) !== false) {
|
|
// Tanggapan ke pengirim webhook
|
|
http_response_code(200);
|
|
echo "Data webhook diterima dan disimpan di $log_file";
|
|
} else {
|
|
// Gagal menyimpan file log
|
|
http_response_code(500);
|
|
echo "Gagal menyimpan data ke file log.";
|
|
}
|
|
} else {
|
|
// Pesan grup tidak diproses
|
|
http_response_code(400);
|
|
echo "Pesan grup tidak diproses.";
|
|
}
|
|
} else {
|
|
// Jika `apiKey` tidak ditemukan
|
|
http_response_code(400);
|
|
}
|
|
?>
|