无法在多条短信中使用 Open-Smpp 库发送特殊字符

Can't send special characters using Open-Smpp library in multi sms

我正在使用 open-smpp 库与 SMSC 通信。 我可以同时发送单条和多条短信,但是我遇到了特殊字符 (šđžć) 的问题,在发送多条消息 (sendMultiSMS) 时会显示为“?”。

我在 https://en.wikipedia.org/wiki/Short_Message_Peer-to-Peer 上读到,short_message 字段中的文本必须匹配 data_coding。

PSB,两种方法的代码部分。 根据上面的 wiki 资源,我定义了代表 data_coding 的变量 DATA_CODING 并且我尝试像这样在 short_message 中编码文本: submitSM.setShortMessage(message.getMessage(), Data.ENC_UTF16); - 单个消息 ed.appendString(messageAux, Data.ENC_UTF16); - 多消息

所以对于单条消息,波纹管组合很好(DATA_CODING =(字节)0x08 和数据。ENC_UTF16),字符正常,但对于多条短信,特殊字符如下'?'.

我尝试了所有组合,例如:
DATA_CODING =(字节)0x01 和数据。ENC_UTF16
DATA_CODING =(字节)0x08 和数据。ENC_UTF16
DATA_CODING =(字节)0x01 和数据。ENC_UTF8
DATA_CODING =(字节)0x08 和数据。ENC_UTF8
等,但没有成功。

**private static final byte DATA_CODING = (byte) 0x08;**

public void sendSMS(XMessage message) throws SmppException
{ 
    .
    .
    .
    SubmitSM submitSM = new SubmitSM();
    setScheduleDate(message, submitSM);
    submitSM.setProtocolId(PROTOCOL_ID);
    **submitSM.setDataCoding(DATA_CODING);**
    submitSM.setSourceAddr(mSrcAddress);
    submitSM.setDestAddr(mDestAddress);
    submitSM.setSequenceNumber(message.getSequence());
    **submitSM.setShortMessage(message.getMessage(), Data.ENC_UTF16);**
    SubmitSMResp submitSMResp = mSession.submit(submitSM);
}

public void sendMultiSMS(XMessage message) throws SmppException
{
    .
    .
    .
    submitSMMulti = new SubmitSM();
    submitSMMulti.setProtocolId(PROTOCOL_ID);
    **submitSMMulti.setDataCoding(DATA_CODING);**
    setScheduleDate(message, submitSMMulti);
    submitSMMulti.setSourceAddr(mSrcAddress);
    submitSMMulti.setDestAddr(mDestAddress);
    submitSMMulti.setEsmClass((byte)0x40);

    messageArray = XSMSProcessUtil.getMultiMessages(message.getMessage(), numSegments);
    SubmitSMResp submitSMResp = null;
    for(int count = 0; count < messageArray.length; count++)
    {
        submitSMMulti.setSequenceNumber(message.getSequence() + count);
        messageAux = messageArray[count];
        ByteBuffer ed = new ByteBuffer();
        ed.appendByte((byte)5);
        ed.appendByte((byte)0x00);
        ed.appendByte((byte)3);
        ed.appendByte((byte)message.getSequence());
        ed.appendByte((byte)numSegments);
        ed.appendByte((byte)(count +1));
        **ed.appendString(messageAux, Data.ENC_UTF16);**
        submitSMMulti.setShortMessageData(ed);
        submitSMResp = mSession.submit(submitSMMulti);
    }
}

我使用此信息找到了解决方案 URL.
这是简短的解释:

The GSM character encoding uses 7 bits to represent each character, non-Latin-based alphabet languages usually use phones supporting Unicode. The specific character encoding utilized by these phones is usually UTF-16 or UCS-2. Both UTF-16 and UCS-2 use 16 bits to represent each character. Standard SMS messages have a maximum payload of 140 bytes (1120 bits). For Unicode phones, which use a 16-bit character encoding, this allows a maximum of 70 characters per standard SMS message. UDH takes up 6 bytes (48 bits) of a normal SMS message payload. So each individual concatenated SMS message can hold 67 characters: 1072 bits / (16 bits/character) = 67 characters

我需要将消息的最大大小从 153 降低到 67 并使用 DATA_CODING = (byte) 0x08 和 Data.ENC_UTF16.