English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
SMS largo sin verificar, si está interesado, puede probar
Reescrito según el método de python
/** * Análisis de PDU de SMS * * * @param pduPayload * @return */ public static String retrieveSMSInfo(byte[] pduPayload) throws UnsupportedEncodingException { int startPos = 3; //#Dirección del remitente 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]; //#Nº BIT 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; //#¿El contenido del sms incluye información de encabezado de protocolo?, 0 no incluye, 1 Incluye (sms largo, sms push) int TP_VPF = (TP_Header >> 3) & 3; //#¿Incluye el byte del período de validez?, 0 no incluye, otros incluye // #00 indica sin período de validez, TP-VP se configura como 00. // #10indica el formato relativo, TP-VP uso1byte. // #01indica el formato incremental, TP-VP uso7byte. // #11indica el formato absoluto, TP-VP uso7byte int TP_MMS = (TP_Header >> 2) & 1;//# TP-MMS(TP-Más-Mensaje-to-Send):1 No hay más mensajes para enviar desde el centro de mensajería startPos = startPos + 3; //#号码 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”表示使用7位编码,设置为“02”使用8位编码,设置为“08”使用UCS2编码。 startPos = startPos + 2; if (TP_VPF == 2) { startPos = startPos + 1; } else if (TP_VPF == 1 || TP_VPF == 3) { startPos = startPos + 7; } //# 长短信:内容前面需要增加6个字段 //# 1、 字节一:包头长度,固定填写0x05; //# 2、 字节二:包头类型标识,固定填写0x00,表示长短信; //# 3、 字节三:子包长度,固定填写0x03,表示后面三个字节的长度; //# 4、 字节四到字节六:包内容: //# a) 字节四:长消息参考号,每个SP给每个用户发送的每条参考号都应该不同,可以从0开始,每次加1,最大255,便于同一个终端对同一个SP的消息的不同的长短信进行识别; //# b) 字节五:本条长消息的的总消息数,从1到255,一般取值应该大于2; //# c) 字节六:本条消息在长消息中的位置或序号,从1到255,第一条为1,第二条为2,最后一条等于第四字节的值。 //# 例子: //# 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) { //#长短信--未验证 可能需要转无符号 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位编码--已验证 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 --Verificado, se puede analizar normalmente 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; }
Lo que se menciona anteriormente es una explicación integral de la decodificación de SMS PDU de Java que el editor le presenta a todos, esperamos que sea útil para ustedes. Si tienen alguna pregunta, déjenos un mensaje y el editor les responderá a tiempo. También agradezco mucho el apoyo de todos a la página web de呐喊教程!
Declaración: El contenido de este artículo se obtiene de la red, pertenece a los propietarios originales, el contenido se contribuye y sube por los usuarios de Internet de manera autónoma, este sitio no posee los derechos de propiedad, no se ha realizado una edición humana y no asume ninguna responsabilidad legal relacionada. Si encuentra contenido sospechoso de infracción de derechos de autor, por favor envíe un correo electrónico a: notice#oldtoolbag.com (al enviar un correo electrónico, reemplace # con @ para denunciar, y proporcione evidencia relevante. Una vez confirmado, este sitio eliminará inmediatamente el contenido sospechoso de infracción de derechos de autor.)