📄 msgid.java
字号:
package com.khan.sms;
import java.util.HashMap;
import com.khan.util.*;
/**
* <p>Title: 处理MSG解码</p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class MsgID {
private int month;
private int day;
private int hour;
private int min;
private int sec;
private int gatewayID; //7位
private int seqID; //(3) 序列号:bit16~bit1,顺序增加,步长为1,循环使用
byte[] MsgID;
public MsgID(String msgid) {
if (msgid.length() < 22) {
throw new ExceptionInInitializerError("MSG_ID 长度不足22位!");
}
int ioffset = 0;
month = Integer.parseInt(msgid.substring(ioffset, ioffset + 2));
ioffset += 2;
day = Integer.parseInt(msgid.substring(ioffset, ioffset + 2));
ioffset += 2;
hour = Integer.parseInt(msgid.substring(ioffset, ioffset + 2));
ioffset += 2;
min = Integer.parseInt(msgid.substring(ioffset, ioffset + 2));
ioffset += 2;
sec = Integer.parseInt(msgid.substring(ioffset, ioffset + 2));
ioffset += 2;
gatewayID = Integer.parseInt(msgid.substring(ioffset, ioffset + 7));
ioffset += 7;
seqID = Integer.parseInt(msgid.substring(ioffset, ioffset + 5));
ioffset += 5;
MsgID = new byte[8];
SocketCommon.FillChar(MsgID, (byte) 0x00);
}
public MsgID(byte[] msgid) {
MsgID = msgid;
month = (int) ((msgid[0] >> 4) & 0x0F);
day = (int) ((msgid[0] & 0x0F) << 1) + ((msgid[1] >> 7) & 0x01);
hour = (int) ((msgid[1] >> 2) & 0x1F);
min = (int) ((msgid[1] & 0x03) << 4) + ((msgid[2] >> 4) & 0x0F);
sec = (int) ((msgid[2] & 0x0F) << 2) + ((msgid[3] >> 6) & 0x03);
gatewayID = (int) (((msgid[3] & 0x3F) << 16) + (msgid[4] << 8) + (msgid[5]));
seqID = ((((msgid[6] + 256)) % 256 * 256) + (msgid[7] + 256) % 256);
//System.out.println(seqID);
}
public byte[] Encode() {
MsgID[0] = (byte) (MsgID[0] | (byte) (month << 4)); // month 4bit
MsgID[0] = (byte) (MsgID[0] | (byte) (day >> 1)); // day 5bit
MsgID[1] = (byte) (MsgID[1] | (byte) (day << 7));
MsgID[1] = (byte) (MsgID[1] | (byte) (hour << 2)); // hour 5bit
MsgID[1] = (byte) (MsgID[1] | (byte) (min >> 4)); // min 5bit
MsgID[2] = (byte) (MsgID[2] | (byte) (min << 4));
MsgID[2] = (byte) (MsgID[2] | (byte) (sec >> 2)); // sec 5bit
MsgID[3] = (byte) (MsgID[3] | (byte) (sec << 6));
MsgID[3] = (byte) (MsgID[3] | (byte) (gatewayID >> 16)); //gatewayID 22bit
MsgID[4] = (byte) (MsgID[4] | (byte) (gatewayID >> 8));
MsgID[5] = (byte) (MsgID[5] | (byte) (gatewayID));
MsgID[6] = (byte) (MsgID[6] | (byte) (seqID >> 8));
MsgID[7] = (byte) (MsgID[7] | (byte) (seqID));
return MsgID;
}
public String toString() {
return SocketCommon.IntFormat(month, 2) + SocketCommon.IntFormat(day, 2)
+ SocketCommon.IntFormat(hour, 2) + SocketCommon.IntFormat(min, 2)
+ SocketCommon.IntFormat(sec, 2) + SocketCommon.IntFormat(gatewayID, 7)
+ SocketCommon.IntFormat(seqID, 5);
}
static public void main(String[] args) {
/*
String aa = "abcd145";
aa =aa.substring(0, aa.indexOf(0x34));
System.out.println(aa);*/
/*
byte[] data = {0x00, 0x00, 0x00 ,0x15,
(byte)0x80, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x01,
(byte)0x9c, (byte)0xbd, (byte)0xc6, 0x40,
0x03, (byte)0xe9, 0x00, 0x26, 0x00};
System.out.println(getDWord(data, 4));
*/
//PrintDataHex( toByteArray(0x80000004));
//PrintDataHex( toByteArrayHigh(0x80000004));
//System.out.println(toHexString(toByteArray(0x80000004)));
//com.khan.sms.cmpp2.Cmpp2Connect cmppconn = new com.khan.sms.cmpp2.Cmpp2Connect("626019", "niW516", (byte)0x20);
//System.out.println(System.getProperty("file.separator"));
//cmppconn.setSeqID(2315);
//PrintDataHex(cmppconn.encodeCmpp());
byte[] msgid = {(byte) 0xAD, 0x0D, 0x6E, 0x40, 0x07, (byte) 0xD1, (byte) 0xA0, (byte) 0xCF};
//String msgid ="0830142132000000100000";
MsgID mi = new MsgID(msgid);
SocketCommon.PrintDataHex(mi.Encode());
System.out.println(mi);
//String str ="s";
/*
java.util.Properties pe = System.getProperties();
java.util.Enumeration ea =pe.propertyNames();
while (ea.hasMoreElements()) {
String s = (String) ea.nextElement();
System.out.println(s+": |"+ pe.getProperty(s));
}
*/
/*
java.util.Map hm = System.getenv();
java.util.Iterator e = hm.keySet().iterator();
while (e.hasNext()) {
Object ob = e.next();
System.out.println((String)ob + ":\t " + hm.get(ob) );
}
*/
//com.khan.sms.cmpp2.Cmpp2Connect cmppconn = new com.khan.sms.cmpp2.Cmpp2Connect("626019", "niW516", (byte)0x20);
//System.out.println(System.getProperty("file.separator"));
//cmppconn.setSeqID(2315);
//PrintDataHex(cmppconn.encodeCmpp());
//String mobile = "13632346940";
//System.out.println(mobile.toCharArray().length);
//com.khan.file.CopyFile cf = new com.khan.file.CopyFile();
//cf.copy("c:/SMS.7z","d:/SMS.7z");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -