📄 cmpp.java
字号:
this.parseSubmitRespPack(dataInStream);
break;
case CMPP.CMPP_ACTIVE_TEST:
break;
case CMPP.CMPP_ACTIVE_TEST_RESP:
break;
case CMPP.CMPP_QUERY:
break;
case CMPP.CMPP_QUERY_RESP:
break;
}
}
catch(Exception e){
throw e;
}
}
/**
* 解析CMPP_CONNECT_RESP信息包
* 7.4.1.2 CMPP_CONNECT_RESP消息定义(ISMG -> SP)
* @param dataInputStream
*/
private void parseConnectRespPack( DataInputStream dataInputStream ) throws Exception
{
try{
if(this.Version ==32) this.Status = dataInputStream.readByte();
if(this.Version ==48) this.Status = dataInputStream.readInt();
this.AuthenticatorISMG = this.readString(dataInputStream,16);
this.Version = dataInputStream.readByte();
}catch(Exception e){
System.out.println("[CMPP]CMPP.parseConnectRespPack error " + e);
throw e;
}
}
/**
* 解析CMPP_DELIVER信息包
* 8.4.5.1 CMPP_DELIVER消息定义(ISMG->SP)
* @param dataInputStream
*/
private void parseDeliverPack( DataInputStream dataInputStream ) throws Exception
{
try{
this.Msg_Id = dataInputStream.readLong();
//目的号码。SP的服务代码,一般4--6位,或者是前缀为服务代码的长号码;该号码是手机用户短消息的被叫号码。
this.Dest_terminal_Id = this.readString(dataInputStream,21);
this.Service_Id = this.readString(dataInputStream,10);
this.TP_pid = dataInputStream.readByte();
this.TP_udhi = dataInputStream.readByte();
this.Msg_Fmt = dataInputStream.readByte();
if(Version == 48){ //CMPP3.0
this.Src_terminal_Id = this.readString(dataInputStream,32);
this.Src_terminal_type = dataInputStream.readByte();
}
else if(Version == 32){ //CMPP2.0
this.Src_terminal_Id = this.readString(dataInputStream, 21);
}
this.Registered_Delivery = dataInputStream.readByte();
this.Msg_Length = dataInputStream.readByte();
byte[] msgContent = null;
//当为状态报告时候
if(Registered_Delivery == 1){
this.Report_Msg_Id = dataInputStream.readLong();
this.Report_Stat = this.readString(dataInputStream,7);
this.Report_Submit_time = this.readString(dataInputStream,10);
this.Report_Done_time = this.readString(dataInputStream,10);
this.Report_Dest_terminal_Id = this.readString(dataInputStream,32);
this.Report_SMSC_sequence = 1;//dataInputStream.readInt();
//this.Msg_Content = readDeliverString(dataInputStream,this.Msg_Length-13,this.Msg_Fmt);
Debug.outInfo("\n[CMPPMaster]"+PublicFunction.getFormatTime()+" 状态报告\nSrc_Number:"+this.Src_terminal_Id+"\nDest_Number:"+this.Dest_terminal_Id+"\nReport_Stat:"+this.Report_Stat+"\nMsg_Id:"+this.Report_Msg_Id);
}
else{
//当字节数大于128时候
this.Msg_Content = readDeliverString(dataInputStream,this.Msg_Length,this.Msg_Fmt);
if(Version == 48){ //CMPP3.0
this.LinkID = this.readString(dataInputStream,20);
}
else if(Version == 32){ //CMPP2.0
this.Reserved = this.readString(dataInputStream,8);
}
Debug.outInfo("\n[CMPPMaster]"+PublicFunction.getFormatTime()+" 接收数据\nSrc_Number:"+this.Src_terminal_Id+"\nDest_Number:"+this.Dest_terminal_Id+"\nMsg_Content:"+this.Msg_Content+"\nMsg_Id:"+this.Msg_Id+"\nLink_Id:"+this.LinkID+"");
}
}catch(Exception e){
System.out.println("[CMPP]CMPP.parseDeliverPack error " + e);
throw e;
}
}
/**
* 解析CMPP_SUBMIT_RESP信息包
* 8.4.3.2 CMPP_SUBMIT_RESP消息定义(ISMG à SP)
* @param dataInputStream
*/
private void parseSubmitRespPack( DataInputStream dataInputStream ) throws Exception
{
try{
this.Msg_Id = dataInputStream.readLong();
//目的号码。SP的服务代码,一般4--6位,或者是前缀为服务代码的长号码;该号码是手机用户短消息的被叫号码。
if(Version == 48){ //CMPP3.0
this.Result = (byte)dataInputStream.readInt();
}
else if(Version == 32){ //CMPP2.0
this.Result = (byte)dataInputStream.readByte();
}
if(this.Result == 0){
//发送成功的,只打印消息,不做日志
System.out.println("\n[CMPPMaster]"+PublicFunction.getFormatTime()+" Submit_Resp\n"+"MsgId:"+this.Sequence_Id+"\nResult:"+this.Result);
}
else{
Debug.outInfo("\n[CMPPMaster]"+PublicFunction.getFormatTime()+" Submit_Resp\n"+"MsgId:"+this.Sequence_Id+"\nResult:"+this.Result);
}
}catch(Exception e){
System.out.println("[CMPP]CMPP.parseSubmitRespPack error " + e);
throw e;
}
}
/**
* 解析CMPP_QUERY_RESP信息包
* 8.4.4.2 CMPP_QUERY_RESP消息的定义(ISMG àSP)
* @param dataInputStream
*/
private void parseQueryRespPack( DataInputStream dataInputStream ) throws Exception
{
try{
this.Time = readString(dataInputStream,8);
this.Query_Type = dataInputStream.readByte();
this.Query_Code = readString(dataInputStream,10);
this.MT_TLMsg = dataInputStream.readInt();
this.MT_Tlusr = dataInputStream.readInt();
this.MT_Scs = dataInputStream.readInt();
this.MT_WT = dataInputStream.readInt();
this.MT_FL = dataInputStream.readInt();
this.MO_Scs = dataInputStream.readInt();
this.MO_WT = dataInputStream.readInt();
this.MO_FL = dataInputStream.readInt();
}catch(Exception e){
System.out.println("[CMPP]CMPP.parseQueryRespPack error " + e);
throw e;
}
}
/**
* 向数据输出流写入指定长度字符串,不足右补“\0”
* @param dataOutStream 由调用者传送来的数据输出流
* @param str 写入的字符
* @param StrLen 指定长度
* @throws Exception
*/
private void writeString_old(DataOutputStream dataOutStream,String str,int StrLen)
throws Exception
{
int i;
try{
if(str!=null)
{
dataOutStream.writeBytes(str) ;
System.out.println("str len = "+str.length());
for (i=1;i<=StrLen-str.length ();i++)
{
dataOutStream.writeByte('\0');
}
}else{
for (i=1;i<=StrLen;i++)
{
dataOutStream.writeByte('\0');
}
}
}catch(IOException e){
throw e;
}
}
/**
* 向数据输出流写入指定长度字符串,不足右补“\0”
* @param dataOutStream 由调用者传送来的数据输出流
* @param str 写入的字符
* @param StrLen 指定长度
* @throws Exce
**/
private void writeString(DataOutputStream dataOutStream,String str,int StrLen)
throws Exception {
if(str==null || str.length()==0){
for(int i=0;i<StrLen;i++){
dataOutStream.writeByte('\0');
}
return;
}
// byte[] bytes = str.getBytes();
// int theLength = Math.min(bytes.length,StrLen);
// dataOutStream.write(bytes,0,theLength);
int theLength = str.length() < StrLen ? str.length() : StrLen;
dataOutStream.writeBytes(str.substring(0,theLength));
//不足部分补'\0'
for(int i=0;i<StrLen-theLength;i++){
dataOutStream.writeByte('\0');
}
}
/**
* 从流中读取一个字符串,返回的String 不包含'\0'
*/
private static String readString(DataInputStream inStream,int StrLen)
{
byte[] readByte = new byte[1000];
int i = 0;
//当消息长度为大于(128时候)
if(StrLen <0)
StrLen = 256 + StrLen;
try{
while(true){
readByte[i] = inStream.readByte() ;
i++;
if (i>=1000)
return "";
if(i > StrLen-1)
break;
}
} catch(IOException e){
return "erro";
}
String result = new String(readByte,0,i);
return result.trim ();
}
/**
* 按长度,编码格式从字节流中读取指定长度的字符
* @param inStream :字节流
* @param StrLen :长度
* @param fmt :编码格式
* @return
*/
private static String readDeliverString(DataInputStream inStream, int StrLen,
int fmt) {
String result = "";
byte[] readByte = new byte[1000];
int i = 0;
//判断字符串是否长于128位
if (StrLen < 0) {
StrLen = 256 + StrLen;
}
try {
while (true) {
readByte[i] = inStream.readByte();
i++;
if (i >= 1000)
return "";
if (i > StrLen - 1)
break;
}
}
catch (IOException e) {
return "readStringError->IOException";
}
//按编码格式进行转码
try {
if (fmt == 8) {
result = new String(readByte, "UnicodeBigUnmarked");
}
if (fmt == 0) {
result = new String(readByte, 0, i);
}
if (fmt == 15) {
result = new String(readByte, "gb2312");
}
}
catch (Exception e) {
return "readStringError->FormatException";
}
return result.trim();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -