SMS PDU 格式 - 如何提取消息部分

ano*_*mer 5 java sms gsm pdu

如何从 SMS PDU 中提取消息?

我需要从 SMS PDU 获取消息。当我使用一些在线服务时,它们运行良好。例如,这里 - http://www.diafaan.com/sms-tutorials/gsm-modem-tutorial/online-sms-pdu-decoder/ - 来自 PDU 的消息0791448720003023240DD0E474D81C0EBB010000111011315214000BE474D81C0EBB5DE3771Bdiafaan.com

我发现了一些 SMS PDU Java 实现来进行PDU->Text转换,但它们似乎没有按我的预期工作,因为我没有从整个 PDU 中提取消息部分(换句话说,我没有剪切服务信息 - From,SMSC. ..) - 那么我怎样才能在 Java 上做到这一点呢?或者只是一个算法也会有很大的帮助。谢谢!

ano*_*mer 4

最后我使用了 SMSLib 库:

            //String resultMessage = ...
            Pdu pdu = new PduParser().parsePdu(resultMessage);
            byte[] bytes = pdu.getUserDataAsBytes();
            String decodedMessage;
            int dataCodingScheme = pdu.getDataCodingScheme();
            if (dataCodingScheme == PduUtils.DCS_ENCODING_7BIT) {
                decodedMessage = PduUtils.decode7bitEncoding(null, bytes);
            } else if (dataCodingScheme == PduUtils.DCS_ENCODING_8BIT) {
                decodedMessage = PduUtils.decode8bitEncoding(null, bytes);
            } else if (dataCodingScheme == PduUtils.DCS_ENCODING_UCS2) {
                decodedMessage = PduUtils.decodeUcs2Encoding(null, bytes);
            } else {
                log.error("Unknown DataCodingScheme!");
                ...
            }
Run Code Online (Sandbox Code Playgroud)

  • 它可以做得更好 - “PduUtils”中有一个“getDecodedText”方法 (3认同)