📄 cmpp2deliver.java
字号:
package com.khan.sms.cmpp2;
import com.khan.sms.MsgID;
import java.io.*;
import com.khan.util.SocketCommon;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Cmpp2Deliver extends Cmpp2Data {
public MsgID Msg_ID = null;
public String Dest_ID = "";
public String Service_ID = "";
public byte Tp_PID = 0x00;
public byte Tp_UDHI = 0x00;
public byte Msg_FMT = 0x00;
public String Src_Terminal = "";
public byte IsReport = 0x00;
public byte Msg_Length = 0x00;
public String Msg_Content = "";
public Registered_Delivery Statu_Report = null;
byte[] Reserved = null;
public Cmpp2Deliver(byte[] data) {
if (data.length < 12)
throw new ExceptionInInitializerError("数据包长度小于12字节,包错误!");
int ioffset = 0;
TotalLen = SocketCommon.getDWord(data, ioffset);
if (data.length < 12)
throw new ExceptionInInitializerError("数据包头Total_Len字段标示长度小于12字节,包头错误!");
ioffset += 4;
CommandID = SocketCommon.getDWord(data, ioffset);
ioffset += 4;
SeqID = SocketCommon.getDWord(data, ioffset);
ioffset += 4;
Data = new byte[TotalLen - ioffset];
System.arraycopy(data, ioffset, Data, 0, TotalLen - ioffset);
//MsgID.PrintDataHex(data);
//MsgID.PrintDataHex(Data);
}
public byte[] encodeCmpp() {
return null;
}
public Cmpp2Data decodeCmpp() {
int ioffset=0;
byte[] tmp = new byte[8] ;
System.arraycopy(Data, ioffset, tmp, 0, tmp.length);
ioffset += tmp.length;
Msg_ID = new MsgID(tmp);
tmp = new byte[21];
System.arraycopy(Data, ioffset, tmp, 0, tmp.length);
ioffset += tmp.length;
//MsgID.PrintDataHex(tmp);
Dest_ID = new String(tmp).trim();
if( Dest_ID.indexOf(0x00) > -1)
Dest_ID =Dest_ID.substring(0, Dest_ID.indexOf(0x00));
tmp = new byte[10];
System.arraycopy(Data, ioffset, tmp, 0, tmp.length);
ioffset += tmp.length;
Service_ID = new String(tmp).trim();
if( Service_ID.indexOf(0x00) > -1)
Service_ID =Service_ID.substring(0, Service_ID.indexOf(0x00));
Tp_PID = Data[ioffset++];
Tp_UDHI = Data[ioffset++];
Msg_FMT = Data[ioffset++];
tmp = new byte[21];
System.arraycopy(Data, ioffset, tmp, 0, tmp.length);
ioffset += tmp.length;
Src_Terminal = new String(tmp).trim();
if( Src_Terminal.indexOf(0x00) > -1)
Src_Terminal =Src_Terminal.substring(0, Src_Terminal.indexOf(0x00));
IsReport = Data[ioffset++];
Msg_Length = Data[ioffset++];
tmp = new byte[Msg_Length];
System.arraycopy(Data, ioffset, tmp, 0, tmp.length);
ioffset += tmp.length;
switch (IsReport) {
case 0x00: { //非状态报告
try {
switch (Msg_FMT) {
case 8: Msg_Content = new String(tmp, "unicodebigunmarked").trim();
break;
case 15:Msg_Content = new String(tmp, "GB2312").trim();
break;
default: Msg_Content = new String(tmp).trim();
break;
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if( Msg_Content.indexOf(0x00) > -1)
Msg_Content =Msg_Content.substring(0, Msg_Content.indexOf(0x00));
}
break;
case 0x01: Statu_Report = new Registered_Delivery(tmp);//状态报告
break;
default:
break;
}
Reserved = new byte[8];
if (ioffset + 8 <= Data.length );
System.arraycopy(Data, ioffset, Reserved, 0, Reserved.length);
ioffset += Reserved.length;
return this;
}
public String toString() {
return "CMPP2_DELIVER:Msg_ID="+Msg_ID
+ ",Dest_ID="+Dest_ID
+ ",Service_ID="+Service_ID
+ ",Tp_PID="+Tp_PID
+ ",Tp_UDHI="+Tp_UDHI
+ ",Msg_FMT="+Msg_FMT
+ ",Src_Terminal="+Src_Terminal
+ ",IsReport="+IsReport
+ ",Msg_Length="+Msg_Length
+ ",Msg_Content="+( IsReport == 0x00 ? Msg_Content : Statu_Report );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -