【发布时间】:2018-06-01 09:07:50
【问题描述】:
我正在开发类似 WhatsApp 的网络应用程序,并希望通知用户有新消息。我正在使用 Firebase 的推送通知。
如果用户收到 message1,则会显示“message1”的通知。 当消息 2 出现时,我想将其附加到上一个通知的正文中,而不是显示新的通知。
如“消息 1 \n 消息 2”等。
一旦通过单击读取通知并且当有新消息进来时说“Message3”,它应该是正文中的新消息,没有已阅读的Message1和Message2。
我发送通知的代码如下所示。
define( 'API_ACCESS_KEY', 'AAAAlHKlaCE_______________________-NdJXkojLf9Ap9mu' );
$data = array("to" => $key,
"priority" => "normal",
"collapseKey" => "demo",
"notification" => array(
"title" => "New message",
"body" => "message1 ",
"icon" => "../profiles/p1.jpg",
"tag" => "hello",
"click_action" => "http://website.com"
));
$data_string = json_encode($data);
echo "The Json Data : ".$data_string;
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$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_POSTFIELDS, $data_string);
$result = curl_exec($ch);
curl_close ($ch);
就像 whatsapp 一样,将对话的新消息添加到通知的正文中。 如何使用 firebase 来做到这一点?
【问题讨论】:
-
为什么这个帖子有两个反对票?
-
问题的格式可以稍微多一点,以便于阅读和理解。但是,是的,在不评论需要纠正的地方的情况下投反对票是很糟糕的。你得到了我的投票和答案。希望对您有所帮助。
-
我已经改写了这个问题。看看它既满足你的需要,如果不满足,那就更正。
标签: firebase web-applications push-notification notifications progressive-web-apps