【问题标题】:Notification not show in Device tray by using Firebase notification使用 Firebase 通知未在设备托盘中显示通知
【发布时间】:2017-05-18 11:40:59
【问题描述】:

我使用cordova-plugin-fcm 插件为我的 IONIC 应用程序发送通知。我需要在我的应用程序中发送通知中的图像,所以我在我的 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;
    }
    ?>`

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

【问题讨论】:

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


【解决方案1】:

它解决了我的问题。如果有人遇到同样的问题,

请点击链接:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多