我正在尝试使用Firebase在Angular5和Codeigniter中发送网络推送通知。在初始化Firebase之后,我可以获得要发送推送通知的设备令牌。但是当我试图在后端使用curl发送时,它总是显示以下错误:
{
"multicast_id":8778443463170192739,
"success":0,
"failure":1,
"canonical_ids":0,
"results":[
{
"error":"MismatchSenderId"
}
]
}
在后端 API 请求中,我正在使用“Server key”:
"AAAA8q7RESs:APA91bFrOrzgvTb0yQTqTF6huozIvgi_5xf1lY8qv5kyoDViuBYnVFr3Qfxg3DZHN_e7-AqWBIvRlQvPJkgZtxKIpCYs_aUUiYHOKuKLLJvzxAENjKmF4mCQJb94tJV8J-vBgnv0FPPY"
。但始终显示相同的错误。我的后端 PHP 代码是:public function sendpushnotification() {
$request = json_decode(file_get_contents('php://input'),true);
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => array($request['token']),
'data' => array( "message" => "Hello this is test push notification" ),
);
$headers = array(
'Authorization: key=AAAA8q7RESs:APA91bFrOrzgvTb0yQTqTF6huozIvgi_5xf1lY8qv5kyoDViuBYnVFr3Qfxg3DZHN_e7-AqWBIvRlQvPJkgZtxKIpCYs_aUUiYHOKuKLLJvzxAENjKmF4mCQJb94tJV8J-vBgnv0FPPY',
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
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_POSTFIELDS, json_encode( $fields ) );
// Avoids problem with https certificate
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
// Execute post
$result = curl_exec($ch);
curl_close($ch);
echo json_encode($result);
}
有人能帮我吗?我花了很多时间但没有找到解决方案。
我有一个问题。设备令牌/设备 ID 是否取决于消息发送者 ID?
registration_ids
是什么?在registration_ids
中传递$id
的数据是什么? - Sofyan Thayf