40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Dhiva\Core;
|
|
|
|
class Notification
|
|
{
|
|
public function getNotification()
|
|
{
|
|
$notification = array();
|
|
$notification['title'] = "KAMTIBMAS (KEAMANAN KETERTIBAN MASYARAKAT)";
|
|
$notification['message'] = "Selamat datang di Aplikasi KAMTIBMAS (KEAMANAN KETERTIBAN MASYARAKAT) (0)";
|
|
$notification['image'] = "https://project.adhivasindo.co.id/diy/assets/logo/logo_polda_diy.png";
|
|
return $notification;
|
|
}
|
|
public function publish($publish)
|
|
{
|
|
$ff = explode('#', $publish['isi']);
|
|
$notification['title'] = $ff[0];
|
|
$notification['message'] =$ff[1]. PHP_EOL. $ff[2]. PHP_EOL. $ff[3];
|
|
$fields = array('to' => FIREBASE_TOPIC . $publish['topic'], 'data' => $notification);
|
|
$url = 'https://fcm.googleapis.com/fcm/send';
|
|
$headers = array('Authorization: key=' . FIREBASE_API, 'Content-Type: application/json');
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
|
|
|
|
$output = curl_exec($ch);
|
|
if (!json_decode($output)) {
|
|
print_r($output);
|
|
die;
|
|
}
|
|
curl_close($ch);
|
|
return json_decode($output);
|
|
}
|
|
}
|