编码 £ 通过网关发送的短信无法正常工作

发布于 2024-07-15 08:36:43 字数 928 浏览 5 评论 0原文

我在使用名为 Cymba 的提供商发送的 SMS 消息时遇到问题。

基本上,我按照 URL 编码的规范将消息发布给他们。

然而,当消息发送到我的手机时,£ 前面会出现一个 A,即 £A

现在,C# 字符串默认为 Unicode,因此我切换到 ASCII 编码,£ 则显示为 ?。

我尝试从 Unicode 和 ASCII 版本开始将消息字符串转换为十六进制(通过此网关,您也可以以十六进制形式提交消息)。 然而,同样的行为也会发生。

我怀疑这与字符串编码有关,因为 SMS 支持 7 位编码格式:GSM 03.38

我还怀疑,如果我通过 Unicode 发送,我只会收到 70 或 140 个字符的消息,而不是标准的 160 个字符。

我短信发送相当新,因此任何帮助或建议将不胜感激。

所以问题是,如何将我的 C# 字符串转换为这种格式?

更新:看起来网关是有问题的,而不是我的代码,因为我尝试用 7 位等效的十六进制值替换有问题的 £,但这也不起作用。 请参阅下面的我的测试代码,这可能会在将来帮助其他人:

byte pound = 0xA3;
byte GSMPound = 0x01;
string hexxedMsg = "";
System.Text.UnicodeEncoding encoder = new System.Text.UnicodeEncoding();
byte[] msgBytes = encoder.GetBytes(message);

foreach (byte byt in msgBytes)
{
    if(byt == pound)
        hexxedMsg += GSMPound.ToString("X");
    else
        hexxedMsg += byt.ToString("X2"); ;
}

I'm having trouble with an SMS message I am sending using a provider called Cymba.

Basically I'm posting the message over to them as per their specifications URL encoded.

However when the message is sent to my phone the £ appears with an A in front i.e. £A

Now C# strings are Unicode by default, so I switched to ASCII encoding and the £ comes over as ?.

I've tried converting the message string to hex starting form the Unicode and ASCII versions (as via this gateway you an also submit the message as hex). However the same behaviour occurs.

I suspect it is something to do with the string encoding as SMS supports a 7bit encoding format: GSM 03.38

I suspect also that if I send over Unicode I'll only get a 70 or 140 char message instead of the standard 160.

I'm quite new to SMS sending so any help or advice will be appreciated.

So the question is, how can I get my C# strings into this format?

Update: Looks like the Gateway is the one with the problem not my code as I tried replacing the offending £ with the 7bit equivalent hex value and this did not work either. See below for my test code which may help others in future:

byte pound = 0xA3;
byte GSMPound = 0x01;
string hexxedMsg = "";
System.Text.UnicodeEncoding encoder = new System.Text.UnicodeEncoding();
byte[] msgBytes = encoder.GetBytes(message);

foreach (byte byt in msgBytes)
{
    if(byt == pound)
        hexxedMsg += GSMPound.ToString("X");
    else
        hexxedMsg += byt.ToString("X2"); ;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余罪 2024-07-22 08:36:43

有一个 GSM 03.38 到 Unicode 映射表,表明 £ 应该被编码为 0x01,这样你就可以尝试(只需对它进行硬编码一次尝试)。 但是,您确实应该与网关运营商检查所有这些内容。 网关是否真的希望您在 URL 编码的 GSM 03.38 中发布? 如果是这样,那么该映射表可能是可行的方法 - 您可能需要编写自己的实现来从字符串映射到字节(完全实现 System.Text.Encoding 会有点过分)。 不过,我会先尝试使用硬编码消息。

There's a GSM 03.38 to Unicode mapping table available which suggests that £ should be encoded as 0x01 so you could try that (just hard-coding it for a single attempt). However, you should really check all of this with the gateway operator. Is the gateway genuinely expecting you to post in URL-encoded GSM 03.38? If so, that mapping table is probably the way to go - you may need to write your own implementation to map from a string to bytes (fully implementing System.Text.Encoding would be overkill). I'd try it with a hard-coded message first though.

蓝梦月影 2024-07-22 08:36:43

此页面包含有关"7 位默认字母表"

最简单的解决方案可能是创建一个字典,将 GSM 03.38 标准编码的 Unicode 代码点(大约 140 个字形)映射为 1 或 2 个字节(0x27、0x?? 对需要 2 个字节)。

完成后(取决于您的提供商),您可能还必须将 8 位字节压缩为 7 位序列流。 这里有一个视觉示例

在您实现所有这些之后(并且喝了几杯啤酒!),您可能希望将其转换为 System.Text.Encoding 实现。


您可能还想查看 CodeProject 上的 PDUDecoder 进行反向操作。 还有一个在线版本。

This page contains info on the "7-bit default alphabet".

The simplest solution may be to create a Dictionary that maps the Unicode code points encoded by the GSM 03.38 standard (approximately 140 glyphs) into 1 or 2 bytes (2 bytes are needed for the 0x27, 0x?? pairs).

Once that's done (depending on your provider) you may also have to squeeze the 8-bit bytes into a stream of 7-bit sequences. There's a visual sample here.

And after you've achieved all of that (and had a couple of beers!) you might want to turn it into a System.Text.Encoding implementation.


You might also want to have a look at PDUDecoder on CodeProject for the reverse operation. There's an online version too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文