帮前辈贴出来,希望更多的人来看看,也不枉俺在村口吆喝了这么多天
mo方的主程序- import cmpp12.*;
- import java.net.*;
- import java.io.*;
- public class testcomplexmo {
- public static void main(String[] args) {
- testcomplexmo atestprocesse=new testcomplexmo();
- }
- public testcomplexmo() {
- Socket so=null;
- OutputStream out=null;
- InputStream input=null;
- CMPP_Command command=null;
- CMPP_Seq seq=new CMPP_Seq(212);
- int error=0;
-
- try {
- so=new Socket("192.168.1.62",700);
- input=so.getInputStream();
- out=so.getOutputStream();
- command=new CMPP_Command();
-
- //CMPP_Connect
- CMPP_Connect con=new CMPP_Connect(seq.getGlobalSeq(), //设置sequenceid,
- //可不用API提供的类CMPP_Seq所提供的方法,自己输入sequenceid
- "xlmo",//CP_ID
- "xl",//密码
- 0); //版本号一般填0
- error=con.write(out);//发送消息
- System.out.println("connect.error="+error);
- System.out.println();
-
- boolean loop=true;
- while (loop) {
- CMPP_Command tmpCMD=command.read(input);//读消息
- switch (command.getCommandID()) {
- //CMPP_Deliver
- case CMPP_Command.ID_CMPP_DELIVER :
- CMPP_Deliver deliver=(CMPP_Deliver)tmpCMD;//强制转换
- int result=deliver.readbody();//解包
- System.out.println("get cmpp deliver");
- System.out.println("total_length:"+deliver.getTotalLength());
- System.out.println("command_id:"+deliver.getCommandID());
- System.out.println("seq:"+deliver.getSequenceId());
- //get the information of header
- System.out.println("msg_id0:"+deliver.getMsgId0());
- System.out.println("msg_id1:"+deliver.getMsgId1());
- //MsgID is the message number.
- //it is int
- System.out.println("destination_id:"+deliver.getDestnationId());
- //the Destnation_id is SP MO phone number,
- //eg. "2000"
- // it is String
- System.out.println("service_id:"+deliver.getServiceId());
- //the Service_id is Service id
- //it is String
- System.out.println("tp_pid:"+deliver.getTP_pid());
- //TP_pid is GSM protocal type
- //it is int
- System.out.println("tp_udhi:"+deliver.getTP_udhi());
- //TP_udhi is GSM protocal type
- //it is int
- System.out.println("Msg_Fmt:"+deliver.getMsgFmt());
- //Msg_Fmt - the formate of this message
- //int
- System.out.println("usernumber(SrcTerminalId):"+deliver.getSrcTerminalId());
- //SrcTerminalId - the user's mobile number
- //String
- System.out.println("registered_deliver:"+deliver.getRegisteredDelivery());
- //Registered_Delivery specify if this MO message is a message Response
- //0 means not a Response message
- //1 means is a Response message
- //it is int
- System.out.println("msglen:"+deliver.getMsgLength());
- //MessageLength means the length of this message
- //it is int
- System.out.println("content:"+deliver.getMsgContent());
- //MessageContent - the content of this message
- //String
- System.out.println("msgid_submit0:"+deliver.getMsgId_Submit0());
- System.out.println("msgid_submit1:"+deliver.getMsgId_Submit1());
- //MsgID_Submit is the message number. the same as MsgID
- //it is int
- System.out.println("cmppstat:"+deliver.getStat());
- //Stat - Response result the meaning follows SMPP3.3 protocol
- //String
- System.out.println("submittime:"+deliver.getSubmitTime());
- //YYMMDDHHMM
- //String
- System.out.println("donttime:"+deliver.getDoneTime());
- //YYMMDDHHMM
- //String
- System.out.println("Dest_terminal_id:"+deliver.getDestnationId());
- //Dest_terminal_id - the user's mobile number who receive the message
- //String
- System.out.println("smscseq:"+deliver.getSMSCSequence());
- //the sequence number that the SMSC provides
- //int
- //CMPP_DeliverRep
- CMPP_DeliverRep deliverRep=
- new CMPP_DeliverRep(deliver.getSequenceId(),//SequenceId
- deliver.getMsgId0(),//MsgId,要求和收到的deliver一致
- deliver.getMsgId1(),//MsgId,要求和收到的deliver一致
- 55);//Result
- //new CMPP_DeliverRep(deliver.getSequenceId(),
- //deliver.getMsgId0(),deliver.getMsgId1(),result);
- deliverRep.write(out);//发送消息
- System.out.println("deliver responce have send out!");
- System.out.println();
- System.out.println("-------------------------------");
- break;
- //CMPP_Terminate
- case CMPP_Command.ID_CMPP_TERMINATE :
- CMPP_Terminate terminate=(CMPP_Terminate)tmpCMD;//强制转换
- System.out.println("get cmpp terminate");
- System.out.println("total_length:"+terminate.getTotalLength());
- System.out.println("command_id:"+terminate.getCommandID());
- System.out.println("seq:"+terminate.getSequenceId());
- //CMPP_TerminateRep
- CMPP_TerminateRep terminateRep=
- new CMPP_TerminateRep(terminate.getSequenceId());//SequenceId
- terminateRep.write(out);//发送消息
- System.out.println("termination responce have send out!");
- System.out.println();
- System.out.println("--------------------------------");
- loop=false;
- break;
- //CMPP_ActiveTest
- case CMPP_Command.ID_CMPP_ACTIVE_TEST :
- CMPP_ActiveTest activetest=(CMPP_ActiveTest)tmpCMD;//强制转换
- System.out.println("get active test");
- System.out.println("total_length:"+activetest.getTotalLength());
- System.out.println("command_id:"+activetest.getCommandID());
- System.out.println("seq:"+activetest.getSequenceId());
- //CMPP_ActiveTestRep
- CMPP_ActiveTestRep activetestRep=
- new CMPP_ActiveTestRep(activetest.getSequenceId());//SequenceId
- activetestRep.write(out);//发送消息
- System.out.println("active test responce have send out!");
- System.out.println();
- System.out.println("--------------------------------");
- break;
- }
- }
- } catch (Exception e) {
- System.out.println(e.toString());
- } finally {
- try {
- System.out.println("the end of motest");
- System.in.read();
- //it just for debug
- } catch (Exception s) {
- System.out.println(s.toString());
- }
- }
- }
- }
复制代码 |