• <bdo id='4mY8T'></bdo><ul id='4mY8T'></ul>

  • <tfoot id='4mY8T'></tfoot>

        <small id='4mY8T'></small><noframes id='4mY8T'>

        <i id='4mY8T'><tr id='4mY8T'><dt id='4mY8T'><q id='4mY8T'><span id='4mY8T'><b id='4mY8T'><form id='4mY8T'><ins id='4mY8T'></ins><ul id='4mY8T'></ul><sub id='4mY8T'></sub></form><legend id='4mY8T'></legend><bdo id='4mY8T'><pre id='4mY8T'><center id='4mY8T'></center></pre></bdo></b><th id='4mY8T'></th></span></q></dt></tr></i><div id='4mY8T'><tfoot id='4mY8T'></tfoot><dl id='4mY8T'><fieldset id='4mY8T'></fieldset></dl></div>
        <legend id='4mY8T'><style id='4mY8T'><dir id='4mY8T'><q id='4mY8T'></q></dir></style></legend>

        如何从网络向应用发送 FCM 通知

        How to send FCM notification to app from web(如何从网络向应用发送 FCM 通知)
        • <i id='YbMO7'><tr id='YbMO7'><dt id='YbMO7'><q id='YbMO7'><span id='YbMO7'><b id='YbMO7'><form id='YbMO7'><ins id='YbMO7'></ins><ul id='YbMO7'></ul><sub id='YbMO7'></sub></form><legend id='YbMO7'></legend><bdo id='YbMO7'><pre id='YbMO7'><center id='YbMO7'></center></pre></bdo></b><th id='YbMO7'></th></span></q></dt></tr></i><div id='YbMO7'><tfoot id='YbMO7'></tfoot><dl id='YbMO7'><fieldset id='YbMO7'></fieldset></dl></div>
          <tfoot id='YbMO7'></tfoot>

          1. <legend id='YbMO7'><style id='YbMO7'><dir id='YbMO7'><q id='YbMO7'></q></dir></style></legend>
                <tbody id='YbMO7'></tbody>
                  <bdo id='YbMO7'></bdo><ul id='YbMO7'></ul>

                  <small id='YbMO7'></small><noframes id='YbMO7'>

                  本文介绍了如何从网络向应用发送 FCM 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发基于 Firebase 数据库和存储的聊天应用程序.一切正常,但现在我需要实现 FCM 以在应用程序处于后台或前台时接收应用程序的通知.我找不到一种在 PHP 中实现的方法,它监听 firebase 数据库中的任何更改,如果有任何更改,则向应用程序发送推送通知.

                  I am developing chat app which is based on Firebase Database and Storage. Everything is working fine, but now I need implementation of FCM to receive notification on app when app is in background or foreground. I can't find a way to implement in PHP which listen any changes in firebase database and if there is any change then send push notification to app.

                  有很多代码从 PHP 发送通知,但没有一个是基于 Firebase 数据库的,甚至官方文档也有我的共享主机不支持的 Node.js 指南.

                  There is so many code which send notification from PHP, but none is based on Firebase database and even official documentation has Node.js guide which my shared hosting doesn't support.

                  我已经在我的应用端实现了 FCM 代码,并通过 Firebase 控制台进行了测试.

                  I already implemented FCM code on my app side which is tested from Firebase Console.

                  这是我的 Firebase 数据库结构

                  Here is my Firebase database structure

                  推荐答案

                  发送推送通知只是向 FCM 服务器发送 post 请求的问题.

                  Sending a push notification is only a matter of sending a post request to FCM servers.

                  这是工作示例:

                  $data = json_encode($json_data);
                  //FCM API end-point
                  $url = 'https://fcm.googleapis.com/fcm/send';
                  //api_key in Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key
                  $server_key = 'YOUR_KEY';
                  //header with content_type api key
                  $headers = array(
                      'Content-Type:application/json',
                      'Authorization:key='.$server_key
                  );
                  //CURL request to route notification to FCM connection server (provided by Google)
                  $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_VERIFYHOST, 0);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                  $result = curl_exec($ch);
                  if ($result === FALSE) {
                      die('Oops! FCM Send Error: ' . curl_error($ch));
                  }
                  curl_close($ch);
                  

                  JSON 负载示例:

                  [
                      "to" => 'DEVICE_TOKEN',
                      "notification" => [
                          "body" => "SOMETHING",
                          "title" => "SOMETHING",
                          "icon" => "ic_launcher"
                      ],
                      "data" => [
                          "ANYTHING EXTRA HERE"
                      ]
                  ]
                  

                  这篇关于如何从网络向应用发送 FCM 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                          <tbody id='frp8Z'></tbody>
                          <tfoot id='frp8Z'></tfoot>

                        • <small id='frp8Z'></small><noframes id='frp8Z'>

                          <i id='frp8Z'><tr id='frp8Z'><dt id='frp8Z'><q id='frp8Z'><span id='frp8Z'><b id='frp8Z'><form id='frp8Z'><ins id='frp8Z'></ins><ul id='frp8Z'></ul><sub id='frp8Z'></sub></form><legend id='frp8Z'></legend><bdo id='frp8Z'><pre id='frp8Z'><center id='frp8Z'></center></pre></bdo></b><th id='frp8Z'></th></span></q></dt></tr></i><div id='frp8Z'><tfoot id='frp8Z'></tfoot><dl id='frp8Z'><fieldset id='frp8Z'></fieldset></dl></div>
                          • <bdo id='frp8Z'></bdo><ul id='frp8Z'></ul>
                            <legend id='frp8Z'><style id='frp8Z'><dir id='frp8Z'><q id='frp8Z'></q></dir></style></legend>