[英]Unable to send push notifications from Firebase
I want to send push notifications from the web to Android devices but it responses "invalid registration".我想从网络向 Android 设备发送推送通知,但它响应“无效注册”。
I tried to send from firebase console but is does not include the message data我试图从 firebase 控制台发送,但不包括消息数据
<?php
//$con= new mysqli("localhost","root","","doctor_appointment");
include('connection.php');
$sql = " Select * From token_register where id = 1";
$result = mysqli_query($connection_to_db,$sql);
$tokens = array();
if(mysqli_num_rows($result) > 0 ){
while ($row = mysqli_fetch_assoc($result)) {
$tokens[] = $row["token"];
// $token = $row["token"];
// echo "$token";
}
}
mysqli_close($connection_to_db);
function send_notification ($tokens, $message)
{
// define( 'API_ACCESS_KEY', 'AIzaSyDt2xaRw4XGzghfxAMRFVy-I8ZeacBDbHA');
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => array($tokens),
'data' => array( "message" => $message ),
);
$headers = array(
'Authorization:key = AIzaSyDdHTdvqzN8lrUqhZKOeuiR2d9cETRBhNw',
'Content-Type: application/json'
);
$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('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
$message = array("message" => " FCM PUSH NOTIFICATION TEST MESSAGE");
$message_status = send_notification($tokens, $message);
echo $message_status;
?>
I expected to be我预计会
{
"multicast_id":7068539387015084016,
"success":1,
"failure":0,
"results":[
{"RegistrationSuccess"}
]
}
but responds但回应
{
"multicast_id":7068539387015084016,
"success":0,
"failure":1,
"canonical_ids":0,
"results":[
{
"error":"InvalidRegistration"
}
]
}
As per your given logs, Registration id is wrong.根据您给定的日志,注册 ID 是错误的。
Try to send it through Rest API tool.尝试通过 Rest API 工具发送。 Eg Postman.比如邮递员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.