且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过 cURL/PHP 发送时设备上未收到 Firebase 通知

更新时间:2022-06-10 22:15:29

有两个问题:

  1. 我需要在有效负载中包含 notification 部分,而不是 data
  2. 不知何故,负载没有被 PHP 正确格式化.

最后,我使用 PHP 函数 shell_exec() 通过 SSH 执行 cURL 请求.这并不理想,但它完成了工作.

In the end I used the PHP function shell_exec() to do a cURL request over SSH instead. This isn't ideal but it got the job done.

示例代码:

shell_exec('curl -X POST --header "Authorization: key=<key here>" --header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{"to":"'.$to.'","priority":"high","notification":{"body": "'.stripslashes($message).'"}}"');