📄 xsms.java~18~
字号:
// Decompiled by DJ v2.9.9.61 Copyright 2000 Atanas Neshkov Date: 2003-1-3 17:35:38
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: xsms.java
package cncgw.xsms;
import java.io.*;
import java.net.Socket;
import cncgw.cncMain;
import cncgw.parser.ParseXml;
import java.util.StringTokenizer;
import org.jdom.*;
import cncgw.parser.cncParser;
// Referenced classes of package cncgw.xsms:
// xsmse_pack, xsmse_head, conn_desc, OutOfBoundsException,
// xsmse_login, MD5, UnknownPackException, DeliverFailException,
// xsmse_result, xsmse_submit_result, xsmse_login_result, xsmse_us_user,
// xsmse_deliver_result, xsmse_cancel, xsmse_submit
public final class xsms
{
public xsms()
{
}
protected boolean read_count_byte(DataInputStream in, byte buf[], int len)
throws IOException
{
try
{
for(int i = 0; i < len; i++)
buf[i] = in.readByte();
}
catch(IOException e)
{
in = null;
throw e;
}
return true;
}
protected void memset(byte b[], int len)
{
for(int i = 0; i < len; i++)
b[i] = 0;
}
protected int read_unknowncount_byte(DataInputStream in, byte buf[])
throws IOException
{
int len = 0;
try
{
do
{
buf[len] = in.readByte();
if(buf[len] == 0)
break;
len++;
} while(true);
}
catch(IOException e)
{
in = null;
throw e;
}
return ++len;
}
public String SocketRead(conn_desc conn) throws IOException
{
InputStream ins ;
String readStr = "";
try
{
ins = conn.sock.getInputStream();
String readLine=null;
// byte[] xmlHeader = new byte[8];
// ins.read(xmlHeader);
// String xmlHeaderStr = new String(xmlHeader);
// int xmlLength = Integer.parseInt(xmlHeaderStr.substring(4,8))-8;
// byte[] xmlString = new byte[xmlLength];
byte[] xmlString = new byte[1024*4];
int readLength=ins.read(xmlString);
// while((xmlLength-readLength)>0)
// {
// byte[] loseString = new byte[xmlLength-readLength];
// int loseLength=ins.read(loseString);
// for(int i=0;i<loseLength;i++)
// xmlString[readLength+i] = loseString[i];
// readLength=readLength+loseLength;
//
// }
readStr =new String(xmlString);
return readStr.trim();
}catch(IOException e )
{
cncMain.errorlog("[错误]-从中心网关接收消息发生错误!"+e.getMessage());
throw e;
}
}
// protected boolean readPack(DataInputStream in, xsmse_pack p)
// throws IOException
// {
// try
// {
// p.pk_head.pk_len = in.readInt();
// p.pk_head.pk_cmd = in.readInt();
// p.pk_head.pk_stat = in.readInt();
// p.pk_head.pk_seq = in.readInt();
// read_count_byte(in, p.buf, p.pk_head.pk_len - 16);
// }
// catch(IOException e)
// {
// throw e;
// }
// return true;
// }
// protected boolean readHead(String recvXmlStr, xsmse_pack p)
//
// {
//
// p.pk_head.command_id = in.readInt();
// p.pk_head.command_status = in.readInt();
// p.pk_head.sequence_no = in.readInt();
//
//
// return true;
// }
protected int strlen(byte str[])
{
int i;
for(i = 0; str[i] != 0 && i < 200; i++);
return i;
}
// protected boolean send_count_byte(DataOutputStream out, byte buf[], int len)
// throws IOException
// {
// try
// {
// for(int i = 0; i < len; i++)
// out.writeByte(buf[i]);
//
// out.flush();
// }
// catch(IOException e)
// {
// throw e;
// }
// return true;
// }
// protected boolean send_unknowncount_byte(DataOutputStream out, byte buf[])
// throws IOException
// {
// int i = 0;
// try
// {
// while(buf[i] != 0 && i < 200)
// {
// out.writeByte(buf[i]);
// i++;
// }
// out.write(buf[i]);
// out.flush();
// }
// catch(IOException e)
// {
// throw e;
// }
// return true;
// }
protected int strcpy(byte d[], byte s[], int from, int maxlen)
{
int i;
for(i = 0; i < maxlen; i++)
d[i + from] = s[i];
d[i + from] = 0;
return i;
}
protected int string2byte(String s, byte d[], int from, int maxlen)
{
int i = 0;
int j = 0;
for(; i < s.length(); i++)
{
char c = s.charAt(i);
c &= '\uFF00';
c >>= '\b';
byte b = (byte)c;
j++;
if(b == 0)
{
c = s.charAt(i);
d[(j - 1) + from] = (byte)(c & 0xff);
} else
{
d[(j - 1) + from] = b;
c = s.charAt(i);
d[j + from] = (byte)(c & 0xff);
j++;
}
}
if(j > maxlen)
j = maxlen;
d[j + from] = 0;
return j;
}
/**
* 将/n处理掉<br>
*/
private String removeBr(String Content){
String makeContent = new String();
StringTokenizer strToken = new StringTokenizer(Content,"\n");
while(strToken.hasMoreTokens()) {
makeContent = makeContent + strToken.nextToken();
}
return makeContent;
}
protected String getSendHeader(xsmse_head ch)
{
StringBuffer sb = new StringBuffer();
sb.append("<?xml version=\"1.0\" encoding = \"GBK\"?>\n");
sb.append("<xsmp>\n");
sb.append("<message_header>\n");
sb.append("<command_id>"+ch.command_id+"</command_id>\n");
sb.append("<command_status>"+ch.command_status+"</command_status>\n");
sb.append("<sequence_no>"+ch.sequence_no+"</sequence_no>\n");
sb.append("</message_header>\n");
return sb.toString();
}
protected int testDigitString(byte t[], int maxlen)
{
int i;
for(i = 0; t[i] != 0 && i < maxlen; i++)
if(t[i] > 57 || t[i] < 48)
return -1;
return i != maxlen ? 1 : -2;
}
public void xsms_connect_to_ismg(String host, int port, conn_desc conn)
throws IOException
{
Socket s = null;
try
{
s = new Socket(host, port);
s.setSoTimeout(0x1d4c0);
}
catch(IOException e)
{
throw e;
}
conn.seq = 0x7ffffff0;
conn.sock = s;
}
public void xsms_disconnect_from_ismg(conn_desc conn)
{
try
{
conn.sock.close();
}
catch(Exception _ex)
{
return;
}
}
public void xsms_login(conn_desc conn, String id, String icp, String ip, String system_id, String password, String system_type, String interface_version,String address_range)
throws IOException, OutOfBoundsException
{
xsmse_head ch = new xsmse_head();
xsmse_login login_body = new xsmse_login();
String sendXML = "";
OutputStream out = null;
OutOfBoundsException e = new OutOfBoundsException();
try
{
synchronized (lockObject)
{
out = (conn.sock.getOutputStream());
ch.command_id = xsmsE_ESME_BNDRCV;
ch.command_status = 0;
ch.sequence_no = conn.seq;
sendXML = getSendHeader(ch);
if(id.length()>16)
throw e;
if(system_id.length()>16)
throw e;
if(password.length()>9)
throw e;
if(system_type.length()>13)
throw e;
if(interface_version.length()>2||interface_version.length()<2)
throw e;
if(address_range.length()>41)
throw e;
sendXML = sendXML+login_body.getLoginBodyXML(id,icp,ip,system_id,password,system_type,interface_version,address_range);
System.out.println("sendXML---"+sendXML);
// String sendXML2="xsmp"+XmlStrLength(sendXML)+sendXML;
// 中心网关接收不到信息时,应询问如何避免读到的信息不会发生前后两个xml包粘连混合,建议应参考移动网关增加包长标示
out.write(sendXML.getBytes());
out.flush();
System.out.println("have flush!");
conn.seq++;
if(conn.seq == 0x7fffffff)
conn.seq = 1;
out = null;
}
}
catch(IOException e1)
{
out = null;
throw e1;
}
//
}
public xsmse_result readResPack(conn_desc conn)
throws IOException, UnknownPackException, DeliverFailException,JDOMException,NullPointerException
{
xsmse_result cr = new xsmse_result();
String recvXMLString = "";
xsmse_pack pack = new xsmse_pack();
do
{
try{
recvXMLString = SocketRead(conn);
}catch(IOException e){
throw e;
}
try{
ParseXml.xmlConfig(removeBr(recvXMLString));
pack.pk_head.command_id = Integer.parseInt(ParseXml.getElement("command_id").trim());
pack.pk_head.command_status = Integer.parseInt(ParseXml.getElement("command_status").trim());
pack.pk_head.sequence_no = Integer.parseInt(ParseXml.getElement("sequence_no").trim());
}catch(JDOMException ex){
throw ex;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -