OGeek|极客世界-中国程序员成长平台

标题: php - Firebase Api Key 仅适用于 iOS [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:36
标题: php - Firebase Api Key 仅适用于 iOS

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

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

这是我的代码

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

        $headers = array(
            'Authorization:key=AIzaSyBiOCXbU7roG59_**********vWa4Xc' ,
            'Content-Type:application/json'
        );      
        $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;
?>

react 是

stdClass Object
(
    [multicast_id] => 8.5168949472892E+18
    [success] => 1
    [failure] => 0
    [canonical_ids] => 0
    [results] => Array
        (
            [0] => stdClass Object
                (
                    [message_id] => 0:1493801065120413%2d69fd2bf9fd7ecd
                )

        )

)



Best Answer-推荐答案


从 iphone 中删除应用程序并重新安装,之后您将获得新的 firebase token 尝试再次发送推送。 首先从 php 端调试它,他们正在发送更新的设备 token 上的推送。

关于php - Firebase Api Key 仅适用于 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43755402/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4