2011-06-08 228 views
3

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

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); 

在此之后,我收到带有中文符号的消息。哪里不对?

+0

问题解决了。问题是HexUtil没有正确地为unicode转换字符串。对于此使用代码从这里: http://en.wikipedia.org/wiki/List_of_Unicode_characters – totali 2011-06-08 10:06:37

+0

你可以请你自己回答这个问题,然后接受答案?另外,如果他们解决了您的问题,则需要接受以前问题的答案。 – Zecas 2012-05-16 15:37:28

回答

2

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

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

获取字节:

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

此样品给你发送短信与此charset UCS2。

3

应该

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

HexUtil是这里的红鲱鱼。