is it possible to send notifications on desktop php code example
Example 1: how to send notification to android from php
<?php
$apiKey = "your api key";
$registrationIDs = array( "reg id1","reg id2");
$message = "Your message e.g. the title of post";
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ),
);
$headers = array(
'Authorization: key=' . $apiKey,
'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));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
Example 2: send notification php to PC
use Joli\JoliNotif\Notification;
if ($notifier) {
$notification =
(new Notification())
->setBody('The notification body')
->setTitle('The notification title')
->setIcon(__DIR__.'/Resources/icons/success.png');
;
$notifier->send($notification);
}