【发布时间】:2016-07-05 07:38:35
【问题描述】:
我正在使用使用 php 的 Firebase API 并使用 JSON 格式发送帖子数据。回复是给我message_id,但消息没有送达。
当我使用 Firebase 控制台而不是具有相同字段的 API 时,它已成功交付。
我的php代码:
<?php
$json_data = '{ "data": {
"title": "Hey you got a message",
"text": "Hi from firebase api"
},
"to": "/topics/all",
"priority": "high"
}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization:key="Used my server key here"'
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>
回复:
{"message_id":64666973642901*****}
PS:使用星号隐藏信息。
更新:
当我将 to 字段设置为特定令牌时,消息正在传递。但设置为topics/all 时不起作用。
有没有其他方法可以像在控制台中一样将其发送给所有与应用关联的人?
【问题讨论】:
标签: php firebase firebase-cloud-messaging firebase-notifications