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

📄 smppframe.java

📁 smpp java实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      smppEncoder.bind(bind);
      SmppEncoder smppEncoder1 = new SmppEncoder();
      smppEncoder1.smppHeader(smppHeader);
      sock.sendPacket(smppEncoder1.getBytes());
      sock.sendPacket(smppEncoder.getBytes());
      //System.out.println(smppEncoder.getBytes().length);
      //System.out.println(smppEncoder1.getBytes().length);
      //int test=0XFFFFFFFF+1;
      //System.out.println("test:"+test);
    }

    catch (encoderException ee) {
      System.out.println("send bind Problem!");
    }

    if (thread == null) {
      thread = new Thread(this);
      thread.start();
    }
    //启动一个连续发送短信的线程

    new Dbsm();
  }

//--------------------------------------------------------------------
//向短消息中心提交短消息
//--------------------------------------------------------------------
  void jButtonSend_actionPerformed(ActionEvent e) {
    String source_addr = sourceAddress.getText().trim();
    String desti_addr = destinationAddress.getText().trim();
    String message = smscontext.getText().trim();
    //将中文短消息转化成中文编码
    try {
      byte[] abyte = message.getBytes("GB2312");
      //message = new String(message.getBytes("ISO-8859-1"),"GBK");
      message = new String(abyte);
    }
    catch (UnsupportedEncodingException ee) {
      ee.printStackTrace();
    }

    //sock=new Sock();
    //String message=StringtopureAscii.toTureAsciiStr(message1);
    /*    SmppHeader smppHeader = new SmppHeader(33 + source_addr.getBytes().length +
                                               desti_addr.getBytes().length +
                                               message.getBytes().length +
                                               (2 *
         (new Date()).toString().getBytes().
                                                length - 24),
                                               ESME_SUB_SM, //command_id
                                               0,
                                               j_no);
        submit = new Submit(
            null, //短消息服务的类别
            0,
            0,
            source_addr, //源地 址
            0,
            0,
            desti_addr, //目的地 址
            0, //短消息类 型
            0,
            0,
            new Date(),
            new Date(),
            0,
            1,
            1,
            0,
            message.length(),
            message);
        try {
          SmppEncoder smppEncoderHe = new SmppEncoder();
          smppEncoderHe.smppHeader(smppHeader); //对smppHeader进行编码
          SmppEncoder smppEncoderSub = new SmppEncoder();
          smppEncoderSub.submit(submit); //对submit进行编码
          sock.sendPacket(smppEncoderHe.getBytes());
          sock.sendPacket(smppEncoderSub.getBytes());
          //System.out.println("abyte2.length:"+abyte2.length);
          //System.out.println(2 * (new Date()).toString().getBytes().length);
          //System.out.println(smppEncoderHe.getBytes().length);
          //System.out.println((new Date()).toString());
          //System.out.println(smppEncoderSub.getBytes().length);
          //sock.sendPacket(abyte2);
         DataUpdate.setSmObject(new SmObject(0, source_addr, desti_addr, message));
        }
        catch (encoderException ee) {}
     */

    try {
      SmppHeader smppHeader = new SmppHeader(16 + 18 +
                                             source_addr.getBytes("ISO-8859-1").
                                             length +
                                             desti_addr.getBytes("ISO-8859-1").
                                             length +
                                             message.getBytes("ISO-8859-1").
                                             length
                                             ,

                                             ESME_SUB_SM, //command_id
                                             0,
                                             j_no);

      submit = new Submit(
          null, //短消息服务的类别
          0,
          0,
          source_addr, //源地 址
          0,
          0,
          desti_addr, //目的地 址
          0, //短消息类 型
          0,
          0,
          null,
          null,
          0,
          1,
          0,
          0,
          message.getBytes("ISO-8859-1").length,
          message);
      try {
        SmppEncoder smppEncoderHe = new SmppEncoder();
        smppEncoderHe.smppHeader(smppHeader); //对smppHeader进行编码
        SmppEncoder smppEncoderSub = new SmppEncoder();
        smppEncoderSub.submit(submit); //对submit进行编码
        sock.sendPacket(smppEncoderHe.getBytes());
        sock.sendPacket(smppEncoderSub.getBytes());
        System.out.println(smppEncoderHe.getBytes().length);
        System.out.println(smppEncoderSub.getBytes().length);
        DataUpdate.setSmObject(new SmObject(0, source_addr, desti_addr, message));
      }
      catch (encoderException ee) {
        ee.printStackTrace();
      }

    }
    catch (UnsupportedEncodingException ee) {
      ee.printStackTrace();
    }

  }

