推送通知脚本无法传递消息(此网站已在后台更新)

时间:2018-06-27 07:44:23

标签: javascript php push-notification firebase-cloud-messaging

我们已经开发了订​​阅脚本的JS部分。这是流程:

  1. 我们显示模式窗口
  2. 用户点击订阅按钮
  3. 显示了HTTPs Popup iframe。
  4. 用户单击本机浏览器的订阅按钮
  5. ajax请求通过用户令牌发送到服务器

您可以在此处查看其工作方式:https://kuni.space/

现在,我们已经开发了一个php脚本,用于向订阅的用户发送推送通知。这是代码:

$ipServ = "firebase_server_key";
$id = "cYT_iJKme2Q:APA91bG1c1WmkFZvkSxud7R3HeF5DpePnmZwYRLY6-FOWsVLHAF6X9ly4pl-wtb2LjA1ed744tRZDvdzFwB3WsZAaqvNmtl2JyWVt8agx8gDtKMROMRH9VLm3lgGe7YzkYIlSWD3ejZY";


#API access key from Google API's Console
define('API_ACCESS_KEY', $ipServ);
$registrationIds = $id;

#prep the bundle
$msg = array
(
    'body' => 'Hello world',
    'title' => 'Title Hello world',
    'icon' => '',/*Default Icon*/
    'sound' => 'mySound'/*Default sound*/,
    "click_action" => "OPEN_ACTIVITY_1"
);

$msg1 = array
(
    'message' => '\u270C Peace, Love \u2764 and PhoneGap \u2706!',
    'title' => 'This is a title. title',
    'subtitle' => 'This is a subtitle. subtitle',
    'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
    'vibrate' => 1,
    'sound' => 1,
    'largeIcon' => 'large_icon',
    'smallIcon' => 'small_icon',
    'msgcnt' => 3
);

$fields = array
(
    'to' => $id,
    'notification' => $msg,
    'data' => $msg1,
    'priority' => 10
);


$headers = array
(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);

#Send Reponse To FireBase Server
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
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 Of FireBase Server

我执行了此脚本,但是在接收方,我看到的是消息“此站点已在后台更新”,而不是我的消息。

如何修改此脚本以向接收方传递正确的消息?

0 个答案:

没有答案