?? sendthread.java
字號:
/*
* 創(chuàng)建日期 2004-6-8
*
* 更改所生成文件模板為
* 窗口 > 首選項 > Java > 代碼生成 > 代碼和注釋
*/
package cmpp2;
import java.util.*;
import com.commerceware.cmpp.*;
import java.text.DateFormat;
/**
* @author Administrator
*
* 更改所生成類型注釋的模板為
* 窗口 > 首選項 > Java > 代碼生成 > 代碼和注釋
*/
public class SendThread extends Thread
{
ArrayList outal;
boolean outstop, unconnect;
Sendmsg sm;
String orgaddr, destaddr, content;
public final CMPP sendp = new CMPP();
public final conn_desc sendcon = new conn_desc();
cmppe_result cr = new cmppe_result();
Date date = new Date();
DateFormat shortDateFormat =
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
DateFormat mediumDateFormat =
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
public static void main(String[] args)
{
}
public void initSend(ArrayList outal, boolean outstop)
{
this.outal = outal;
this.outstop = outstop;
}
public void run()
{
System.out.println("send start");
connect();
int testsend = 0;
try
{
sleep(1000);
}
catch (Exception e)
{
}
while (!outstop)
{
int a = 0;
if (!unconnect)
{
if (!outal.isEmpty())
{
sm = (Sendmsg) outal.get(0);
orgaddr = sm.getOrgaddr();
destaddr = sm.getDestaddr();
content = sm.getContent();
System.out.println("send orgaddr=" + orgaddr);
System.out.println("send destaddr=" + destaddr);
System.out.println(
"send content=" + content + content.length());
send(orgaddr, destaddr, content);
outal.remove(0);
//testsend = 0;
try
{
sleep(10);
}
catch (Exception e)
{
}
}
else
{
try
{
if (testsend > 30000)
{
sendp.cmpp_active_test(sendcon);
readPa();
testsend = 0;
}
sleep(100);
testsend += 100;
}
catch (Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
System.out.println("have a exception");
testsend = 0;
try
{
sendp.cmpp_connect_to_ismg(
"211.140.2.202",
7890,
sendcon);
System.out.println("connect ok");
sendp.cmpp_login(
sendcon,
"(企業(yè)代碼)",
"(密碼)",
(byte) 2,
0x12,
0105121212);
System.out.println("login ok");
readPa();
}
catch (Exception ex)
{
}
}
}
}
else
{
try
{
sleep(10000);
}
catch (Exception e)
{
}
}
}
try
{
sendp.cmpp_logout(sendcon);
readPa();
}
catch (Exception e)
{
}
}
public void stopSend()
{
outstop = true;
}
public void connect()
{
try
{
sendp.cmpp_connect_to_ismg("211.140.2.202", 7890, sendcon);
System.out.println("connect ok");
sendp.cmpp_login(
sendcon,
"(企業(yè)代碼)",
"(密碼)",
(byte) 2,
0x12,
0105121212);
System.out.println("login ok");
readPa();
unconnect = false;
}
catch (Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
System.out.println("have a exception");
try
{
System.in.read();
}
catch (Exception e1)
{
}
}
}
public synchronized void readPa()
{
try
{
cr = sendp.readResPack(sendcon);
switch (cr.pack_id)
{
case CMPP.CMPPE_NACK_RESP :
System.out.println("get nack pack");
break;
case CMPP.CMPPE_LOGIN_RESP :
cmppe_login_result cl;
cl = (cmppe_login_result) cr;
date = new Date();
System.out.println(
" send login resp: STAT = "
+ cl.stat
+ mediumDateFormat.format(date));
break;
case CMPP.CMPPE_LOGOUT_RESP :
date = new Date();
System.out.println(
"send logout resp: STAT = "
+ cr.stat
+ mediumDateFormat.format(date));
break;
case CMPP.CMPPE_SUBMIT_RESP :
cmppe_submit_result sr;
sr = (cmppe_submit_result) cr;
date = new Date();
System.out.println(
"send submit resp: STAT = "
+ sr.stat
+ mediumDateFormat.format(date));
//cmppe_cancel cc1 = new cmppe_cancel();
//cc1.set_msgid(new String(sr.msg_id));
break;
case CMPP.CMPPE_DELIVER :
byte msg[], src_addr[], dest_addr[];
System.out.println("5: STAT = 0");
cmppe_deliver_result cd = (cmppe_deliver_result) cr;
sendp.cmpp_send_deliver_resp(sendcon, cd.seq, cd.stat);
//cmpp_send_deliver_resp(con,cd.seq,cd.stat);
break;
case CMPP.CMPPE_ACTIVE_RESP :
date = new Date();
System.out.println(
"send active resp" + mediumDateFormat.format(date));
break;
default :
break;
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
System.out.println("have a exception");
}
}
public void send(String srcaddr, String destaddr, String content)
{
char test[] = new char[10];
byte short_msg[] = new byte[150];
byte buf[] = new byte[40];
byte b1[] = new byte[10];
cmppe_submit sub = new cmppe_submit();
cmppe_submit_result res = new cmppe_submit_result();
cmppe_cancel can = new cmppe_cancel();
byte icp_id[] = stringtobyteArray("(企業(yè)代碼)", 10);
byte svc_type[] = stringtobyteArray("(密碼)", 6);
byte fee_type = 0;
byte info_fee = 0;
byte proto_id = 1;
byte msg_mode = 1;
byte priority = 0;
byte fee_utype = 2;
byte fee_user[] = new byte[CMPP.CMPPE_MAX_MSISDN_LEN];
fee_user = stringtobyteArray("", 12);
byte validate[] = new byte[10];
validate[0] = 0;
byte schedule[] = new byte[2];
schedule[0] = 0;
byte src_addr[] = stringtobyteArray(srcaddr, 12);
byte du_count = 1;
byte dst_addr[][] = stringtobyteArray2(destaddr, 10, 15);
String ww = content;
// String ww="abcdefghijklmnopqrstuvwxyz0123456789";
byte data_coding = 15;
short_msg = stringtobyteArray(ww, 150);
//byte sm_len = 12;
byte protoid = 1;
// for(int i=0; i< 12; i++)
// short_msg[i]=0x38;
try
{
String procStr = new String(ww.getBytes(), "ISO8859-1");
//String procStr=ww;
sub.set_icpid(icp_id);
sub.set_svctype(svc_type);
sub.set_feetype(fee_type);
sub.set_infofee(info_fee);
sub.set_protoid(proto_id);
sub.set_msgmode(msg_mode);
sub.set_priority(priority);
sub.set_validate(validate);
sub.set_schedule(schedule);
sub.set_feeutype(fee_utype);
sub.set_feeuser(fee_user);
sub.set_srcaddr(src_addr);
sub.set_dstaddr(dst_addr);
sub.set_ducount(du_count);
sub.set_msg(data_coding, procStr.length(), short_msg);
sendp.cmpp_submit(sendcon, sub);
System.out.println("submit ok");
readPa();
}
catch (Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
System.out.println("have a exception");
try
{
System.in.read();
}
catch (Exception e1)
{
}
}
}
public byte[] stringtobyteArray(String content, int length)
{
byte[] outbyte = new byte[length];
try
{
String procStr = new String(content.getBytes(), "ISO8859-1");
//byte[] procbyte=content.getBytes();
byte[] procbyte = procStr.getBytes("ISO8859-1");
//byte[] procbyte=content.getBytes("gb2312");
for (int i = 0; i < procbyte.length; i++)
outbyte[i] = procbyte[i];
outbyte[procbyte.length] = 0;
return outbyte;
}
catch (Exception e)
{
}
finally
{
return outbyte;
}
}
public byte[][] stringtobyteArray2(
String content,
int length1,
int length2)
{
byte[][] outbyte = new byte[length1][length2];
byte[] procbyte = new byte[length2];
procbyte = content.getBytes();
for (int i = 0; i < content.length(); i++)
outbyte[0][i] = procbyte[i];
outbyte[0][content.length()] = 0x0;
return outbyte;
}
public byte Stringtobyte(String content)
{
byte outbyte;
byte[] procbyte = content.getBytes();
outbyte = procbyte[0];
return outbyte;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -