我的文件如下:
<?php
ignore_user_abort();
ob_start();
$url = 'https://fcm.googleapis.com/fcm/send';
$Token = 'c128i0tYn..BA';
$fields = array('to' => $Token ,
'notification' => array('body' => 'HI', 'title' => ':)'));
define('GOOGLE_API_KEY', 'AIzaSyA9..4xU');
$headers = array(
'Authorization:key='.GOOGLE_API_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if($result === false)
die('Curl failed ' . curl_error());
curl_close($ch);
return $result;
?>
它工作正常,但仅用于向特定设备发送通知(通过变量$ Token)。
现在我想向已安装我的应用的所有设备发送通知, 我该怎么办? 。谢谢!
答案 0 :(得分:0)
变化:
'to' => $Token ,
有关:
'registration_ids' => $ArrayOfTokens ,
参考 https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream
答案 1 :(得分:0)
您始终可以向主题发送通知,只需输入通知格式:
{
"to":"/topic/whatever-topic-you-want",
"notification": {
"body":"I am the body",
"title":"I am title"
},
"priority":"high"
}
并且在客户端,如果它是Android设备,那么只需订阅主题&#39;无论你想要什么主题&#39;使用:
FirebaseMessaging.getInstance().subscribeToTopic("whatever-topic-you-want");
订阅该主题的所有设备都将收到通知