我正在从我的应用服务器发送通知。 当我发送英文文本时没关系,但是当我发送阿拉伯文字时,我得到了这个:
这是我的代码:
<?php
require "connection.php";
$title=$_POST['title'];
$message=$_POST['message'];
function send_notification ($tokens, $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data'=>$message
);
$headers = array(
'Authorization:key =MY_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;
}
$sql = " Select fcm_token From fcm_info";
$result = mysqli_query($con,$sql);
$tokens = array();
if(mysqli_num_rows($result) > 0 ){
while ($row = mysqli_fetch_assoc($result)) {
$tokens[] = $row["fcm_token"];
}
}
mysqli_close($con);
$message = array("message" => $message,"title" => $title);
$message_status = send_notification($tokens, $message);
echo $message_status;
?>
我尝试将Content-type更新为: &#39; Content-Type:application / json; charset-utf8&#39; 并将JSON_UNESCAPED_UNICODE添加到json_encode()
但仍然得到如上图所示的结果.. 请提出任何建议。
SOLUTION:
使用以下方法将htmlentities解码为字符:
html_entity_decode(json_encode($字段));
答案 0 :(得分:0)
用以下内容替换开口:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Send Notification</title>
</head>
它告诉浏览器使用UTF-8进行编码。