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

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

      <tfoot id='JrdrV'></tfoot>

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

        时间:2024-08-22
          <bdo id='XqcDn'></bdo><ul id='XqcDn'></ul>

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

              <tbody id='XqcDn'></tbody>

                  <tfoot id='XqcDn'></tfoot>

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

                1. 本文介绍了通过 cURL/PHP 发送时设备上未收到 Firebase 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 iOS 应用,该应用已在应用商店上线.我可以将推送通知发送到安装了该应用的 iOS 设备,但前提是我从 Firebase 控制台发送它们.

                  I have an iOS app which is live on the app store. I am able to send push notifications to iOS devices which have the app installed, but only when I send them from the Firebase console.

                  当我尝试通过 cURL 请求发送推送通知时,来自服务器的响应表明我成功了,但设备上没有收到消息.我已经尝试过使用多播和单个接收者有效负载.

                  When I try to send push notifications via a cURL request, the response from the server indicates that I was successful but the message isn't received on the device. I have tried this with both multicast and single recipient payloads.

                  我一定遗漏了一些更基本的东西,但我看不到它.

                  I must be missing something more fundamental, but I can't see it.

                  这是我的 PHP 代码:

                  Here is my PHP code:

                  <?php
                  // API access key from Google API's Console
                  define( 'API_ACCESS_KEY', 'AI*****4LPGkx8xtDG2tBl*****7KWJfmp1szcA' );
                  $registrationIds = array( $_GET['id'] );
                  // prep the bundle
                  $msg = array
                  (
                      'message'   => 'here is a message. message',
                      'title'     => 'This is a title. title'
                  );
                  $fields = array
                  (
                      'to'            => "cUxd-iTVVWo:APA*****kQTuqJ5RREKhhlJjm27NCuVfUn5APg3lBFqh-YWjgx*****iOpAQeLB14CzM2YTwIJo_75jzCmbFLKj0_zpKSHvAEbmJz*****BBezGJIng-N4H-cAD6ahY7mQNYZtEJLAIE",
                      'data'          => $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;
                  

                  这是我在运行此代码时得到的响应:

                  Here is the response I get when running this code:

                  {"multicast_id":5814921248239922706,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1476193002715692%a4ddee3cf9fd7ecd"}]}

                  {"multicast_id":5814921248239922706,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1476193002715692%a4ddee3cf9fd7ecd"}]}

                  推荐答案

                  有两个问题:

                  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).'"}}"');
                  

                  这篇关于通过 cURL/PHP 发送时设备上未收到 Firebase 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 PHP 中使用 fcm(firebase 控制台)向 iphone 发送推送通知? 下一篇:FCM 推送通知问题:“错误":“未注册"

                  相关文章

                    <bdo id='nyMLn'></bdo><ul id='nyMLn'></ul>

                  1. <small id='nyMLn'></small><noframes id='nyMLn'>

                    <legend id='nyMLn'><style id='nyMLn'><dir id='nyMLn'><q id='nyMLn'></q></dir></style></legend>

                    <tfoot id='nyMLn'></tfoot>

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