如何发送包含Unicode字符的批量SMS?

时间:2019-05-10 11:28:36

标签: c# bulksms

我正在使用批量SMS应用程序。它工作正常,但是当我发送带有Unicode字符的消息时,手机将其显示为 ????????

我正在使用一个包含URL,数字和消息正文的XML文件。

我的代码是这样:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "POST";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byteArray = Encoding.UTF8.GetBytes(xml);
string text = Encoding.UTF8.GetString(byteArray);
request.ContentType = "text/xml; encoding='utf-8'";

request.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome / 41.0.2228.0 Safari / 537.36";
request.Accept = "text/xml,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = (HttpWebResponse)request.GetResponse();

if (response.ContentLength > 0)
{
    Console.WriteLine(((HttpWebResponse)response).StatusDescription);
    dataStream = response.GetResponseStream();

    using (StreamReader reader = new StreamReader(dataStream))
    {
        returnValue = reader.ReadToEnd();
    }
}
else
{
    returnValue = "ERROR" + " " + "No Response From Jasmin";
}

Console.WriteLine(returnValue);
dataStream.Close();
response.Close();

希望你们给我一个解决方案?

2 个答案:

答案 0 :(得分:1)

它实际上取决于提供者。如果他们允许或支持Unicode SMS。像SMS一样,它支持Unicode SMS,如果启用其转码功能,则它们将计数1 SMS = 70个字符。

Transcoding Option

您可以在以下位置检查其易于使用的 SMS API集成 for C#:https://sms.to/sms-api#/

答案 1 :(得分:0)

SMS将UCS-2字符集用于Unicode字符(每个字符16位,因此最大长度减半)。如果源字符串不兼容ASCII,则需要转换为UCS-2。有关操作方法,请参见Convert to UCS2