菜鸟教程小白 发表于 2022-12-11 19:22:13

php - Firebase 云消息传递 PHP 集成发送推送通知


                                            <p><p>我在 PHP 中集成了 FCM 推送通知功能。现在,通知工作正常,但 <code>badge</code> 号码不起作用。</p>

<p>我添加了 <code>badge = 1</code>,但每次都没有显示 1 而不是递增角标(Badge)编号。我想发送自动递增的角标(Badge)编号。</p>

<p>请看我的php文件代码:</p>

<pre><code> &lt;?php

    $ch = curl_init(&#34;https://fcm.googleapis.com/fcm/send&#34;);

    //The device token.
    $token = &#34;DEVICE_TOKEN_HERE&#34;; //token here

    //Title of the Notification.
    $title = &#34;Title Notification&#34;;

    //Body of the Notification.
    $body = &#34;This is the body show Notification&#34;;

    //Creating the notification array.
    $notification = array(&#39;title&#39; =&gt;$title, &#39;text&#39; =&gt; $body, &#39;sound&#39; =&gt; &#39;default&#39;, &#39;badge&#39; =&gt; &#39;1&#39;);

    //This array contains, the token and the notification. The &#39;to&#39; attribute stores the token.
    $arrayToSend = array(&#39;to&#39; =&gt; $token, &#39;notification&#39; =&gt; $notification,&#39;priority&#39;=&gt;&#39;high&#39;);

    //Generating JSON encoded string form the above array.
    $json = json_encode($arrayToSend);
    //Setup headers:
    $headers = array();
    $headers[] = &#39;Content-Type: application/json&#39;;
    $headers[] = &#39;Authorization: key=API_KEY_HERE&#39;; // key here

    //Setup curl, add headers and post parameters.
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, &#34;POST&#34;);                                                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);      

    //Send the request
    $response = curl_exec($ch);

    //Close request
    curl_close($ch);
    return $response;

?&gt;
</code></pre>

<p>请帮帮我!!!谢谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>这是预期的行为。 iOS 不会自动增加您发送的角标(Badge)。在发送之前,您必须在服务器端确定角标(Badge)的应有值。</p>

<p>另见 <a href="https://stackoverflow.com/q/1942605/4625829" rel="noreferrer noopener nofollow">post</a> .</p></p>
                                   
                                                <p style="font-size: 20px;">关于php - Firebase 云消息传递 PHP 集成发送推送通知,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/43085546/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/43085546/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: php - Firebase 云消息传递 PHP 集成发送推送通知