javaunicodesmppjsmpp

Send Unicode SMS via SMPP


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?


Solution

  • 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.