//--------------------------------------------------------------------
//供内部调用,发送短信
//---------------------------------------------------------------------
  private void sendSm(String s1, String s2, String s3) {
    String source_addr = s1;
    String desti_addr = s2;
    String message = s3;
    //将中文短消息转化成unicoder编码
    try {
      byte[] abyte = message.getBytes("ISO-8859-1");
      //message = new String(message.getBytes("ISO-8859-1"),"GBK");
      message = new String(abyte);
    }
    catch (UnsupportedEncodingException ee) {}

    sock = Sock.getSock();
    //String message=StringtopureAscii.toTureAsciiStr(message1);
    /*    SmppHeader smppHeader = new SmppHeader(16+17 + source_addr.getBytes().length +
                                               desti_addr.getBytes().length +
                                               message.getBytes().length +
                                               (2 *
         (new Date()).toString().getBytes().
                                                length - 24),
                                               ESME_SUB_SM, //command_id
                                               0,
                                               j_no);
        submit = new Submit(
            null, //短消息服务的类别
            0,
            0,
            source_addr, //源地 址
            0,
            0,
            desti_addr, //目的地 址
            0, //短消息类 型
            0,
            0,
            new Date(),
            new Date(),
            0,
            1,
            1,
            0,
            message.getBytes().length,
            message);
     */
    try {
      SmppHeader smppHeader = new SmppHeader(16 + 18 +
                                             source_addr.getBytes("ISO-8859-1").
                                             length +
                                             desti_addr.getBytes("ISO-8859-1").
                                             length +
                                             message.getBytes("ISO-8859-1").
                                             length
                                             ,

                                             ESME_SUB_SM, //command_id
                                             0,
                                             j_no);

      submit = new Submit(
          null, //短消息服务的类别
          0,
          0,
          source_addr, //源地 址
          0,
          0,
          desti_addr, //目的地 址
          0, //短消息类 型
          0,
          0,
          null,
          null,
          0,
          1,
          0,
          0,
          message.getBytes("ISO-8859-1").length,
          message);
      try {
        SmppEncoder smppEncoderHe = new SmppEncoder();
        smppEncoderHe.smppHeader(smppHeader); //对smppHeader进行编码
        SmppEncoder smppEncoderSub = new SmppEncoder();
        smppEncoderSub.submit(submit); //对submit进行编码
        // byte[] abyte0=smppEncoderHe.getBytes();
        // byte[] abyte1=smppEncoderSub.getBytes();
        //byte[] abyte2=new byte[abyte0.length+abyte1.length];
        //for(int i = 0; i < abyte0.length; i++)
        //         abyte2[i] = abyte0[i];
        //for(int j = 0; j < abyte1.length; j++)
        //        abyte2[j + abyte0.length] = abyte1[j];
        sock.sendPacket(smppEncoderHe.getBytes());
        sock.sendPacket(smppEncoderSub.getBytes());
        //System.out.println("abyte2.length:"+abyte2.length);
        //System.out.println(2 * (new Date()).toString().getBytes().length);
        System.out.println(smppEncoderHe.getBytes().length);
        //System.out.println((new Date()).toString());
        System.out.println(smppEncoderSub.getBytes().length);
        //sock.sendPacket(abyte2);
      }
      catch (encoderException ee) {
        ee.printStackTrace();
      }

    }
    catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
  }

//---------------------------------------------------------------------
//读取从短消息中心发来的信息的函数
//--------------------------------------------------------------------
  byte[] read(int i) throws IOException {
    int j = 0;
    byte abyte0[] = new byte[i];
    try {
      int k;
      for (; j < i; j += k) {
        if ( (k = Sock.getSock().in.read(abyte0, j, i - j)) == -1) {
          throw new IOException("SMSC Connection closed (remotely)");
        }
      }
      return abyte0;
    }
    catch (IOException ioexception) {
      return abyte0;
      //throw ioexception;
    }
  }

//--------------------------------------------------------------------
//向服务器发送断开请求
//--------------------------------------------------------------------
  void jButtonDisconnect_actionPerformed(ActionEvent e) {

    SmppHeader smppHeader = new SmppHeader(16, ESME_UBD, 0, j_no);
    //Unbind unbind=new Unbind(smppHeader);
    SmppEncoder smppEncoder = new SmppEncoder();
    try {
      smppEncoder.smppHeader(smppHeader);
    }
    catch (encoderException ex) {
      ex.printStackTrace();
    }
    sock.sendPacket(smppEncoder.getBytes());
    //System.out.println(smppEncoder.getBytes().length);
  }

//----------------------------------------------------------------------
//获取Sequence_no的值
//----------------------------------------------------------------------
  public static int getSequence_no()
  {return j_no;}
  public static void setSequence_no()
  {j_no++;}

  public static void setVectorValue(int index,SmObject smobject)
  {
    vector_sm.put(String.valueOf(index),smobject);
  }
//--------------------------------------------------------------------
//确认连接状况
//----------------------------------------------------------------------
  void jButtonok_actionPerformed(ActionEvent e) {
    SmppHeader smppHeader = new SmppHeader(16, ESME_QRYLINK, 0, j_no);
    SmppEncoder smppEncoder = new SmppEncoder();
    try {
      smppEncoder.smppHeader(smppHeader);
    }
    catch (encoderException ex) {
      ex.printStackTrace();
    }
    sock.sendPacket(smppEncoder.getBytes());
  }

//--------------------------------------------------------------------
//增加用户命令
//--------------------------------------------------------------------
  void jButtonadduser_actionPerformed(ActionEvent e) {
    SmppHeader smppHeader = new SmppHeader(45, ESME_ADD_SUB, 0, j_no);
    String number = "12345";
    try {
      byte[] abyte = number.getBytes("ISO-8859-1");
      number = new String(abyte);
    }
    catch (UnsupportedEncodingException ex) {}

    AddUser addUser = new AddUser(number,
                                  "liao",
                                  "zcitt",
                                  102,
                                  0,
                                  0,
                                  1,
                                  0,
                                  0,
                                  "abcde"
                                  );
    try {
      SmppEncoder smppEncoder = new SmppEncoder();
      smppEncoder.smppHeader(smppHeader);
      SmppEncoder smppEncoder1 = new SmppEncoder();
      smppEncoder1.addUser(addUser);

⌨️ 快捷键说明

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