【问题标题】:SMS PDU format - how to extract message partSMS PDU 格式 - 如何提取消息部分
【发布时间】:2015-11-17 13:18:58
【问题描述】:

如何从 SMS PDU 中提取消息?

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

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

【问题讨论】:

    标签: java sms gsm pdu


    【解决方案1】:

    最后我使用了 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!");
                    ...
                }
    

    【讨论】:

    • 它可以做得更好——在PduUtils中有一个getDecodedText方法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    • 2018-01-27
    • 1970-01-01
    • 1970-01-01
    • 2012-04-19
    相关资源
    最近更新 更多