"Hello from Api", 'vibrate' => 1, 'sound' -6ren">
gpt4 book ai didi

php - Firebase 如何发送主题通知

转载 作者:IT王子 更新时间:2023-10-28 23:37:07 28 4
gpt4 key购买 nike

我正在使用以下脚本向特定用户发送通知:

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'My_API_KEY' );
$registrationIds = array( TOKENS );
// prep the bundle
$msg = array
(
'body' => "abc",
'title' => "Hello from Api",
'vibrate' => 1,
'sound' => 1,
);

$fields = array
(
'registration_ids' => $registrationIds,
'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 );
echo $result;
?>

脚本运行良好,但我如何向所有安装了我的应用程序的用户发送通知。我在我的应用程序(警报)中创建了一个主题,我可以通过 firebase 控制台向所有用户发送通知。谁能指导我更新上面的主题脚本。

最佳答案

我通过替换修复了

$fields = array
(
'registration_ids' => $registrationIds,
'notification' => $msg
);

$fields = array
(
'to' => '/topics/alerts',
'notification' => $msg
);

关于php - Firebase 如何发送主题通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42384157/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com