【问题标题】:Sending SMS using PHP API with unicode message使用带有 unicode 消息的 PHP API 发送 SMS
【发布时间】:2012-07-28 22:59:41
【问题描述】:

我尝试通过 RoutoMessaging PHP API 发送短信。我阅读了我能找到的所有文档和示例。 他们有用于以 unicode 格式发送 SMS 的 PHP 示例脚本:

<?php  
// include RoutoSMS class  
include("RoutoTelecomSMS.php");  
// creating object  
$sms = new RoutoTelecomSMS;  
// setting login parameters  
$sms->SetUssms->SetOwnNum("44792838383838");  
$sms->SetType("unicode"); 
// get values entered from FORM  
$sms->SetNumber($number);  
$message="04220432043E04580435002004370435043B0435043D04350020043E0
44704380020044104430020043C04380020043F0430043C043504420020043F043E
043C044304420438043B0435002E002E002E"; 
$sms->SetMessage($message);  
// send SMS and print result  
$smsresult = $sms->Send();  
print $smsresult;  
?> 

我不明白的是如何将文本从提交的字符串转换为包含在 $message 中所需的代码。 任何人都可以建议将文本转换为 $message 的功能吗? 我目前使用 PHP 5.3.3 版。

【问题讨论】:

  • 如果你的号码实际上是(那个数字减去额外的 38 个),那么我建议删除它。
  • AFAIK SMS 使用一种非常古老的编码,称为 PDU。如果您的库没有在内部将 Unicode 转换为 PDU,则您必须自己进行。

标签: php string function unicode


【解决方案1】:

您发送的消息是 Cryllic 文本。应该是塞尔维亚语吧。它读作“Твоје зелене очи су ми памет помутиле...”

解码

header('Content-Type: text/html; charset=utf-8');
$str = "04220432043E04580435002004370435043B0435043D04350020043E044704380020044104430020043C04380020043F0430043C043504420020043F043E043C044304420438043B0435002E002E002E";
foreach(str_split($str, 4) as $char) echo "&#x{$char};";

这就是您对消息进行编码的方式

$string = "Твоје зелене очи су ми памет помутиле...";
$string = mb_convert_encoding($string, 'UCS-2', 'utf8');
for($i =0; $i < strlen($string); $i++)
    echo strtoupper(bin2hex($string[$i]));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多