Firebase云消息传递 - invalidRegistration(php)

时间:2017-08-29 08:20:16

标签: php android http firebase-cloud-messaging

我在向Firebase项目中的主题发送推送通知时遇到问题。如果我运行PHP脚本,我给了我错误' invalidRegistration'

php脚本:

DELETE FROM     t_old a
using           t_prop b 
where           a.company_id IS NOT DISTINCT FROM b.company_id
and             b.company_id is null;

我的应用程序中 FCM实例ID 服务的代码;

<?php


$topic = "/topics/info";
$fcm_server_url = "https://fcm.googleapis.com/fcm/send";

$title = utf8_encode("AleXoTroN");
$content_text = utf8_encode("AleXoTroN");
$color_code = utf8_encode("#2baa7f");


$httpheader = array('Content_Type:application/json', 'Authorization:key=***');
$msg = array('to' => $topic, 'data' => array('title' => $title, 'content_text' => $content_text, 'color' => $color_code));

$curl_connection = curl_init();
curl_setopt($curl_connection, CURLOPT_URL, $fcm_server_url);
curl_setopt($curl_connection, CURLOPT_POST, true);
curl_setopt($curl_connection, CURLOPT_HTTPHEADER, $httpheader);
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $msg);
$answerFromServer = curl_exec($curl_connection);
curl_close($curl_connection);

echo "Server:<br/>".$answerFromServer;

?>

1 个答案:

答案 0 :(得分:1)

你没有对你的消息进行json编码。

在将其发送给FCM之前使用json_encode($msg)