Closed musaffar-patel closed 3 years ago
Hi
I have managed to get the library up and running and have successfully subscribed client side.
However, when performing a test and pushing a new notification, a success error is printed however no notification appears on the desktop.
[v] Message sent successfully for subscription https://fcm.googleapis.com/fcm/send/f1azG0YpefY:APA91bEgPUCksrDdHc3vpd8JZUsiLnf6sphqgw8TdyPVyTMaviZGvBY76RPJ2zFmMFpvhxoL3hvbvMSJ_O8Ct5nqKmDYozsZh-IU-gm2DWqeTVRRgW9k6Hq58vxnYi75RehmdXbEr_yb.
I have double checked my public and private keys and also the end point. All seem correct.
below is the code, much of it take from the readme.md: private key has been removed
$auth = [ 'VAPID' => [ 'subject' => 'mailto:xxx@gmail.com', 'publicKey' => 'BBFwt4l1ZvIoCkH2Cp9DSQKGN6MUQ5mFXrT3OLKNsoqSTweloz87hZtIA64Zgx2zROgxPWN1l61q8ezM0QkD2Dg', 'privateKey' => '', ], ]; $notifications = [ [ 'subscription' => Subscription::create([ 'endpoint' => 'https://fcm.googleapis.com/fcm/send/f1azG0YpefY:APA91bEgPUCksrDdHc3vpd8JZUsiLnf6sphqgw8TdyPVyTMaviZGvBY76RPJ2zFmMFpvhxoL3hvbvMSJ_O8Ct5nqKmDYozsZh-IU-gm2DWqeTVRRgW9k6Hq58vxnYi75RehmdXbEr_yb', // Chrome 'contentEncoding' => 'aesgcm', 'publicKey' => 'BBFwt4l1ZvIoCkH2Cp9DSQKGN6MUQ5mFXrT3OLKNsoqSTweloz87hZtIA64Zgx2zROgxPWN1l61q8ezM0QkD2Dg', 'privateKey' => '', ]), 'payload' => '{"msg":"Hello World!"}' // optional (defaults null), ], ]; $webPush = new WebPush($auth); // send multiple notifications with payload foreach ($notifications as $notification) { $webPush->queueNotification( $notification['subscription'], $notification['payload'] // optional (defaults null) ); } /** * Check sent results * @var MessageSentReport $report */ foreach ($webPush->flush() as $report) { $endpoint = $report->getRequest()->getUri()->__toString(); if ($report->isSuccess()) { echo "[v] Message sent successfully for subscription {$endpoint}."; } else { echo "[x] Message failed to sent for subscription {$endpoint}: {$report->getReason()}"; } } /** * send one notification and flush directly * @var MessageSentReport $report */ $report = $webPush->sendOneNotification( $notifications[0]['subscription'], $notifications[0]['payload'] // optional (defaults null) );
When I test the push notification on https://web-push-codelab.glitch.me/ using the same keys the notification appears as expected.
Any help here would be appreciated as I've already spent 2 days on this but not getting far.
I have the same problem! No message is coming from the browser. But returned report says everything is fine. What was your solution?
Hi
I have managed to get the library up and running and have successfully subscribed client side.
However, when performing a test and pushing a new notification, a success error is printed however no notification appears on the desktop.
[v] Message sent successfully for subscription https://fcm.googleapis.com/fcm/send/f1azG0YpefY:APA91bEgPUCksrDdHc3vpd8JZUsiLnf6sphqgw8TdyPVyTMaviZGvBY76RPJ2zFmMFpvhxoL3hvbvMSJ_O8Ct5nqKmDYozsZh-IU-gm2DWqeTVRRgW9k6Hq58vxnYi75RehmdXbEr_yb.
I have double checked my public and private keys and also the end point. All seem correct.
below is the code, much of it take from the readme.md: private key has been removed
When I test the push notification on https://web-push-codelab.glitch.me/ using the same keys the notification appears as expected.
Any help here would be appreciated as I've already spent 2 days on this but not getting far.