• <legend id='2O09Y'><style id='2O09Y'><dir id='2O09Y'><q id='2O09Y'></q></dir></style></legend>

  • <tfoot id='2O09Y'></tfoot>

      <small id='2O09Y'></small><noframes id='2O09Y'>

    1. <i id='2O09Y'><tr id='2O09Y'><dt id='2O09Y'><q id='2O09Y'><span id='2O09Y'><b id='2O09Y'><form id='2O09Y'><ins id='2O09Y'></ins><ul id='2O09Y'></ul><sub id='2O09Y'></sub></form><legend id='2O09Y'></legend><bdo id='2O09Y'><pre id='2O09Y'><center id='2O09Y'></center></pre></bdo></b><th id='2O09Y'></th></span></q></dt></tr></i><div id='2O09Y'><tfoot id='2O09Y'></tfoot><dl id='2O09Y'><fieldset id='2O09Y'></fieldset></dl></div>

      • <bdo id='2O09Y'></bdo><ul id='2O09Y'></ul>

        通过服务器端代码的 Firebase 通知

        时间:2023-07-29
          <bdo id='boTI3'></bdo><ul id='boTI3'></ul>

            <tbody id='boTI3'></tbody>

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

            • <i id='boTI3'><tr id='boTI3'><dt id='boTI3'><q id='boTI3'><span id='boTI3'><b id='boTI3'><form id='boTI3'><ins id='boTI3'></ins><ul id='boTI3'></ul><sub id='boTI3'></sub></form><legend id='boTI3'></legend><bdo id='boTI3'><pre id='boTI3'><center id='boTI3'></center></pre></bdo></b><th id='boTI3'></th></span></q></dt></tr></i><div id='boTI3'><tfoot id='boTI3'></tfoot><dl id='boTI3'><fieldset id='boTI3'></fieldset></dl></div>
                  <tfoot id='boTI3'></tfoot>
                1. <legend id='boTI3'><style id='boTI3'><dir id='boTI3'><q id='boTI3'></q></dir></style></legend>
                2. 本文介绍了通过服务器端代码的 Firebase 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  新的 Firebase 通知服务允许我们使用控制台 UI 向所有移动应用用户发布通知.

                  The new Firebase notifications service allows us to use a Console UI to post notifications to all mobile app users.

                  但我找不到 Firebase 通知服务的任何 REST API.我想通过基于事件的服务器端代码自动向移动用户发送通知.Firebase 通知服务是否具有可通过 HTTP/S 访问的 API?

                  But I could not find any REST API for the Firebase Notifications Service. I want to send notifications to mobile users automatically through server-side code based on an event. Does Firebase Notifications Service have an API that can be accessed over HTTP/S?

                  推荐答案

                  是的,你可以.

                  1)首先,获取你的firebase项目的服务器密钥:

                  1) Firstly, get the server key of your firebase project:

                  Project Settings -> Cloud Messaging Tab -> Copy the Server key.
                  

                  2) 现在,这里是一个示例 php 脚本,用于向特定设备发送通知:

                  2) Now, here is a sample php script to send notification to a specific device:

                  <?php
                  $ch = curl_init("https://fcm.googleapis.com/fcm/send");
                  
                  //The device token.
                  $token = "device_token_here";
                  
                  //Title of the Notification.
                  $title = "The North Remembers";
                  
                  //Body of the Notification.
                  $body = "Bear island knows no king but the king in the north, whose name is stark.";
                  
                  //Creating the notification array.
                  $notification = array('title' =>$title , 'body' => $body);
                  
                  //This array contains, the token and the notification. The 'to' attribute stores the token.
                  $arrayToSend = array('to' => $token, 'notification' => $notification);
                  
                  //Generating JSON encoded string form the above array.
                  $json = json_encode($arrayToSend);
                  
                  //Setup headers:
                  $headers = array();
                  $headers[] = 'Content-Type: application/json';
                  $headers[] = 'Authorization: key= your_server_key_here';
                  
                  //Setup curl, add headers and post parameters.
                  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
                  curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
                  curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);       
                  
                  //Send the request
                  curl_exec($ch);
                  
                  //Close request
                  curl_close($ch);
                  
                  ?>
                  

                  3) 执行输出:

                  {"multicast_id":8XXXD,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:14XX"}]} 
                  

                  这篇关于通过服务器端代码的 Firebase 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:FCM - 在 onMessageReceived 中设置徽章 下一篇:Firebase 推送通知不适用于 iOS 上的生产环境

                  相关文章

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

                    1. <legend id='VKsei'><style id='VKsei'><dir id='VKsei'><q id='VKsei'></q></dir></style></legend>

                      <tfoot id='VKsei'></tfoot>

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