使用Firebase通知

时间:2017-01-04 08:41:12

标签: php cordova firebase ionic-framework firebase-cloud-messaging

我使用cordova-plugin-fcm插件为我的IONIC App发送通知。我需要在我的应用程序中发送通知中的图像,因此我在PHP代码中使用 notificationOptions

如果我的设备托盘中没有显示 notificationOptions 通知,但是当我尝试在我的PHP代码中实现 notificationOptions 时,通知不会显示在我的设备托盘中但我得到在我的控制台日志中:

{"notificationOptions":"{\"largeIcon\":\"https:\\/\\/avatars2.githubusercontent.com\\/u\\/1174345?v=3&s=96\",
\"smallIcon\":\"mipmap\\/icon\",
\"id\":4,\"text\":\"Test message\",
\"title\":\"Title test\",
\"autoCancel\":true}",
"dataValuesToGetWhenClickedOn":"111","wasTapped":false}

PHP代码:

    `<?php
    $msg = array
    (
        "dataValuesToGetWhenClickedOn" => 111,
        'notificationOptions' => array(
            'title' => "Title test",
            'id' => 4,
            'text' => "Test message",
            'smallIcon' => "mipmap/icon",
            'largeIcon'   => "https://avatars2.githubusercontent.com/u/1174345?v=3&s=96",
            'autoCancel'  => true
        )
    );
    //print_r($msg); // exit();
    $fields = array
    (
        'to'  => "c5clRYgB1vo:APA91bGTlyTQur2S9b5iksc16-T0KzwV9Ein0n0RSafgDBdgxVKjhGQU0BLPmvnJVShCKDhlpeJCpHthmRglQcegT",
        'data'          => $msg
    );
    $data =  json_encode($fields);
    $ch = curl_init("https://fcm.googleapis.com/fcm/send");
    $header = array('Accept: application/json','Content-Type: application/json',
    "Authorization: key=---Api Key---");
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    //curl_exec($ch);
    if(curl_exec($ch) === false)
    {
        echo 'Curl error: ' . curl_error($ch);
    }
    else
    {
        $result = curl_exec($ch );
        curl_close( $ch );
        echo $result;
    }
    ?>`

请帮帮我。我想知道我做错了什么。

1 个答案:

答案 0 :(得分:0)

它解决了我的问题。如果任何人面临同样的问题,

请点击链接:

https://github.com/andrehtissot/cordova-plugin-firebase-extended-notification-app-example