我正在尝试使用 php 从 clickatell 短信提供商发送阿拉伯语文本,但我所能发送的只是乱码文本。我用于测试的文本是“غثس هوس”。
我曾尝试使用 iconv 将消息文本编码为 Windows-1256,1250 和 ISO-8859-6 格式,但每次它只会发送乱码文本。
任何人都可以给我一些我缺少的东西的指示吗?
提前致谢
最佳答案
好的,这是给后来走上这条路的人的。找到解决方案 here 保留 Esailija 答案中的代码
<?php
$text = "غثس هفس خن";
$arr = unpack('H*hex', iconv('UTF-8', 'UCS-2BE', $text));
$message = strtoupper($arr['hex']);
$username = '';
$password = '';
$API_ID = '';
$to = '';
$url = "http://api.clickatell.com/http/auth?user=$username&password=$password&api_id=$API_ID";
$ret = file($url);
$sess = explode(":",$ret[0]);
if ($sess[0] == "OK") {
$sess_id = trim($sess[1]);
$url = "http://api.clickatell.com/http/sendmsg?session_id=$sess_id&to=$to&text=$message&unicode=1";
$ret = file($url);
$send = explode(":",$ret[0]);
if ($send[0] == "ID") {
echo "success - message ID: ". $send[1];
} else {
echo "send message failed";
}
} else {
echo "Authentication failure: ". $ret[0];
}
关于php - Clickatell 阿拉伯语文本出现乱码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13839466/