开发者

deliver_sm request with unicode charecter

开发者 https://www.devze.com 2023-04-05 12:52 出处:网络
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 char

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, "");
}


You need set

submitSM.setDataCoding((byte)(0x08)); // UCS-2
submitSM.setShortMessage( MessageStr, "UTF-16" );


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消