⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 npapitest.java~2~

📁 短信网关发送接受平台。
💻 JAVA~2~
字号:
package smscenter;import cmpp12.*;import com.newpalm.smsgwapi.*;import com.newpalm.log.BatchLog;public class NpApiTest {  public NpApiTest() {  }  public static void main(String[] args) {    NpApiTest npApiTest1 = new NpApiTest();    npApiTest1.test();  }  public void test(){    String IsmgIP = "202.108.48.189";//server's IP    int IsmgPort = 8010;//server's port    String IsmgUser = "910013";//auth username    String IsmgPass = "354789";//auth password    int SocketTimeout =60;//socket timeout    int version = 0;//server's version    boolean LogFlag = true;//need authentication    int msg_id = 0;    //initialize some link parameters    SpConnector12 spConnector = new SpConnector12(IsmgIP,IsmgPort,SocketTimeout,IsmgUser,IsmgPass,version,LogFlag);    BatchLog.setPrintDevice(BatchLog.DEV_SCREEN);//API log output into Screen    for(int i =0 ;i<10; i ++) {//at most 10 messages for test      //login and connect      if(!spConnector.ifConnected()){//if being not logined, try to login        int logret = spConnector.login();        if (logret == 0) {          System.out.println("login successfully! logret=" + logret);        }        else {          System.out.println("login failed! logret=" + logret);          //wait for 10s          try {            Thread.sleep(10 * 1000);          }          catch (Exception ex) {}          //continue to login          continue;        }      }      //if there is no message to send and its status comes into idle,      //you should send ActiveTest Msg by 10s for keeping the link alive.      //if(idletime>10s)      try{spConnector.sendActive();}catch(Exception ex){}      //if there are some submit msg to send out      //send  submit message      CMPPSubmitMessage oneMsg = new CMPPSubmitMessage();      oneMsg.setMsgId(msg_id++);      if(msg_id>2) break; //if sended 2 msg, then jump out of while      oneMsg.setPkTotal(1);      oneMsg.setPkNumber(1);      oneMsg.setRegisteredDelivery(0);      oneMsg.setMsgLevel(0);      oneMsg.setServiceId("TEST");      oneMsg.setFeeUserType(3);      oneMsg.setFeeTerminalId("13912345678");      oneMsg.setTpPid(0);      oneMsg.setTpUdhi(0);      oneMsg.setMsgFmt(15);      oneMsg.setMsgSrc("1010");      oneMsg.setFeeType("01");      oneMsg.setFeeCode("0");      oneMsg.setValidTime("");      oneMsg.setAtTime("");      oneMsg.setSrcTerminalId("1010");      oneMsg.setDestUsrTl(1);      oneMsg.setDestTerminalId("13912345678");      oneMsg.setMsgContent("test测试");      oneMsg.setReserve("");      //send the message      try {        spConnector.sendMsg(oneMsg);        System.out.println("Send one submit message: " +                           " SequenceID:'" + oneMsg.getSequenceID() + "'" +                           " Msg_id:'" + oneMsg.getMsgId() + "'" +                           " Pk_total:'" + oneMsg.getPkTotal() + "'" +                           " Pk_number:'" + oneMsg.getPkNumber() + "'" +                           " Msg_level:'" + oneMsg.getMsgLevel() + "'" +                           " Service_id:'" + oneMsg.getServiceId() + "'" +                           " fee_usertype:'" + oneMsg.getFeeUserType() + "'" +                           " fee_termianl_id:'" + oneMsg.getFeeTerminalId() + "'" +                           " tp_pid:'" + oneMsg.getTpPid() + "'" +                           " tp_udhi:'" + oneMsg.getTpUdhi() + "'" +                           " Msg_Fmt:'" + oneMsg.getMsgFmt() + "'" +                           " Msg_src:'" + oneMsg.getMsgSrc() + "'" +                           " FeeType:'" + oneMsg.getFeeType() + "'" +                           " FeeCode:'" + oneMsg.getFeeCode() + "'" +                           " Valid_Time:'" + oneMsg.getValidTime() + "'" +                           " At_Time:'" + oneMsg.getAtTime() + "'" +                           " Src_terminal_id:'" + oneMsg.getSrcTerminalId() + "'" +                           " DestUsr_tl:'" + oneMsg.getDestUsrTl() + "'" +                           " Dest_terminal_id:'" + oneMsg.getDestTerminalId().trim() +"'" +                           " Msg_Content:'" + oneMsg.getMsgContent() + "'" +                           " Registered_delivery:'" + oneMsg.getRegisteredDelivery() + "'" +                           " Reserve:'" + oneMsg.getReserve() + "'\n"                           );      }      catch (Exception ex) {}      //receive  messages from server      CMPPMessage cmppMsg = null;      try {        cmppMsg = spConnector.readMsg();      }      catch (Exception recvEx) {        System.out.println(" Socket linker disconnect." + recvEx.toString());        break;      }      if (cmppMsg == null) {        BatchLog.info("receive one null Deliver");        continue;      }      //differentiate the message type by cmppMsg.getCommandID()      //the message received may be CMPP_Deliver,CMPP_Submit_REP, or else.      try {        switch (cmppMsg.getCommandID()) {          case CmppConstants.CMPP_Deliver:            CMPPDeliverMessage cmppDeliverMsg = (CMPPDeliverMessage) cmppMsg;            System.out.println("Receive one MO: phone=" +                               cmppDeliverMsg.getDestTermianlId() +                               " content=" + cmppDeliverMsg.getMsgContent());            break;          case CmppConstants.CMPP_Submit_REP:            //Generally,by matching submit response msgid with sumit msgid,            //you can find out the corresponding submit msg.            //status=0 denotes success; other status's value denotes error code            CMPPSubmitRepMessage subRepMsg = (CMPPSubmitRepMessage) cmppMsg;            System.out.println("Receive one MT Reply: MsgId=" +                               subRepMsg.getMsgId() +                               " status=" + subRepMsg.getResult());            break;          case CmppConstants.CMPP_Active_Test:            break;          case CmppConstants.CMPP_Terminate:            break;          case CmppConstants.CMPP_Query_REP:            break;          case CmppConstants.CMPP_Terminate_REP:            break;          case CmppConstants.CMPP_Active_Test_REP:            break;          case CmppConstants.CMPP_Cancel_REP:            break;        } //switch      }      catch (Exception ex) {}      //sleep 1s      try{Thread.sleep(1*1000);}catch(Exception ex){}   }//while   //logout and disconnect   try{spConnector.logout();;}catch(Exception ex){}   System.out.println("logout");   BatchLog.stopWrite();//stop Api logs output }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -