通过 SMPP 发送 Unicode 短信

发布于 2024-11-14 20:13:53 字数 837 浏览 5 评论 0原文

我想通过 SMPP(JSMPP 库)发送带有 unicode 字符的短信。我知道数据编码必须是 8 &短信长度为 70 个字符。但是当我尝试这个时,我收到带有中文符号的短信。这是我的代码:

ESMClass esmClass = new ESMClass();
GeneralDataCoding coding = new GeneralDataCoding(8)
String text = "üöğçşə ƏIÖĞŞÇÜ";
String p = HexUtil.convertStringToHexString(text);
byte[] textByte = HexUtil.convertHexStringToBytes(p);

String messageId = session.submitShortMessage("CMT",TypeOfNumber.INTERNATIONAL,
                   NumberingPlanIndicator.UNKNOWN,"1111", TypeOfNumber.INTERNATIONAL,
                   NumberingPlanIndicator.UNKNOWN, "phone_number", esmClass,
                   (byte) 0, (byte) 1, timeFormatter.format(new Date()), null,
                   new RegisteredDelivery(SMSCDeliveryReceipt.DEFAULT),
                   (byte) 0, coding, (byte) 0, textByte);

之后我收到带有中文符号的消息。怎么了?

I want to send sms iwth unicode characters via SMPP (JSMPP library). I know that Data Encoding must be 8 for it & sms length is 70 character. But when I try this, I get sms with Chinese symbols. Here is my code:

ESMClass esmClass = new ESMClass();
GeneralDataCoding coding = new GeneralDataCoding(8)
String text = "üöğçşə ƏIÖĞŞÇÜ";
String p = HexUtil.convertStringToHexString(text);
byte[] textByte = HexUtil.convertHexStringToBytes(p);

String messageId = session.submitShortMessage("CMT",TypeOfNumber.INTERNATIONAL,
                   NumberingPlanIndicator.UNKNOWN,"1111", TypeOfNumber.INTERNATIONAL,
                   NumberingPlanIndicator.UNKNOWN, "phone_number", esmClass,
                   (byte) 0, (byte) 1, timeFormatter.format(new Date()), null,
                   new RegisteredDelivery(SMSCDeliveryReceipt.DEFAULT),
                   (byte) 0, coding, (byte) 0, textByte);

After this I get message with Chinese symbols. What is wrong?

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

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

发布评论

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

评论(2

蓝天 2024-11-21 20:13:53

应该是

byte[] textByte = text.getBytes("UTF-16BE");

HexUtil 在这里是一个转移注意力的事情。

It should be

byte[] textByte = text.getBytes("UTF-16BE");

HexUtil is a red herring here.

赤濁 2024-11-21 20:13:53

不要将字符串转换为十六进制字符串 &使用此数据编码而不是:

GeneralDataCoding dataCoding = new GeneralDataCoding(false, true, MessageClass.CLASS1, Alphabet.ALPHA_UCS2);

获取字节:

byte[] textByte = text.getBytes("UTF-16BE");

此示例为您提供使用此字符集 UCS2 发送短信。

Don't convert string to hex string & use this data coding instead of that:

GeneralDataCoding dataCoding = new GeneralDataCoding(false, true, MessageClass.CLASS1, Alphabet.ALPHA_UCS2);

Get bytes:

byte[] textByte = text.getBytes("UTF-16BE");

This sample gives you send sms with this charset UCS2.

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