SMS PDU 格式 - 如何提取消息部分
SMS PDU format - how to extract message part
如何从 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!");
...
}
如何从 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!");
...
}