我可能會嘗試從使用php的clickatell短信提供程序發送阿拉伯文本,但是我所能發送的所有文本都是亂碼文本。我用於測試的文本是「غثسهفس」。Clickatell阿拉伯文文本得到了亂碼
我已經嘗試使用iconv編碼消息文本到Windows-1256,1250和ISO-8859-6格式,但每次只發送亂碼文本。
任何人都可以請給我一些指針,我缺少什麼?提前
我可能會嘗試從使用php的clickatell短信提供程序發送阿拉伯文本,但是我所能發送的所有文本都是亂碼文本。我用於測試的文本是「غثسهفس」。Clickatell阿拉伯文文本得到了亂碼
我已經嘗試使用iconv編碼消息文本到Windows-1256,1250和ISO-8859-6格式,但每次只發送亂碼文本。
任何人都可以請給我一些指針,我缺少什麼?提前
好吧,這是這條道路上後什麼人。發現從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];
}
相當不錯的發現,它需要特設的十六進制編碼,而不是標準的百分比編碼。 – Esailija
由於基於this,默認爲GSM,但是你也可以選擇UCS2。
所以:
<?php
//Make sure the PHP source file is physically
//saved in utf-8
$text = rawurlencode(iconv("UTF-8", "UCS-2", "غثس هفس "));
$url = "http://api.clickatell.com/http/auth?user=username&password=password&api_id=API_ID&encoding=UCS2";
$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=$text&encoding=UCS2";
$ret = file($url);
$send = explode(":",$ret[0]);
if ($send[0] == "ID") {
echo "successnmessage ID: ". $send[1];
} else {
echo "send message failed";
}
} else {
echo "Authentication failure: ". $ret[0];
}
我重寫的Clickate代碼爲好vtiger 6,以便它可以容納UTF-8擴展的字符的溶液here 護代碼。我用土耳其語。我使用下面的代碼進行轉換。我希望你能端口。
/**
* Function to handle UTF-8 Check and conversion
* @author Nuri Unver
*
*/
public function smstxtcode($data){
$mb_hex = '';
$utf = 0;
for($i = 0 ; $i<mb_strlen($data,'UTF-8') ; $i++){
$c = mb_substr($data,$i,1,'UTF-8');
$o = unpack('N',mb_convert_encoding($c,'UCS-4BE','UTF-8'));
$hx = sprintf('%04X',$o[1]);
$utf += intval(substr($hx,0,2));
$mb_hex .= $hx;
}
if ($utf>0)
{
$return=$mb_hex;
$utf=1;
}
else
{
$return=utf8_decode($data);
$utf=0;
}
return array($utf,$return);
}
你用你的消息調用這個函數。你得到的響應是一個數組,表示根據消息以及要發送的文本發送unicode或普通文本。如果沒有擴展字符,它只會以unicode = 0的純文本形式發送它以保存字符。如果消息包含擴展字符,它會將消息轉換爲十六進制代碼並將其作爲unicode發送。
此代碼只是進行計算。您需要實現自己的代碼以將其移植到您的系統。爲了演示這是我用好vtiger代碼來提取數據併發送消息:
/**
* Function to handle SMS Send operation
* @param <String> $message
* @param <Mixed> $toNumbers One or Array of numbers
*/
public function send($message, $toNumbers) {
if(!is_array($toNumbers)) {
$toNumbers = array($toNumbers);
}
$params = $this->prepareParameters();
$smsarray = $this->smstxtcode($message);
$params['text'] = $smsarray[1];
$params['unicode'] = $smsarray[0];
$params['to'] = implode(',', $toNumbers);
$serviceURL = $this->getServiceURL(self::SERVICE_SEND);
不錯,謝謝你的信息:) – pinaki
簡短的回答:你需要做兩件事情:
一)將您的阿拉伯語消息:
$ data = iconv(「UTF-8」,「UCS-2BE」,$ data); $ data = bin2hex($ data);
使用得到的字符串作爲郵件文本
b)如果通過HTTP發送API,包括Unicode參數:
&的unicode = 1
是否的Clickate文檔指定任何編碼?這也可能因語言/運營商和/或接聽電話而異。 – deceze
我沒有看到clickatell文檔中的任何特定的編碼細節。現在我已經用完了關於下一步嘗試的想法:) – pinaki