Java 使用unicode字符传递\u sm请求
我正在尝试开发一个smsc模拟器,它将发送sm到网关。现在我能够成功地将deliver_sm请求发送到网关。但这次我需要将Unicode字符作为消息正文发送。当我尝试发送Unicode字符时,网关无法识别它。它显示为无效关键字,如消息。现在我想我的16位按摩编码是不正确的。这是我的代码。如果可能的话,请给我正确的代码Java 使用unicode字符传递\u sm请求,java,sms,unicode-string,smpp,Java,Sms,Unicode String,Smpp,我正在尝试开发一个smsc模拟器,它将发送sm到网关。现在我能够成功地将deliver_sm请求发送到网关。但这次我需要将Unicode字符作为消息正文发送。当我尝试发送Unicode字符时,网关无法识别它。它显示为无效关键字,如消息。现在我想我的16位按摩编码是不正确的。这是我的代码。如果可能的话,请给我正确的代码 try { ByteBuffer ed = new ByteBuffer(); DeliverSM request = new DeliverSM();
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, "");
}
尝试改用UTF-8编码。您可能需要首先对数据进行编码 免责声明:我不知道
deliver\u sm
API,但SMS确实使用UTF-8 你需要一套
submitSM.setDataCoding((byte)(0x08)); // UCS-2
submitSM.setShortMessage( MessageStr, "UTF-16" );
我试过了。我试着在这个mannar中转换印地语文本::try{String=”हिंदि भाषा "; byte[]utf8=string.getBytes(“UTF-8”);string=newstring(utf8,“UTF-8”);System.out.println(string);}catch(UnsupportedEncodingException e){}但当我试图编译此代码时,它显示如下::某些字符无法使用cp1252字符编码进行映射……不,SMS使用UTF-16(数据编码=8)