📄 smscshortmsg.java
字号:
package smgpgw;
import java.io.*;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author wangpei
* @version 1.0
*/
public class SmscShortMsg {
private int nParseResult = SmscConstants.ESME_ROK;
public int headCmdID; //消息类型 当该值等于0时表示该消息无效
public int headCmdStatus = 0; //请求命令是否执行成功(在RESP中为空)
public int headSeqcNo; //消息流水号(可以用来完成消息的确认)
//消息体
//请求连接
public String bindSysID = ""; //连接者ID;在RESP中也有
public String bindSysPwd = ""; //连接者密码
public String bindSysType = ""; //连接者类型
public int bindSysVersion = 3; //版本号
public int bindTon = 0;
public int bindNpi = 0;
public String bindAddrRange = "";
//ACK
public String ackMsgID = "01"; //HexString 短消息ID,当该消息是ACK时有效
//短消息
public String msgServiceType = ""; //与短消息服务相关的类型
public byte msgSourceAddressTon = 3; //源地址编码类型
public byte msgSourceAddressNpi = 0; //源地址编码方案
public String msgSourceAddress = "0"; //源地址
public byte msgDestAddressTon = 1; //目的地址编码类型
public byte msgDestAddressNpi = 1; //目的地址编码方案
public String msgDestAddress = ""; //目的地址
public byte msgEsmClass = 0; //短消息类型 在SUBMIT_SM中没有意义
public byte msgProtocolID = 33; //GSM协议类型
public byte msgPriorityFlag = 0; //短消息优先级
public String msgScheduleDeliveryTime = ""; //定时发送短消息的时间
public String msgValidityPeroid = ""; //短消息的最后有效期限
public byte msgRegisterdDeliveryFlag = 0; //是否需要反馈标志
public byte msgReplaceIfPresentFlag = 0; //是否替换短消息标志
public byte msgDataCoding = 26; //数据编码方案 8:unicode
public byte msgSmDefaultMsgID = 0; //预定义短消息ID
public byte msgSmLength = 0; //短消息长度
public String msgShortMsgText = ""; //短消息数据内容
//ESME向SMSC查询提交的短消息状态
public String queryMsgID = ""; // 短消息ID
public byte queryTon = 2; //地址编码类型
public byte queryNpi = 1; //地址编码方案
public String queryAddress = ""; //地址
public String queryFinalDate = ""; //短消息生命周期终止时间
public byte queryMsgStatus; //短消息当前状态
public byte queryErrorCode; //GSM错误码
//取消提交的短信息
public String ccServiceType = ""; //保留
public String ccMsgID = ""; //短消息ID,设置为NULL时表示取消所有源编码地址和目标编码地址与下属地址相同的短消息
public byte ccSrcAddTon = 2; //原地址编码类型
public byte ccSrcAddNpi = 1; //源地址编码方案
public String ccSrcAdd = ""; //源地址
public byte ccDestAddTon = 2; //目的地址编码类型
public byte ccDestAddNpi = 1; //目的地址编码方案
public String ccDestAdd = ""; //目的地址
//替换提交的短消息
public String rpMsgID; //需要被替换的短消息ID
//public int accessor_id=1;
/**
* 此短信中心的字段没有修改原来移动的内容,只在上面添加了一些小灵通的需要的字段
*/
public String msgRecvTime = "";
public SmscShortMsg() { }
public int getParseResult() {
return nParseResult;
}
public byte[] getPackage() {
ByteArrayOutputStream byteArrayOutStream = new ByteArrayOutputStream();
DataOutputStream dataOutStream = new DataOutputStream(byteArrayOutStream);
switch(headCmdID) {
case SmscConstants.SMPP_ENQUIRE_LINK_RESP :
getHead(dataOutStream,16);
break;
case SmscConstants.SMPP_ENQUIRE_LINK :
getHead(dataOutStream,16);
break;
case SmscConstants.SMPP_BIND_RECEIVER_RESP :
getBindRespCommand(dataOutStream);
break;
case SmscConstants.SMPP_BIND_TRANSMITTER_RESP :
getBindRespCommand(dataOutStream);
break;
case SmscConstants.SMPP_UNBIND_RESP:
getHead(dataOutStream,16);
break;
case SmscConstants.SMPP_SUBMIT_SM_RESP :
getSubmitAckCommand(dataOutStream);
break;
case SmscConstants.SMPP_DELIVER_SM :
getDeliverCommand(dataOutStream);
break;
case SmscConstants.SMPP_QUERY_SM_RESP :
//Log.debug("send a query ") ;
break;
case SmscConstants.SMPP_GENERIC_NAK :
getHead(dataOutStream, 16);
//Log.debug("send a error message!") ;
break;
default:
//Log.debug("invalid command!!!="+headCmdID);
}
byte[] b = byteArrayOutStream.toByteArray();
/*
for(int i=0;i<b.length ;i++)
System.out.print(b[i]+" ") ;
Log.debug(" ") ;
*/
return b;
}
public void parsePackage(byte[] receivedPackage) {
int nResult;
ByteArrayInputStream byteStream = new ByteArrayInputStream(receivedPackage);
DataInputStream dataInStream = new DataInputStream(byteStream);
nResult = parseHead(dataInStream);
if(nResult < 0)
SMSCFrame.RecvArea.append("Parse package head error !!!!!!\n");
//if(headCmdID == 0)
//Log.error(" headCmdID == 0"); // exception thrown
switch(headCmdID) {
case SmscConstants.SMPP_BIND_RECEIVER :
parseBodyBindRes(dataInStream);
break;
case SmscConstants.SMPP_BIND_TRANSMITTER :
parseBodyBindRes(dataInStream);
break;
case SmscConstants.SMPP_UNBIND :
break;
case SmscConstants.SMPP_SUBMIT_SM :
parseBodySubmitReq(dataInStream);
break;
case SmscConstants.SMPP_DELIVER_SM_RESP :
parseBodyDeliverRes(dataInStream);
break;
case SmscConstants.SMPP_ENQUIRE_LINK:
break;
case SmscConstants.SMPP_GENERIC_NAK :
//Log.debug("command invalid! "+headCmdID) ;
break;
default:
//Log.error("sorry,this command_id cann't recommand!="+headCmdID) ;
headCmdID=0;
}
}
private void parseBodyBindRes(DataInputStream dataInStream) {
try {
bindSysID = readString(dataInStream);
if( bindSysID == READSTRINGERROR)
headCmdID = 0;
bindSysPwd =readString(dataInStream);
if( bindSysPwd == READSTRINGERROR)
headCmdID = 0;
bindSysType =readString(dataInStream);
if( bindSysType == READSTRINGERROR)
headCmdID = 0;
bindSysVersion = dataInStream.readByte() ;
bindTon = dataInStream.readByte() ;
bindNpi = dataInStream.readByte() ;
bindAddrRange = readString(dataInStream);
//Log.debug("bindAddrRange="+bindAddrRange) ;
if( bindAddrRange == READSTRINGERROR)
headCmdID = 0;
} catch(IOException e) {
headCmdID=0;
//nParseResult = false;
//Log.error("IOException=="+e.getMessage() ) ;
}
}
private void parseBodyDeliverRes(DataInputStream dataInStream) {
ackMsgID = readString(dataInStream);
if(ackMsgID == READSTRINGERROR)
headCmdID = 0;
}
private void parseBodySubmitReq(DataInputStream dataInStream) {
try {
msgServiceType = readString(dataInStream);
if( msgServiceType == READSTRINGERROR) {
headCmdID = 0;
return;
}
msgSourceAddressTon = dataInStream.readByte() ;
msgSourceAddressNpi = dataInStream.readByte();
msgSourceAddress = readString(dataInStream);
if( msgSourceAddress == READSTRINGERROR) {
headCmdID = 0;
return;
}
msgDestAddressTon = dataInStream.readByte();
msgDestAddressNpi = dataInStream.readByte();
msgDestAddress = readString(dataInStream);
if( msgDestAddress == READSTRINGERROR) {
headCmdID = 0;
return;
}
msgEsmClass = dataInStream.readByte() ;
msgProtocolID = dataInStream.readByte();
msgPriorityFlag = dataInStream.readByte() ;
msgScheduleDeliveryTime = readString(dataInStream);
if( msgScheduleDeliveryTime == READSTRINGERROR) {
headCmdID = 0;
return;
}
msgValidityPeroid = readString(dataInStream);
if( msgValidityPeroid == READSTRINGERROR) {
headCmdID = 0;
return;
}
msgRegisterdDeliveryFlag = dataInStream.readByte();
//Log.debug(" 是否要状态报告的标志 msgRegisterdDeliveryFlag="+ msgRegisterdDeliveryFlag) ;
msgReplaceIfPresentFlag = dataInStream.readByte() ;
msgDataCoding = dataInStream.readByte() ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -