如何从 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 中提取消息部分(换句话说,我没有剪切服务信息 - From,SMSC. ..) - 那么我怎样才能在 Java 上做到这一点呢?或者只是一个算法也会有很大的帮助。谢谢!
最后我使用了 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)
| 归档时间: |
|
| 查看次数: |
3049 次 |
| 最近记录: |