1
私がしなければならないのは、私はアンドロイドアプリからこのスクリプトを起動し、デバイスの所有者に通知を受け取ります。私はブログ、stackoverflowsしかし、誰肯定的な結果をたくさん読みましたphpを使用してfirebaseのクラウドメッセージングを起動できません
<?php
$db_name = "testdb";
$mysql_username = "root";
$mysql_password = "";
$server_name = "localhost";
function send_notification ($tokens , $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key = AIzaSyBAYIZohaZPXBEGqktPh8YEfMlmuYnuCOk',
'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
($server_name,$mysql_username,$mysql_password,$db_name);
$sql = "select `token` from `user_token`;";
$result = mysqli_query($conn,$sql);
$token = array();
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
$token[] = $row["token"];
}
}
mysqli_close($conn);
$message = array('message' => "FCM MESSAGE");
$message_status = send_notification($token , $message);
echo $message_status;
?>
:
は、ここに私のコードです。
ありがとうございます。