我想用PHP發送推送通知,但我不知道該怎麼做。用PHP推送通知。如何使用它?
我成功創建了服務工作者。
我從這個頁面拿了鑰匙https://web-push-codelab.appspot.com/。但我不明白他們爲什麼給一個私鑰?
然後我測試我的推notifiaction,併發送一些通知從這個頁面。 但我想從我的PHP請求發送推送通知。 更多的,我會在所有bowsers可能的工作,這段代碼只適用於谷歌瀏覽器。我們可以用firefox,safari,opéra做到這一點嗎?
我已經在使用librairie web-push-php了。 (avaible這裏:https://github.com/web-push-libs/web-push-php) 我複製/ PASE從文檔中的代碼,我remplace我的鑰匙,而訊息:`
<?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, 「成功」:0,「失敗「:1,」canonical_ids「:0,」results「:[{」error「:」InvalidRegistration「}]}'
我也創建了一個firebase帳戶,但我不知道如何使用它。
而且我還想定位通知。 我想發送像「xxx評論到你的帖子」或「xxx喜歡你的帖子」或「xxx發給你的朋友請求」的通知
希望,你可以幫助我。
您剛剛在公共論壇上發佈了您的公鑰和身份驗證令牌。您應該考慮您的帳戶被盜用,並立即撤銷該令牌。 –
可能的重複https://stackoverflow.com/questions/29705993/using-gcm-to-send-notifications-on-app-returns-invalidregistration-error –