菜鸟教程小白 发表于 2022-12-11 19:36:44

php - Firebase Api Key 仅适用于 iOS


                                            <p><p>我想在 php 中使用 firebase 发送推送通知。我的代码适用于 android,但不适用于 ios 设备。</p>

<p>我在这两种情况下都取得了成功:1。</p>

<p><strong>这是我的代码</strong></p>

<pre><code>&lt;?php
$path_to_firebase_cm = &#39;https://fcm.googleapis.com/fcm/send&#39;;
$fields = array(&#39;registration_ids&#39; =&gt; $token,
                        &#39;data&#39; =&gt;array(&#39;title&#39;=&gt;&#39;Title&#39;,
                                       &#39;body&#39;=&gt;$message[&#39;message&#39;],
                                       &#39;image&#39;=&gt;$imagepath,
                                       &#39;priority&#39;=&gt;&#39;high&#39;
                                       )
                        );

      $headers = array(
            &#39;Authorization:key=AIzaSyBiOCXbU7roG59_**********vWa4Xc&#39; ,
            &#39;Content-Type:application/json&#39;
      );      
      $ch = curl_init();

      curl_setopt($ch, CURLOPT_URL, $path_to_firebase_cm);
      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, json_encode($fields));

      $result = curl_exec($ch);
      curl_close($ch);
      return $result;
?&gt;
</code></pre>

<p><strong> react 是</strong> </p>

<pre><code>stdClass Object
(
    =&gt; 8.5168949472892E+18
    =&gt; 1
    =&gt; 0
    =&gt; 0
    =&gt; Array
      (
             =&gt; stdClass Object
                (
                   =&gt; 0:1493801065120413%2d69fd2bf9fd7ecd
                )

      )

)
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>从 iphone 中删除应用程序并重新安装,之后您将获得新的 firebasetoken 尝试再次发送推送。
首先从 php 端调试它,他们正在发送更新的设备 token 上的推送。 </p></p>
                                   
                                                <p style="font-size: 20px;">关于php - Firebase Api Key 仅适用于 iOS,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/43755402/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/43755402/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: php - Firebase Api Key 仅适用于 iOS