📄 xsms.java~17~
字号:
catch(Exception _ex)
{
status = 2009;
}
finally
{
in = null;
out = null;
}
return status;
}
*/
public void xsms_cancel(conn_desc conn, xsmse_cancel cc)
throws IOException, OutOfBoundsException
{
xsmse_head ch = new xsmse_head();
xsmse_cancel cancel_body = new xsmse_cancel();
String sendXML = "";
OutputStream out = null;
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);
sendXML = sendXML+cancel_body.getCancalBodyXML();
out.write(sendXML.getBytes());
out.flush();
conn.seq++;
if(conn.seq == 0x7fffffff)
conn.seq = 1;
out = null;
}
}
catch(IOException e)
{
out = null;
throw e;
}
}
public void xsms_active_test(conn_desc conn)
throws IOException
{
xsmse_head ch = new xsmse_head();
try
{
ch.command_id = xsmsE_ESME_QRYLINK;
ch.command_status = 0;
ch.sequence_no = conn.seq;
sendHeader(ch,conn);
conn.seq++;
if(conn.seq == 0x7fffffff)
conn.seq = 1;
}
catch(IOException e)
{
throw e;
}
}
protected void sendHeader(xsmse_head ch, conn_desc conn)
throws IOException
{
OutputStream out = null;
out = (conn.sock.getOutputStream());
String sendXML = "";
try
{
synchronized (lockObject)
{
sendXML = getSendHeader(ch);
sendXML = sendXML+"<message_body></message_body></xsmp>\n";
out.write(sendXML.getBytes());
out.flush();
out = null;
}
}
catch(IOException e)
{
out = null;
throw e;
}
}
protected void readPa(conn_desc con)
{
xsmse_result cr = null;
try
{
cr = readResPack(con);
switch(cr.pack_id)
{
case -2147483647:
xsmse_login_result cl = (xsmse_login_result)cr;
System.out.println("------------login resp----------: STAT = " + ((xsmse_result) (cl)).stat);
break;
case -2147483646:
System.out.println("------------logout resp----------: STAT = " + cr.stat);
break;
case -2147483644:
xsmse_submit_result sr = (xsmse_submit_result)cr;
System.out.println("------------submit resp----------: STAT = " + ((xsmse_result) (sr)).stat + " SEQ = " + sr.seq);
break;
case 5: // '\005'
System.out.println("------------deliver---------: STAT = 0");
xsmse_deliver_result cd = (xsmse_deliver_result)cr;
cd.printAllField();
xsms_send_deliver_resp(con, cd.seq, ((xsmse_result) (cd)).stat,cd.media_type,cd.source_address,cd.destination_address);
break;
case -2147483645:
xsmse_query_result qr = (xsmse_query_result)cr;
System.out.println("查询------------query resp-----------::" + qr.stat);
qr.printAllField();
break;
case -2147483640:
System.out.println("取消---------cancel resp-----------: STAT = " + cr.stat);
break;
case -2147483627:
System.out.println("---------active resp-----------: STAT " + cr.stat);
break;
default:
System.out.println("---------Error packet-----------");
break;
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
System.out.println("have a exception");
try
{
System.in.read();
}
catch(Exception _ex) { }
}
}
public static void main(String args[])
{
xsms p = new xsms();
xsmse_submit sub = new xsmse_submit();
new xsmse_submit_result();
new xsmse_cancel();
String short_msg = "hello,我们的业务开通了!";
int sm_len = short_msg.length();
new xsmse_result();
new xsmse_deliver_result();
System.out.println("-----------icp 连接模拟中心测试开始-----------");
Thread thisThread = Thread.currentThread();
try
{
conn_desc con = new conn_desc();
p.xsms_connect_to_ismg("127.0.0.1", 8010, con);
System.out.println("Connected 模拟中心");
p.xsms_login(con, "020014", "8600004","127.0.0.1","310","123456","","10", "");
System.out.println("icp login have send !!!!!!!!!");
// thisThread.sleep(5000);
p.readPa(con);
sub.set_media_type("sms.cnc");
sub.set_service_type("99");
sub.set_source_address("03513530620");
sub.set_destination_address("13934534534");
sub.set_esm_class((byte)1);
sub.set_priority_flag((byte)1);
sub.set_schedule_delivery_time("030401123000500+");
sub.set_validity_peroid("030401123000500+");
sub.set_registered_delivery_flag((byte)0);
sub.set_replace_if_present_flag((byte)0);
sub.set_data_coding((byte)1);//均默认按 1:gb2312
String connect = cncParser.normalize(short_msg);
sub.set_sm_length(connect.length());
sub.set_short_message_text(connect);
sub.set_fee_Type("2");
sub.set_fee_userType("3");
sub.set_seqNo(con.seq);
for(int test_count = 0; test_count < 1; test_count++)
{
int user_seq = p.xsms_submit(con, sub);
System.out.println("Submited SM Seq = " + user_seq);
System.out.println("icp submit "+test_count+" have send !!!!!!!!!");
p.readPa(con);
}
p.xsms_active_test(con);
System.out.println("icp active have send !!!!!!!!!");
p.readPa(con);
p.xsms_logout(con);
System.out.println("icp logout have send !!!!!!!!!");
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
System.out.println("have a exception");
return;
}
}
protected int bytecpy(byte d[], byte s[], int from)
{
int i;
for(i = 0; s[i] != 0; i++)
d[i + from] = s[i];
d[i + from] = 0;
return ++i;
}
public int xsms_submit(conn_desc conn, xsmse_submit cs)
throws IOException
{
xsmse_head ch = new xsmse_head();
new xsmse_pack();
String sendXML = "";
OutputStream out = null;
int user_seq;
try
{
synchronized (lockObject)
{
out = (conn.sock.getOutputStream());
ch.command_id = xsmsE_ESME_SUB_SM;
ch.command_status = 0;
ch.sequence_no = cs.get_seqNo();
sendXML = getSendHeader(ch);
sendXML = sendXML+cs.getSubmitBodyXml(cs.media_type,cs.service_type,cs.source_address,cs.destination_address,cs.esm_class,cs.priority_flag,cs.schedule_delivery_time,cs.validity_peroid,cs.registered_delivery_flag,cs.replace_if_present_flag,cs.data_coding,cs.sm_default_msg_id,cs.sm_length,cs.short_message_text,cs.fee_Type,cs.fee_userType,cs.fee_terminal);;
cs.printAllField();
out.write(sendXML.getBytes());
out.flush();
out = null;
user_seq = cs.get_seqNo();//要保证数据库中id小于0x7fffffff
conn.seq++;
if(conn.seq == 0x7fffffff)
conn.seq = 1;
}
}
catch(IOException e)
{
throw e;
}
return user_seq;
}
public String XmlStrLength(String strTemp)
{
StringBuffer sb = new StringBuffer();
for(int i=0;i<4-( Integer.toString( (8+strTemp.length()) ) ).length();i++)
sb.append("0");
sb.append(strTemp.getBytes().length+8);
return sb.toString();
}
public Object lockObject=new Object();
public static final byte xsmsE_MAX_ICP_ID_LEN = 6;
public static final byte xsmsE_AUTH_LEN = 16;
public static final byte xsmsE_MAX_SVC_LEN = 10;
public static final byte xsmsE_DATETIME_LEN = 16;
public static final byte xsmsE_MAX_DSTS_NUM = 100;
public static final byte xsmsE_MAX_MSGID_LEN = 64;
public static final byte xsmsE_MAX_MSISDN_LEN = 20;
public static final short xsmsE_MAX_SM_LEN = 160;
public static final byte xsmsE_DATE_TIME_LEN = 14;
public static final byte xsmsE_MAX_FEE_TYPE = 99;
public static final int xsmsE_MAX_INFO_FEE = 0xf423f;
public static final byte xsmsE_MAX_PRIORITY = 9;
public static final byte xsmsE_QUERY_TIME_LEN = 8;
public static final byte xsmsE_QUERY_CODE_LEN = 10;
public static final byte xsmsE_PK_HEAD_SIZE = 16;
public static final byte xsmsE_PK_LEN_SIZE = 4;
public static final byte xsmsE_MIN_PK_SIZE = 16;
public static final short xsmsE_MAX_PK_SIZE = 2477;
public static final byte xsmsE_MM_NO_REGIST = 0;
public static final byte xsmsE_MM_REGIST = 1;
public static final byte xsmsE_MM_CONTROL = 2;
public static final byte xsmsE_BIND_SEND = 0;
public static final byte xsmsE_BIND_RECV = 1;
public static final byte xsmsE_DC_ASCII = 0;
public static final byte xsmsE_DC_STK = 3;
public static final byte xsmsE_DC_BIN = 4;
public static final byte xsmsE_DC_UCS2 = 8;
public static final byte xsmsE_DC_GB2312 = 15;
// public static final int xsmsE_NACK_RESP = 0x80000000;
public static final int xsmsE_ESME_BNDRCV = 1;
public static final int xsmsE_ESME_BNDRCV_RESP = 0x80000001;
public static final int xsmsE_ESME_UBD = 2;
public static final int xsmsE_ESME_UBD_RESP = 0x80000002;
public static final int xsmsE_ESME_QUERY_SM = 3;
public static final int xsmsE_ESME_QUERY_SM_RESP = 0x80000003;
public static final int xsmsE_ESME_SUB_SM = 4;
public static final int xsmsE_ESME_SUB_SM_RESP = 0x80000004;
public static final int xsmsE_ESME_DELIVER_SM = 5;
public static final int xsmsE_ESME_DELIVER_SM_RESP = 0x80000005;
public static final int xsmsE_ESME_DELIVER_STATUS = 6;
// public static final int xsmsE_QUERY_RESP = 0x80000006;
// public static final int xsmsE_CANCEL = 7;
// public static final int xsmsE_CANCEL_RESP = 0x80000007;
public static final int xsmsE_ESME_CANCEL_SM = 8;
public static final int xsmsE_ESME_CANCEL_SM_RESP = 0x80000008;
public static final int xsmsE_ESME_QRYLINK = 15;
public static final int xsmsE_ESME_QRYLINK_RESP = 0x80000015;
// public static final int xsmsE_SUBMIT_M = 10;
// public static final int xsmsE_SUBMIT_M_RESP = 0x8000000a;
public static final int xsmsE_RSP_SUCCESS = 0;
public static final int xsmsE_RSP_OTHER_ERR = 1;
public static final int xsmsE_RSP_INVAL_MSG_LEN = 2;
public static final int xsmsE_RSP_UNKNOWN_CMD = 3;
public static final int xsmsE_RSP_SYNC_ERR = 4;
public static final int xsmsE_RSP_INVAL_STRUCT = 5;
public static final int xsmsE_RSP_INVAL_ICP = 16;
public static final int xsmsE_RSP_INVAL_AUTH = 17;
public static final int xsmsE_RSP_INVAL_BIND_TYPE = 18;
public static final int xsmsE_RSP_BINDED = 19;
public static final int xsmsE_RSP_BIND_EXCEED = 20;
public static final int xsmsE_RSP_NOT_BIND = 21;
public static final int xsmsE_RSP_INVAL_MSG_MODE = 32;
public static final int xsmsE_RSP_INVAL_DATA_CODING = 33;
public static final int xsmsE_RSP_INVAL_SVC_TYPE = 34;
public static final int xsmsE_RSP_INVAL_FEE_TYPE = 35;
public static final int xsmsE_RSP_INVAL_DATETIME = 36;
public static final int xsmsE_RSP_DSTS_EXCEED = 37;
public static final int xsmsE_RSP_SMLEN_EXCEED = 38;
public static final int xsmsE_RSP_INVAL_MSISDN = 38;
public static final int xsmsE_RSP_INVAL_PARA = 39;
public static final int xsmsE_RSP_PK_SEQ_REPEAT = 48;
public static final int xsmsE_RSP_PK_SEQ_EXCEED = 49;
public static final int xsmsE_RSP_MSG_NOT_FOUND = 50;
public static final int xsmsE_RSP_LEN_BAD = 136;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -