當(dāng)我嘗試通過 cURL 請(qǐng)求發(fā)送推送通知時(shí),來(lái)自服務(wù)器的響應(yīng)表明我已成功,但設(shè)備上未收到消息。我已經(jīng)嘗試過使用多播和單個(gè)收件人有效負(fù)載。這是我的PHP代碼:<?php//API URL of FCM$url = 'https://fcm.googleapis.com/fcm/send';/*api_key available in:Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key*/ $api_key = 'API_KEY';$device_id = 'eE5U0IQEyTo:APA91bGplai6Bf5ko1hlW5y0oLb0WIa5JytpcuZ7B9lbIay8PNfPv2i1HMUqg1hDtPQqvhy4KLIZgyEh0BHHkfJtdX7E0Ftm-OaN23VahOoWAzjNP2QK8Se7PCibhooVG71jMPmzTHqd';$fields = array ( 'registration_ids' => array ( $device_id ), 'data' => array ( "title" => "test from server", "body" => "test lorem ipsum" ));//header includes Content type and api key$headers = array('Content-Type:application/json','Authorization:key='.$api_key);$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_VERIFYHOST, 0);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));$result = curl_exec($ch);if ($result === FALSE) {die('FCM Send Error: ' . curl_error($ch));}else{ curl_close($ch); print_r($result); return $result;}?> 這是我在運(yùn)行此代碼時(shí)得到的響應(yīng):{ "multicast_id": 1338828245860499776, "success": 1, "failure": 0, "canonical_ids": 0, "results": [{ "message_id": "0:1578484075615332%52ec0605f9fd7ecd" }]}
3 回答

桃花長(zhǎng)相依
TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊
完美答案@Chetan,不會(huì)顯示“數(shù)據(jù)”通知,但會(huì)顯示“通知”。
所以你的數(shù)組應(yīng)該是:
$fields = array (
'registration_ids' => array (
$device_id
),
'notification' => array (
"title" => "test from server",
"body" => "test lorem ipsum"
)
);

冉冉說(shuō)
TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個(gè)贊
將“數(shù)據(jù)”重命名為“通知”
如果“通知”對(duì)象不存在,設(shè)備將不會(huì)在抽屜中顯示通知。
“數(shù)據(jù)”由應(yīng)用程序解釋
“通知”由設(shè)備解釋..
您可以單獨(dú)使用兩者,但如果要顯示通知,則需要“通知”對(duì)象。
- 3 回答
- 0 關(guān)注
- 332 瀏覽
添加回答
舉報(bào)
0/150
提交
取消