📄 smgp.java
字号:
}
SmgpData.AuthenticatorClient = readString(dataInStream, 16);
if (SmgpData.AuthenticatorClient == READSTRINGERROR) {
SmgpData.status = MISAUTH_ERR;
return;
}
SmgpData.LoginMode = dataInStream.readByte();
System.out.println("vvvvvvvvvvvvvvvvvvvvvv:"+SmgpData.LoginMode);
SmgpData.timestamp = dataInStream.readInt();
SmgpData.version = dataInStream.readByte();
}
catch (Exception e) {
e.printStackTrace();
SmgpData.status = MISSTRUCTURE_ERR;
}
return;
}
private static void parseBodyDeliverRep(DataInputStream dataInStream,
SmgpData SmgpData) {
try {
SmgpData.MsgID = readString(dataInStream, 10);
SmgpData.status = dataInStream.readInt();
}
catch (Exception e) {
System.out.println("parse body deliver rep has error :" + e);
}
return;
}
private static void parseBodySubmit(DataInputStream dataInStream,
SmgpData SmgpData) {
SmgpData.status = CORRECT;
try {
SmgpData.msgSubType = dataInStream.readByte();
SmgpData.msgNeedReport = dataInStream.readByte();
SmgpData.msgPriority = dataInStream.readByte();
SmgpData.msgServiceID = readString(dataInStream, 10);
if (SmgpData.msgServiceID.equalsIgnoreCase(READSTRINGERROR)) {
SmgpData.status = 1;
}
SmgpData.msgFeeType = readString(dataInStream, 2);
if (SmgpData.msgFeeType.equalsIgnoreCase("00") ||
SmgpData.msgFeeType.equalsIgnoreCase("01") ||
SmgpData.msgFeeType.equalsIgnoreCase("02") ||
SmgpData.msgFeeType.equalsIgnoreCase("03") ||
SmgpData.msgFeeType.equalsIgnoreCase("04")) {
}
else {
SmgpData.status = MISFEETYPE_ERR;
System.err.println("error:MISFEETYPE_ERR");
return;
}
SmgpData.msgFeeCode = readString(dataInStream, 6);
SmgpData.msgFixedFee = readString(dataInStream, 6);
System.out.println("msgFixedFee = " +SmgpData.msgFixedFee +" msgFeeCode="+SmgpData.msgFeeCode);
if (SmgpData.msgFeeCode == READSTRINGERROR ||
SmgpData.msgFeeCode.equals("")) {
SmgpData.status = MISFEECODE_ERR;
System.err.println("error:MISFEECODE_ERR");
return;
}
Constants.TotalMoney = Constants.TotalMoney +
Integer.parseInt(SmgpData.msgFeeCode);
SmgpData.msgMsgFormat = dataInStream.readByte();
SmgpData.msgValidTime = readString(dataInStream, 17);
SmgpData.msgAtTime = readString(dataInStream, 17);
SmgpData.msgSrcTermID = readString(dataInStream, 21);
SmgpData.msgChargeTermID = readString(dataInStream, 21);
SmgpData.msgDestTermIDCount = dataInStream.readByte();
SmgpData.msgDestTermIDArr = new String[SmgpData.msgDestTermIDCount];
for (int i = 0; i < SmgpData.msgDestTermIDCount; i++) {
SmgpData.msgDestTermID = SmgpData.msgDestTermIDArr[i] = readString(dataInStream, 21);
}
SmgpData.msgMsgLength = dataInStream.readByte();
/*读取短消息内容*/
int msgLen;
if (SmgpData.msgMsgLength < 0) {
msgLen = 256 + SmgpData.msgMsgLength;
}
else {
msgLen = SmgpData.msgMsgLength;
}
if (SmgpData.msgMsgFormat == 0) {
if (msgLen >= 160) {
SmgpData.status = MISLENGTH_ERR;
System.err.println("error:MISLENGTH_ERR");
return;
}
}
else {
if (msgLen > 140) {
SmgpData.status = MISLENGTH_ERR;
System.out.println("异常");
return;
}
}
if (msgLen <= 0) {
SmgpData.status = MISLENGTH_ERR;
System.err.println("error:MISLENGTH_ERR");
System.out.println("异常");
return;
}
byte[] b = new byte[msgLen];
dataInStream.readFully(b);
if (SmgpData.msgMsgFormat == 0 || SmgpData.msgMsgFormat == 15) {
SmgpData.msgMsgContent = new String(b);
SmgpData.msgMsgContent = new String(SmgpData.msgMsgContent.getBytes(),
"gb2312"); //ISO_8859_1
//System.out.println("内容="+SmgpData.msgContent);
}
else if (SmgpData.msgMsgFormat == 8) { //unicode
SmgpData.msgMsgContent = new String(b, "UTF-16BE");
}
else
SmgpData.msgMsgContent = convertBytesToString(b);
SmgpData.msgReserve = readString(dataInStream, 8);
}
catch (Exception e) {
// method.error ("submit from sp has error="+e);
System.out.println("接收内容出错...");
SmgpData.status = MISSTRUCTURE_ERR;
}
/* sum=sum+System.currentTimeMillis()-start;
count++;
if(count==1000) {
System.out.println("sum time="+sum);
count=0;
sum=0;
}*/
Constants.Submit_Nu++;
System.out.println("正确接收到的短信条数=" + Constants.Submit_Nu);
return;
}
private static void parseBodyActiveTest(DataInputStream dataInStream,
SmgpData SmgpData) {
try {
}
catch (Exception e) {
SmgpData.status = 1; //不成功!
}
return;
}
private static void parseBodyActiveTestRep(DataInputStream dataInStream,
SmgpData SmgpData) {
try {
}
catch (Exception e) {
SmgpData.status = 0;
}
return;
}
//-------------------------------------------------------------
private static String readPass(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 READSTRINGERROR;
}
//lgh
//String result = new String(readByte,0,0,i);
String result = new String(readByte, 0, i);
return result;
}
private static String readString(DataInputStream inStream, int StrLen) {
if (StrLen <= 0 || StrLen >= 2101) {
return "";
}
byte[] readByte = new byte[StrLen];
try {
inStream.readFully(readByte);
}
catch (IOException e) {
return READSTRINGERROR;
}
//lgh
//String result = new String(readByte,0,0,StrLen);
String result = new String(readByte, 0, StrLen);
return result.trim();
}
//---------------------------------------------------------------
/**
* 向流中写入一个字符串,以'\0'结尾
*/
private static boolean writeString(DataOutputStream outStream, String str,
int StrLen) {
int i;
try {
if (str != null) {
if (StrLen == 0) {
return true;
}
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;
}
catch (Exception ex) {
return false;
}
return true;
}
//-------------------------------------------------------------
public static String getTime() {
Calendar now = Calendar.getInstance();
String yyyy = String.valueOf(now.get(java.util.Calendar.YEAR));
String mm = String.valueOf(now.get(Calendar.MONTH) + 1);
String dd = String.valueOf(now.get(Calendar.DAY_OF_MONTH));
String hh = String.valueOf(now.get(Calendar.HOUR_OF_DAY));
String ff = String.valueOf(now.get(Calendar.MINUTE));
String ss = String.valueOf(now.get(Calendar.SECOND));
mm = (1 == mm.length()) ? ("0" + mm) : mm;
dd = (1 == dd.length()) ? ("0" + dd) : dd;
hh = (1 == hh.length()) ? ("0" + hh) : hh;
ff = (1 == ff.length()) ? ("0" + ff) : ff;
ss = (1 == ss.length()) ? ("0" + ss) : ss;
String yyyymmdd = yyyy + "-" + mm + "-" + dd;
String hhffss = hh + ":" + ff + ":" + ss;
return yyyymmdd + " " + hhffss + " ";
}
private static boolean validnumber(String telephone) {
telephone = telephone.trim();
for (int i = 0; i < telephone.length(); i++) {
if (telephone.charAt(i) < '0' || telephone.charAt(i) > '9') {
return false;
}
}
return true;
}
private static boolean validtelephone(String telephone) {
if (telephone.trim().equals("")) {
return false;
}
for (int i = 0; i < telephone.length(); i++) {
if (telephone.charAt(i) < '0' || telephone.charAt(i) > '9' ||
telephone.charAt(i) == '+') { //20020306 beijing
return false;
}
}
return true;
}
public 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;
}
}
public 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;
}
}
public static byte[] toByteArray(long number) {
long temp = number;
byte[] b = new byte[8];
for (int i = b.length - 1; i > -1; i--) {
b[i] = new Long(temp & 0xff).byteValue();
temp = temp >> 8;
}
return b;
}
public static byte[] toByteArray(int number) {
int temp = number;
byte[] b = new byte[4];
for (int i = b.length - 1; i > -1; i--) {
b[i] = new Integer(temp & 0xff).byteValue();
temp = temp >> 8;
}
return b;
}
public static byte[] toByteArray(short number) {
short temp = number;
byte[] b = new byte[2];
for (int i = b.length - 1; i > -1; i--) {
b[i] = new Short( (short) (temp & 0xff)).byteValue();
temp = (short) (temp >> 8);
}
return b;
}
private static boolean writeString(String str, byte[] data, int StrLen,
int count) {
try {
for (int i = 0; i < str.length(); i++) {
data[count++] = (byte) str.charAt(i);
}
for (int i = str.length(); i < StrLen; i++) {
data[count++] = '\0';
}
}
catch (Exception e) {
return false;
}
return true;
}
public static int toInteger(byte[] b, int location) {
int s = 0;
for (int i = 0; i < 3; i++) {
if (b[location] > 0)
s = s + b[location++];
else
s = s + 256 + b[location++];
s = s * 256;
}
if (b[location] > 0)
s = s + b[location];
else
s = s + 256 + b[location];
return s;
}
public static long toLong(byte[] b, int location) {
int s = 0;
for (int i = 0; i < 8; i++) {
if (b[location] > 0)
s = s + b[location++];
else
s = s + 65536 + b[location++];
s = s * 65536;
}
if (b[location] > 0)
s = s + b[location];
else
s = s + 65536 + b[location];
return s;
}
private static short msgId = 1;
public static synchronized short getMsgID() {
if (msgId == 32000) {
msgId = 1;
return msgId;
}
return msgId++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -