【发布时间】: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;
}
?>`
请帮助我。我想知道我做错了什么。
【问题讨论】:
-
嗨。你能指出你从哪里得到
notificationOptions参数吗? -
我可以从cordova-plugin-firebase-extended-notification获取
notificationOptions参数
标签: php cordova firebase ionic-framework firebase-cloud-messaging