PHP 코드/웹 브라우저를 사용하여 FCM을 보내려고했습니다.PHP를 사용하여 FCM 알림을 보내는 방법은 무엇입니까?
- FCM 알림은 가상 장치에 나타납니다 : 나는 그것이 PHP 웹 브라우저를 사용하여 보낼 때
는 그러나 문제이다.
- 실제 전화 장치에는 FCM 알림이 표시되지 않습니다.
그리고 파이어베이스 콘솔을 사용하여 실제 전화 장치로만 FCM 알림을 보낼 수 있습니다.
누군가 도울 수 있습니까? 코드는 다음과 같습니다.
<?php
require "init.php";
global $con;
if(isset($_POST['Submit'])){
$message = $_POST['message'];
$title = $_POST['title'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "AAAA2gV_U_I:APA91bHA28EUGmA3BrDXFInGy-snx8wW6eZ_RUE7EtOyM99pbfrVZU_ME-FU0O9_dUxYpM30OYF8KWYlixod_PfwbgLNoovzdkdJ4F-30vY8X_tBz0CMrajCIAgbNVRfw203YdRGli";
$sql = "SELECT fcm_token FROM fcm_table";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_row($result);
$key = $row[0];
$headers = array('Authorization:key=' .$server_key, 'Content-Type:application/json');
$fields = array('to' => $key, 'notification' => array('title' => $title, 'body'=> $message));
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$result = curl_exec($curl_session);
curl_close($curl_session);
mysqli_close($con);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>FCM Notification</title>
</head>
<body>
<form action='fcm_notification.php' method="POST">
<table>
<tr>
<td>Title : </td>
<td><input type="text" name="title" required="required" /></td>
</tr>
<tr>
<td>Message : </td>
<td><input type="text" name="message" required="required" /></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Send notification"></td>
</tr>
</table>
</form>
</body>
</html>
감사합니다.
기기별로 보면 Android가 맞습니까? –
예. 안드로이드 장치 – Jamilah
에뮬레이터에 대한 등록 토큰을 제대로 얻을 수 있습니까? 간단한 cURL 응답을 사용하여 메시지를 보내려고했지만 아직 메시지를받지 못했는지 확인하십시오. –