带有unicode字符的deliver_sm请求
我正在尝试开发一个 SMSC 模拟器,它将发送 Deliver_sm 到网关。现在我可以成功向网关发送 Deliver_sm 请求。但是这次我需要发送 Unicode 字符作为按摩正文。每当我尝试发送 unicode 字符时,网关无法识别它。它显示为无效关键字按摩。现在我猜我的 16 位按摩编码不正确。这是我的代码。如果可能,请给我更正的代码。
try {
ByteBuffer ed = new ByteBuffer();
DeliverSM request = new DeliverSM();
private String message="text";
private SimulatorPDUProcessor proc;
request.setEsmClass((byte)Data.SM_UDH_GSM); //Set UDHI Flag Data.SM_UDH_GSM=0×40
request.setDataCoding((byte) ((byte) 0*04));
ed.appendByte((byte) 6); // UDH Length
ed.appendByte((byte) ((byte) 0*04)); // IE Identifier
ed.appendByte((byte) 4); // IE Data Length
ed.appendByte((byte) 00) ; //Reference Number 1st Octet
ed.appendByte((byte) 00) ; //Reference Number 2nd Octet
try {
ed.appendString(message, Data.ENC_UTF16_BE);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setShortMessage(message,Data.ENC_UTF16);
request.setSourceAddr("sourceAdd");
request.setDestAddr("919865851257");
proc.serverRequest(request);
System.out.println("Message sent.");
try {
generateResult(sourceAdd,"sent");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (WrongLengthOfStringException e) {
System.out.println("Message sending failed ");
event.write(e, "");
}
I am trying to develop a smsc simulator which will send deliver_sm to gateway. Now i am able to send deliver_sm request to gateway successfully.But this time i need to send Unicode character as a massage body.When ever i am trying to send unicode characters the gateway is not recognizing it .It is showing as invalid keyword as massage. Now i guess my 16-bit encoding of the massage is not correct.Here is my code.Please give me corrected code if possible.
try {
ByteBuffer ed = new ByteBuffer();
DeliverSM request = new DeliverSM();
private String message="text";
private SimulatorPDUProcessor proc;
request.setEsmClass((byte)Data.SM_UDH_GSM); //Set UDHI Flag Data.SM_UDH_GSM=0×40
request.setDataCoding((byte) ((byte) 0*04));
ed.appendByte((byte) 6); // UDH Length
ed.appendByte((byte) ((byte) 0*04)); // IE Identifier
ed.appendByte((byte) 4); // IE Data Length
ed.appendByte((byte) 00) ; //Reference Number 1st Octet
ed.appendByte((byte) 00) ; //Reference Number 2nd Octet
try {
ed.appendString(message, Data.ENC_UTF16_BE);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setShortMessage(message,Data.ENC_UTF16);
request.setSourceAddr("sourceAdd");
request.setDestAddr("919865851257");
proc.serverRequest(request);
System.out.println("Message sent.");
try {
generateResult(sourceAdd,"sent");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (WrongLengthOfStringException e) {
System.out.println("Message sending failed ");
event.write(e, "");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要设置
You need set
尝试改用 UTF-8 编码。可能您需要首先对数据进行实际编码。
免责声明:我不知道
deliver_sm
API,但 SMS 确实使用 UTF-8。 <- 我纠正了,USC-16 用于 不适合的消息7 位和 8 位编码。Try to use UTF-8 encoding instead. Possibly you will need to actually encode your data first.
Disclaimer: I have no idea of the
deliver_sm
API, but SMS does use UTF-8. <- I stand corrected, USC-16 is used for messages that don't fit 7-bit and 8-bit encodings.