📄 shortmsgcmpp.java
字号:
return true;
}
private void getDeliverRep(DataOutputStream dataOutStream) {
int bodySize;
try {
bodySize = 16 + 10;
getHead(dataOutStream, bodySize);
writeString(dataOutStream, submit_msg_id, 10);
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void parseBodyDeliver(DataInputStream dataInStream) {
parseResult = CmppConstants.success;
try {
submit_msg_id_tem = getTemMSgID(msgID_b);
msgMode = dataInStream.readByte();
msgDataCoding = dataInStream.readByte();
readString(dataInStream, 14);// recv time
msgSrcAddr = readString(dataInStream, 21);
msgDestAddr = readString(dataInStream, 21);
msgLength = dataInStream.readByte();
if (msgMode == 1) {
int allLen = dataInStream.available();
String tem = readString(dataInStream, allLen);
int inde = tem.indexOf("id:") + "id:".length();
int end = tem.indexOf(" sub");
String reportmsgid_STR = tem.substring(inde, end);
reportMsgId = getTemMSgID(reportmsgid_STR.getBytes());
inde = tem.indexOf("stat") + 4 + 1;
end = tem.indexOf("err");
reportStat = tem.substring(inde, end);
reportDestAddr = msgDestAddr;
} else {
int msgLen;
if (msgLength < 0) {
msgLen = 256 + msgLength;
} else {
msgLen = msgLength;
}
if (msgLen > 320) {
parseResult = CmppConstants.error_too_long;
return;
}
byte[] b = new byte[msgLen];
dataInStream.readFully(b);
if (msgDataCoding == 0)
msgContent = new String(b);
else if (msgDataCoding == 4)//
msgContent = new String(b);
else if (msgDataCoding == 8)//
msgContent = new String(b, "UTF-16BE");
else if (msgDataCoding == 15) //
msgContent = new String(b, "GB2312");
/*
* else if(msgDataCoding == 64) msgContent = new
* String(b,"GB2312");
*/
else
msgContent = convertBytesToString(b);
}
} catch (Exception e) {
parseResult = CmppConstants.error_msg_structure;
LogManage.ins().myLog.logp(Level.WARNING, "", "",
" parse deliver error : " + e);
}
return;
}
private String getTemMSgID(byte[] b) {
String desBuff = "";
String oa;
try {
for (int i = 0; i < b.length; i++) {
oa = Integer.toHexString((int) b[i]);
if (oa.length() <= 1)
oa = "0" + oa;
if (b[i] < 0)
oa = oa.substring(oa.length() - 2);
desBuff += oa;
}
return desBuff;
} catch (Exception e) {
return null;
}
}
private static String convertBytesToString(byte bstr[]) {
String desBuff = "";
String oa;
try {
for (int i = 0; i < bstr.length; i++) {
oa = Integer.toHexString((int) bstr[i]);
if (oa.length() <= 1)
oa = "0" + oa;
if (bstr[i] < 0)
oa = oa.substring(oa.length() - 2);
desBuff += oa;
}
return desBuff;
} catch (Exception e) {
return null;
}
}
// 读取需要发送的消息ID
private static String readMsgID(DataInputStream inStream, int StrLen) {
byte[] readByte = new byte[StrLen];
try {
for (int i = 0; i < StrLen; i++) {
readByte[i] = inStream.readByte();
}
} catch (IOException e) {
System.out.println(" readMsgID error :" + e);
return "erro";
}
msgID_b = (byte[]) readByte.clone();
return new String(readByte);
}
private static boolean writeString(DataOutputStream dataOutStream,
String str) {
try {
dataOutStream.writeBytes(str);
dataOutStream.writeByte('\0');
} catch (IOException e) {
return false;
}
return true;
}
private static boolean writeString(DataOutputStream outStream, String str,
int StrLen) {
int i;
try {
if (str != null) {
outStream.writeBytes(str);
for (i = 1; i <= StrLen - str.length(); i++) {
outStream.writeByte('\0');
}
} else {
for (i = 1; i <= StrLen; i++) {
outStream.writeByte('\0');
}
}
} catch (IOException e) {
return false;
}
return true;
}
private static byte[] convertStringToBytes(String srcBuff) {
String subBuff;
byte ab;
try {
byte des[] = new byte[srcBuff.length() / 2];
int j = 0;
for (int i = 0; i < srcBuff.length(); i += 2, j++) {
subBuff = srcBuff.substring(i, i + 2);
ab = (byte) Integer.parseInt(subBuff, 16);
des[j] = ab;
}
return des;
} catch (Exception e) {
return null;
}
}
private static String readString(DataInputStream inStream) {
byte[] readByte = new byte[180];
int i = 0;
try {
while (true) {
readByte[i] = inStream.readByte();
if (readByte[i] == '\0')
break;
i++;
if (i >= 180)
return "";
}
} catch (IOException e) {
return CmppConstants.READSTRINGERROR;
}
String result = new String(readByte, 0, i);
return result;
}
private byte[] computeDigest(byte[] b) {
try {
MessageDigest alg = MessageDigest.getInstance("MD5");
alg.reset();
alg.update(b);
byte[] hash = alg.digest();
return hash;
} catch (Exception e) {
System.out.println("MessageDigest :" + e);
return null;
}
}
private static boolean CompBytes(byte[] b1, byte[] b2) {
if (b1.length != b2.length)
return false;
for (int i = 0; i < b1.length; i++) {
if (b1[i] != b2[i])
return false;
}
return true;
}
private static String readString(DataInputStream inStream, int StrLen) {
byte[] readByte = new byte[1000];
int i = 0;
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();
}
private byte[] intToBytes(int i) {
try {
ByteArrayOutputStream byteArrayos = new ByteArrayOutputStream();
DataOutputStream dataOutStream = new DataOutputStream(byteArrayos);
dataOutStream.writeInt(i);
return byteArrayos.toByteArray();
} catch (Exception e) {
}
return null;
}
public byte subType = 0;
public String submit_msg_id;
public int totalSize;
public int headCmdID;
public int headCmdStatus;
public int headSeqcNo;
// public String conSourceAddr="";
public byte[] conAuth;
public byte conBindType;
public byte conVersion;
public int conTimestamp;
public byte[] conTimestampBytes;
public byte lastVersion;
public byte[] repAuth;
public String spId;
public String msgId;
public int fwdFlag;
public int AccessorId;
public int smscSeqNo;
public String moMsgId;
public String msgSpId;
public String msgSrcAddr;
public String msgDestAddr;
public String[] msgSubmitDest;
public String msgServiceType;
public byte msgFeeType;
public int msgInfoFee;
public byte msgProtocolId;
public byte msgMode;
public byte msgPriority;
public byte msgFeeUserType;
public byte msgDataCoding;
public String msgDeliverTime;
public String msgDigest;
public byte msgLength;
public String msgContent;
public String msgValidityPeriod;
public String msgSchedule;
public String msgReserve;
public byte TlsFlag;
public int ackMsgID;
public byte respResult;
public int parseResult;
public byte successId;
public String spCode;
public byte[] spPasswd;
public int packetLength;
public int spIndex;
public int pushType;
public String connect_authenticatoricp;
public byte activeResult;
public byte submit_destusr_tl;
public String feeTerminalId;
public byte msgPkTotal;
public byte msgPkNumber;
public byte sendCount = 0;
public long firstSendtime = 0;
public long lastSendtime = 0;
public byte tpPId = 0;
public byte tpUdhi = 0;
public int operateSeqId = 0;
public String reportMsgId;
public String reportStat;
public String reportSubmitTime;
public String reportDoneTime;
public String reportDestAddr;
public int reportSmscSequence;
// 转换用MSGid
private static byte[] msgID_b = null;
public String submit_msg_id_tem = "0";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -