gpt4 book ai didi

php - FCM将消息从PHP复制到iOS Flutter应用

转载 作者:行者123 更新时间:2023-12-03 03:57:40 27 4
gpt4 key购买 nike

我为Flutter应用程序使用Firebase Cloud Message。

我尝试使用php代码触发推送通知。它给我成功:1个结果,但是在我的设备上,我总是收到2条标题和正文相同但消息ID不同的消息(由Google firebase提供)。

我仔细检查过,我只在服务器端触发一次此功能。

我在服务器上的代码

$url = 'https://fcm.googleapis.com/fcm/send';
$msg = array
(
'body' => $message,
'title' => $title,
'badge' => 1,/*Default sound*/
'sound' => 'default',
);
$fields = array
(
'registration_ids' => $id,
'notification' => $msg
);

$fields = json_encode ( $fields );

$apiKey = 'XXXXXXX'; //IOS

$headers = array (
'Authorization: key='.$apiKey,
'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_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );

$result = curl_exec ( $ch );
curl_close ( $ch );
echo $result;

我尝试从Terminal触发此操作,它工作正常,仅发送了1条消息。我的终端代码:
DATA='{"notification": {"body": "this is a body","title": "this is a title"}, "priority": "high", "data": {"click_action": "FLUTTER_NOTIFICATION_CLICK", "id": "1", "status": "done"}, "to": "MYDEVICETOKEN"}'
curl https://fcm.googleapis.com/fcm/send -H "Content-Type:application/json" -X POST -d "$DATA" -H "Authorization: key=XXXXXXXXX"

最佳答案

我有一个类似的问题,但它在React-native中。也许可以帮到您。问题是有两个服务负责在AndroidManifest中接收通知\消息。

关于php - FCM将消息从PHP复制到iOS Flutter应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59855525/

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