简体   繁体   English

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

[英]SMS PDU format - how to extract message part

How can I extract a message from SMS PDU? 如何从SMS PDU中提取消息?

I need to take a message from SMS PDU. 我需要从SMS PDU接收消息。 When I use some online services, they work fine. 当我使用一些在线服务时,它们工作正常。 For example, here - http://www.diafaan.com/sms-tutorials/gsm-modem-tutorial/online-sms-pdu-decoder/ - message from PDU 0791448720003023240DD0E474D81C0EBB010000111011315214000BE474D81C0EBB5DE3771B is diafaan.com . 例如,这里 - http://www.diafaan.com/sms-tutorials/gsm-modem-tutorial/online-sms-pdu-decoder/ - 来自PDU 0791448720003023240DD0E474D81C0EBB010000111011315214000BE474D81C0EBB5DE3771B消息是diafaan.com

I found some SMS PDU Java implementations to do PDU->Text conversion, but it seems they didn't work as I expect because I don't extract message part from whole PDU (in another words I don't cut the service information - From, SMSC...) - so how can I do this on Java? 我发现了一些SMS PDU Java实现来进行PDU->Text转换,但似乎它们没有按照我的预期工作,因为我没有从整个PDU中提取消息部分(换句话说,我没有删除服务信息 -从,SMSC ...) - 那么我怎么能在Java上做到这一点? Or just an algorithm would be a great help too. 或者只是一个算法也将是一个很大的帮助。 Thanks! 谢谢!

Finally I used SMSLib library: 最后我使用了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!");
                ...
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM