Php FCM推送Notif脚本
我按照教程使用Android Studio进行Firebase云消息推送通知。 这是图图: 因此,我的push_notification.php出现了一个问题:Php FCM推送Notif脚本,php,android,Php,Android,我按照教程使用Android Studio进行Firebase云消息推送通知。 这是图图: 因此,我的push_notification.php出现了一个问题: <?php function send_notification ($tokens, $message) { $url = 'https://fcm.googleapis.com/fcm/send'; $fields = array( 'registrat
<?php
function send_notification ($tokens, $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key = AAAALXOnumg:APA91bGI7Qfrl0XVX52KOfjfKfzFcezbD6mwwIti7oswMAvGn3Z9Q1toxJ9IiXiXRFc_vB21NRnwNaI-vYPxcEMO5JH53RrfAtnjxyA5fzaiwONSnLY987ephLapy0ijTyW9VLwwoPBJSq',
'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","toor","gcm");
$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;
?>
当我在我的浏览器上执行它时,结果是:[HTTP/1.0 500内部服务器错误1ms]
我的数据库id是正确的,身份验证密钥也是正确的,那么问题是从哪里来的呢
$conn = mysqli_connect("localhost","root","toor","gcm");
请检查这些详细信息(主机、数据库名、用户名、密码)。检查此链接以确认您通过提供fcm令牌获得了推送,因此在设置中,有服务器密钥和旧服务器密钥,我尝试了这两种密钥