FCM推送通知不通过PHP脚本发送

时间:2016-12-06 06:50:45

标签: php firebase firebase-cloud-messaging

我尝试过发送FCM通知:

function sendFCM($title, $mess, $tk) {
    //var_dump($title);
    //var_dump($tk);
    //exit;
$senderId = 'AAAAqYuVeLs:APA91bEXhJpHUJoHeoPvujhCKopbj5FO3xlLjppgUvbVEBwvXgXz1e6C9ZH93X0iEGfr21Gcu0qf2Mf0g4nHM7RT1kL77pG19wih6YgU6IFmZsWkpJQ2ws_aOKFS70tyXC74KYtV5KdJehM6dr77O0EVfn1SghbuFQ';
$url = 'https://fcm.googleapis.com/fcm/send';

    $fields = array (
            'to' => 'kr0xgwFrcHTTt7X6fsiz0zZ7Y2C2',
            'data' => array (
                    "title" => $title,
                    "body" => $mess
            )
    );
    $payload = json_encode ( $fields );

    $headers = array (
            'Authorization:key='.$senderId,
            'Content-Type:application/json'
    );

        $ch = curl_init ();
        curl_setopt ( $ch, CURLOPT_URL, $url );
        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_IPRESOLVE, CURL_IPRESOLVE_V4 );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $payload );
    enter code here
        $result = curl_exec ( $ch );
        echo json_encode($result);



                // if ($result === FALSE) {
                //  die('FCM Send Error: ' . curl_error($ch));
                //  $json = array("status" => 0, "msg" => "Not Send!");
                //   echo json_encode($json);
                // }else{
                //  $json = array("status" => 1, "msg" => "Send!");
                //   echo json_encode($json);
                // }
                curl_close ( $ch );
}

但我得到了这样的答复:

{"multicast_id":7532299715078966238,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1481002800387502%00000000f9fd7ecd"}]}[]

不发送实际消息。我该怎么办?它在Firebase控制台发送消息历史记录中甚至不可见。

0 个答案:

没有答案