i would like to send push notification in PHP, but i don't know how to do.
I successfully create the Service Worker.
I took a key from this page https://web-push-codelab.appspot.com/. But i don't understand why do they give a private key ?
Then i test my push notifiaction, and i send some notification from this page. But I would like to send push notification from my PHP request. More, i would this work on all the bowsers possible, this code works just with google chrome. Can we do this with firefox, safari, opéra ?
I already use the librairie web-push-php. (avaible here: https://github.com/web-push-libs/web-push-php) I copy/pase the code from the documentation, and i remplace my key, and messages:`
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
use Minishlink\WebPush\WebPush;
$notifications = array(
array(
'endpoint' => 'https://updates.push.services.mozilla.com/push/abc...', // Firefox 43+
'payload' => 'hello !',
'userPublicKey' => '*****', // base 64 encoded, should be 88 chars
'userAuthToken' => '*****', // base 64 encoded, should be 24 chars
), array(
'endpoint' => 'https://android.googleapis.com/gcm/send/abcdef...', // Chrome
'payload' => '{msg:"je fais un test"}',
'userPublicKey' => '*****',
'userAuthToken' => null,
)
);
$webPush = new WebPush();
// send multiple notifications with payload
foreach ($notifications as $notification) {
$webPush->sendNotification(
$notification['endpoint'],
$notification['payload'], // optional (defaults null)
$notification['userPublicKey'], // optional (defaults null)
$notification['userAuthToken'] // optional (defaults null)
);
}
$webPush->flush();
But this code don't work, the page return this :
{"multicast_id":6971447349404987967,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}`
I also create a firebase account, but i don't know how to usi it.
And i would like also target the notifications. I would like to send the notification like "xxx commented to your post" or "xxx liked to your post" or "xxx send to you a friend request"
Hope, you can help me.