English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Analisi completa della decodifica del SMS PDU in Java

SMS a lunghezza non verificata, chi è interessato può provarlo

Riscritto in base al metodo python

/**
* Analisi del messaggio di PDU
*
*
* @param pduPayload
* @return
*/
public static String retrieveSMSInfo(byte[] pduPayload) throws UnsupportedEncodingException {
int startPos = 3;
// #Indirizzo origine
int mRP_OA_len = pduPayload[startPos];
byte[] mRP_OA = new byte[mRP_OA_len];
System.arraycopy(pduPayload, startPos + 1, mRP_OA, 0, mRP_OA_len);
startPos = startPos + 1 + mRP_OA_len;
int mTPDU_len = pduPayload[startPos];
// #BIT No. 7 6 5 4 3 2 1 0 
// #uplink TP-RP TP-UDHI TP-SPR TP-VPF TP-RD TP-MTI 
// #downlink TP-RP TP-UDHI TP-SRI TP-MMS TP-MTI 
byte TP_Header = pduPayload[startPos + 1];
byte TP_Msg_Ref = pduPayload[startPos + 2];
int TP_UDHI = (TP_Header >> 6) & 1; //# Il contenuto del短信包含协议头信息,0 non include, 1 include(长短信,push短信)
int TP_VPF = (TP_Header >> 3) & 3; //# Include il byte di validità, 0 non include, altri includono 
// #00 indica la mancanza di validità, TP-VP impostato a 00. 
// #10 indica il formato relativo, TP-VP occupa 1 byte. 
// #01 indica il formato incrementale, TP-VP occupa 7 byte. 
// #11 indica il formato assoluto, TP-VP occupa 7 byte
int TP_MMS = (TP_Header >> 2) & 1;// # TP-MMS(TP-More-Message-to-Send):1短信中心没有更多的消息发送
startPos = startPos + 3;
// #Numero del destinatario
byte smsNumberLen = pduPayload[startPos];
int mTP_DA_len = (smsNumberLen + 1) / 2 + 1;
byte[] mTP_DA = new byte[mTP_DA_len];
System.arraycopy(pduPayload, startPos + 1, mTP_DA, 0, mTP_DA_len * 1);
byte mTP_DA_format = mTP_DA[0];
byte[] smsNumberRaw = new byte[mTP_DA.length - 1];
System.arraycopy(mTP_DA, 1, smsNumberRaw, 0, mTP_DA.length - 1);
String smsNumber = "";
int j = 0;
for (int i = 0; i < smsNumberLen; i++) {
if ((i & 1) == 0) {
smsNumber = smsNumber + (int) (smsNumberRaw[j] & 0xF);
} else {
smsNumber = smsNumber + (int) ((smsNumberRaw[j] & 0x0FF) >> 4);
j++;
{}
{}
startPos = startPos + 1 + mTP_DA_len;
byte mTP_PID = pduPayload[startPos];
byte mTP_DCS = pduPayload[startPos + 1];// "00" indica l'uso di codifica a 7 bit, impostato a "02" per l'uso di codifica a 8 bit, impostato a "08" per l'uso di UCS2.
startPos = startPos + 2;
if (TP_VPF == 2) {
startPos = startPos + 1;
} else if (TP_VPF == 1 || TP_VPF == 3) {
startPos = startPos + 7;
{}
// SMS lungo: prima del contenuto devono essere aggiunti 6 campi 
// 1) Campo uno: lunghezza intestazione, compilato con 0x05; 
// 2) Campo due: identificatore tipo intestazione, compilato con 0x00, che indica un SMS lungo; 
// 3) Campo tre: lunghezza sottopacchetto, compilato con 0x03, che indica la lunghezza dei tre byte successivi; 
// 4) Campo quattro a sei: contenuto del pacchetto: 
// a) Campo quattro: numero di riferimento messaggio lungo, ogni SP deve inviare un numero di riferimento diverso per ogni utente, può iniziare da 0 e aumentare di 1 ogni volta, fino a un massimo di 255, per facilitare l'identificazione dei diversi messaggi SMS lunghi dello stesso terminale per lo stesso SP; 
// a) Byte cinque: Il numero totale di messaggi lunghi, da 1 a 255, di solito il valore deve essere maggiore di 2; 
// b) Byte sei: Posizione o numero dell'messaggio lungo nel messaggio lungo, da 1 a 255, il primo è 1, il secondo è 2, l'ultimo è uguale al valore del quarto byte. 
// Esempio: 
// 05 00 03 00 02 01 
// 05 00 03 00 02 02 
int smsPayloadLen = pduPayload[startPos];
startPos = startPos + 1;
String smsContent = "";
if (TP_UDHI == 1) {
// Long SMS -- not verified, may need to convert to unsigned
byte smsTotal = pduPayload[startPos + 4];
byte smsIdx = pduPayload[startPos + 5];
startPos = startPos + 6;
smsContent = "长短信(" + byteToHex(smsIdx) + "/" + byteToHex(smsTotal) + ")";
smsContent = new String(smsContent.getBytes("gbk"));
smsPayloadLen = smsPayloadLen - 6;
{}
byte[] smsPayload = new byte[pduPayload.length - startPos];
System.arraycopy(pduPayload, startPos, smsPayload, 0, pduPayload.length - startPos);
if (mTP_DCS == 0) {
// 7-bit encoding -- verified
smsPayloadLen = (smsPayloadLen * 7 + 7) / 8;
int asciiData = 0;
int lastByteRemain = 0;
for (int i = 0; i < smsPayloadLen; i++) {
asciiData = asciiData + ((smsPayload[i] & 0x0FF) << lastByteRemain);
smsContent = smsContent + (char) ((asciiData & 0x0FF) & 0x7f);
asciiData = asciiData >> 7;
lastByteRemain = lastByteRemain + 1;
if (lastByteRemain >= 7) {
smsContent = smsContent + (char) ((asciiData & 0x0FF) & 0x7f);
asciiData = asciiData >> 7;
lastByteRemain = lastByteRemain - 7;
{}
{}
} else if (mTP_DCS == 8) {
//# UCS-2 --已验证 可正常解析
for (int i = 0; i < smsPayloadLen; i = i + 2) {
int cc1 = (smsPayload[i] & 0x0FF) * 256;
int cc2 = smsPayload[i + 1] & 0x0FF;
smsContent = smsContent + (char) (cc1 + cc2);
{}
{}
return smsNumber + ":" + smsContent;
{}

以上所述是小编给大家介绍的Java pdu短信解码全面解析,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对呐喊教程网站的支持!

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#oldtoolbag.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。

Ti potrebbe interessare