【发布时间】:2020-06-29 14:45:32
【问题描述】:
我想在运行时在 firebase 上创建主题。一旦管理员在我的数据库中创建了某个记录,我将创建相应的主题,以便与该主题关联的用户可以使用 firebase 接收通知。
在固定主题的情况下,我可以像这样成功发送符号:
public static function SendFireBaseBroadCast($topicName, $title, $body) {
#API access key from Google API's Console
define('API_ACCESS_KEY', 'API_KEY');
$msg = array
(
'body' => $body,
'title' => $title,
'icon' => 'myicon', /* Default Icon */
'sound' => 'mySound'/* Default sound */
);
$fields = array
(
'to' => "/topics/" . $topicName,
'notification' => $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));
$result = curl_exec($ch);
curl_close($ch);
}
如何在 firebase 运行时创建主题?
【问题讨论】:
标签: php firebase firebase-cloud-messaging