我正在使用php服务器发送FCM推送通知.我想知道如何同时向多个主题发送推送通知.
这是我的代码.
function sendPush($topic,$msg){
$API_ACCESS_KEY = '...';
$msg = array
(
'msg' => $msg
);
$fields = array('to' => '/topics/' . $topic, 'priority' => 'high', 'data' => $msg);
$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_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$pushResult = curl_exec($ch);
curl_close($ch);
}
Run Code Online (Sandbox Code Playgroud) 在调用FCM API时我遇到了一个悲剧性的问题: - 简而言之当我使用以下方法调用API时:
URL:-https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AAAA4Kkj8iw:APA91bE......vE4Hxg
{
"condition" : "'Software' in topics",
"data":{
"title":"Title",
"message":"Hello,Via Multiple Topics"
}
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,我在设备上收到了通知,我订阅了主题"软件",但是当我选择多个主题并将主体更改为
{
"condition" : "'Software' in topics || 'IOT' in topics",
"data":{
"title":"Title",
"message":"Hello,Via Multiple Topics"
}
}
Run Code Online (Sandbox Code Playgroud)
然后我没有收到我在POSTMAN上测试过的通知,它显示已发送消息,但我的设备上没有收到任何通知.
android firebase google-cloud-messaging firebase-cloud-messaging