<?php
function send_notification ($tokens, $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key =
API_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("127.0.0.1","root","ybm123","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" => "메시지 입력 구간");
$message_status = send_notification($tokens, $message);
echo $message_status;
?>
PHP에서 FCM을 통해서 안드로이드로 메시지 전송할 때 영어랑 숫자는 전송이 잘 되는데 한글 전송시
JSON_PARSING_ERROR: Unexpected token END OF FILE at position 0.
에러가 나옵니다. 받는 쪽하고 보내는 쪽에서 UTF-8을 사용해야 되는거 같은데 어떻게 설정을 바꾸는지 모르겠습니다. 다른 방법으로 한글 전송 방법이 있으면 알려주시면 감사하겠습니다.