2

我读了这篇文章来发送 Unicode 短信,但我想知道如何阅读 utf8 信息?

通过 GSM 调制解调器使用 AT 命令在 C# 中发送 Unicode 消息(例如波斯语和阿拉伯语)

我发送此命令但收到的消息文本类似于:

 AT+CMGL="ALL"

  +CMGL: 1,"REC READ","97563937625","","2013/08/28 00:53:30+18"
     0041006A006D0064006A00740020

我阅读短信的命令:

          ExecCommand(port,"AT", 300, "No phone connected");

            ExecCommand(port,"AT+CSCS=\"UCS2\"\n", 300, "No phone connected");

            ExecCommand(port,"AT+CMGF=1", 300, "Failed to set message format.");

            ExecCommand(port,"AT+CPMS=\"MT\"", 300, "Failed to select message storage.");          

            string input = ExecCommand(port, "AT+CMGL=\"ALL\"", 5000, "Failed to read the messages.");
4

2 回答 2

2

我认为 GSM 不支持 UTF8。来自http://en.wikipedia.org/wiki/Short_Message_Service

短消息可以使用多种字母表进行编码:默认的 GSM 7 位字母表、8 位数据字母表和 16 位 UCS-2 字母表

并来自http://en.wikipedia.org/wiki/GSM_03.40

中文、韩文或日文的消息必须使用 UTF-16 字符编码进行编码

数据编码方案 (TP-DCS) 字段主要包含有关消息编码的信息。GSM 仅识别文本消息的 2 种编码和二进制消息的 1 种编码:

GSM 7 位默认字母表(也包括使用国家语言转换表)

UCS-2

8位数据

在同一段中,他们说 2012 年引入了一种新的基于国家的编码(国家语言转换表)。但这仍然不是 UTF-8。

于 2013-08-28T06:55:46.317 回答
2
    private string decoder(string value)
    {
        Regex lettersOnly = new Regex("^[0-9]|[A-Z]$");
        if ((value.Length % 4 == 0) && lettersOnly.Match(value).Success)
        {
            string data = FromHex(value);

            return data;
        }
        else
            return value;
    }      

    public static string FromHex(string hex)
    {
        short[] raw = new short[hex.Length / 4];
        for (int i = 0; i < raw.Length; i++)
        {
            raw[i] = Convert.ToInt16(hex.Substring(i * 4, 4), 16);
        }
        string s = "";
        //wtf encoding utf32 ride ahmagh kos sher pas mide
        foreach (var item in raw)
        {
            s += char.ConvertFromUtf32(item).ToString();
        }
        return s;
    }
于 2015-02-03T21:52:49.080 回答