Firebase云消息传递php脚本返回无效注册
我在网上研究并尝试了各种方法来解决这个问题,但它并没有解决问题。这就是我在php脚本中遇到的错误Firebase云消息传递php脚本返回无效注册,php,android,firebase,push-notification,google-cloud-messaging,Php,Android,Firebase,Push Notification,Google Cloud Messaging,我在网上研究并尝试了各种方法来解决这个问题,但它并没有解决问题。这就是我在php脚本中遇到的错误 {"multicast_id":6412971464416964071,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]} 我使用的是授权密钥,即服务器密钥 push_notification.php <?php function send_notification (
{"multicast_id":6412971464416964071,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
我使用的是授权密钥,即服务器密钥
push_notification.php
<?php
function send_notification ($tokens, $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key = ********',
'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;
}
$conn = mysqli_connect("localhost","root","","fcm");
$sql = "Select Token From users";
$result = mysqli_query($conn,$sql);
$tokens = array();
if(mysqli_num_rows($result) > 0 ){
while ($row = mysqli_fetch_assoc($result)) {
$tokens[] = $row["Token"];
}
}
mysqli_close($conn);
$message = array("message" => " FCM PUSH NOTIFICATION TEST MESSAGE");
$message_status = send_notification($tokens, $message);
echo $message_status;
?>
我的数据库中有一个有效的令牌。但是,它显示无效注册。如何修复此问题?如果注册无效 检查传递给服务器的注册令牌的格式。确保它与客户端应用程序通过注册Firebase通知收到的注册令牌匹配。不要截断或添加其他字符 资料来源: 如果建议的操作对您不起作用,以下是您可以做的其他事情:
- 。它提到需要验证ID令牌的完整性和真实性,并从中检索
uid
- 您可能还想在这里检查这个建议的解决方案,其中指出,如果您从db检索令牌,那么请确保列的数据类型为text或很长的varchar,如200