我已经用PHP编写了一个API,该API将接收Firebase令牌,并将推送通知发送到Android设备。
我已经测试了Android辅助代码,它使用令牌从Firebase控制台接收示例通知。但是,当我尝试从PHP api发送邮件时,它没有发送通知。
这是我的PHP API。
// send firebase push notifcaiton
$url = 'https://fcm.googleapis.com/fcm/send';
$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
$fields = array (
'registration_ids' => array (
$pnsToken
),
'data' => array (
"message" => $message,
"guestId" => $guestId,
"guestEntryId" => $guestEntryId,
"guestName" => $guestName,
"guestAddress" => $guestAddress,
"reason" => $reason
)
);
//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));
}
curl_close($ch);
我不知道为什么它没有从PHP api发送推送通知。
这是我收到的fcm错误:
"fcmResult": "{\"multicast_id\":7084003691931660410,\"success\":0,\"failure\":1,\"canonical_ids\":0,\"results\":[{\"error\":\"NotRegistered\"}]}",