feat: FCM push notification wali (HTTP v1 + service account) — otomatis saat pelanggaran/SP, platform web didukung, command fcm:test

This commit is contained in:
Novy San87
2026-08-06 07:19:36 +07:00
parent 921a3495db
commit b4d212ad0e
6 changed files with 311 additions and 2 deletions
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace App\Console\Commands;
use App\Models\ParentDevice;
use App\Services\FcmService;
use Illuminate\Console\Command;
class TestFcmPush extends Command
{
protected $signature = 'fcm:test {--token= : Token FCM perangkat (opsional, default: token web pertama)}';
protected $description = 'Kirim push notification uji coba via FCM';
public function handle(FcmService $fcm): int
{
if (! $fcm->isEnabled()) {
$this->error('FCM belum dikonfigurasi. Isi FCM_SERVICE_ACCOUNT & FCM_PROJECT_ID di .env');
return self::FAILURE;
}
$token = $this->option('token');
if (! $token) {
$token = ParentDevice::where('platform', 'web')->value('fcm_token');
}
if (! $token) {
$this->error('Tidak ada token perangkat. Daftarkan dulu lewat API /parent/devices atau pakai --token=');
return self::FAILURE;
}
$ok = $fcm->sendToToken($token, [
'title' => '🔔 Uji Coba S1WON DIGI',
'body' => 'Push notification berhasil! Ini notifikasi dari server.',
], ['type' => 'test']);
$this->info($ok ? 'Notifikasi terkirim ✅' : 'Gagal mengirim ❌ (cek log)');
return $ok ? self::SUCCESS : self::FAILURE;
}
}