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

📄 cmpp3connect.java

📁 java支持的短信平台
💻 JAVA
字号:
package com.khan.sms.cmpp3;

import com.khan.util.MD5;
import com.khan.sms.MsgID;
import com.khan.util.SocketCommon;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Cmpp3Connect extends Cmpp3Data{
    String SourAddr="";
      String SharedSecret="";
      byte Version=0x0;
      int TimeStamp;
      //String time="";

      public Cmpp3Connect(String sour_addr, String share_secret, byte version) {
          this.SourAddr = sour_addr;
          this.SharedSecret = share_secret;
          this.Version = version;
          //this.TimeStamp = 922185555;
          this.TimeStamp= (int)com.khan.datetime.SMPTime.getDateTime(false);
      }



      /**
       * decodeCmpp
       *
       * @return Cmpp2Data
       */
      public Cmpp3Data decodeCmpp() {
          return this;
      }

      private byte[] getAuthString(String time){//取得登录认证码(转换前)
          byte[] user=SourAddr.getBytes();
          byte[] auth = SharedSecret.getBytes();
          byte[] timeStamp = time.getBytes();
          if(user==null||auth==null)
              return null;
          byte abyte2[] = new byte[100];
          System.arraycopy(user, 0, abyte2, 0, user.length);//icp
          int k = user.length+ 9;
          System.arraycopy(auth, 0, abyte2, k, auth.length);//keys
          k += auth.length;
          System.arraycopy(timeStamp, 0, abyte2, k, 10);//keys
          k += 10;
          byte auths[] = new byte[k];
          System.arraycopy(abyte2, 0,auths, 0, k);//keys
          return auths;
      }

      /**
       * encodeCmpp
       *
       * @return byte[]
       */
      public byte[] encodeCmpp(){
          if (this.SeqID <1){
            throw new IllegalArgumentException("消息SeqID未定义,请先指定SeqID!");
            //return null;
          }

          byte[] szAuthenticator_Source = null;
          byte[] tmp = new byte[64];

          for (int i = 0; i < tmp.length; i++)
            tmp[i]=0;


          int offset = 0;
          System.arraycopy(SourAddr.getBytes(),0 , tmp, offset, SourAddr.getBytes().length);
          offset += SourAddr.getBytes().length;
          offset += 9;
          System.arraycopy(SharedSecret.getBytes(),0 , tmp, offset, SharedSecret.getBytes().length);
          offset += SharedSecret.getBytes().length;

          String str_temp = String.valueOf(TimeStamp);
          if(!str_temp.startsWith("1")) str_temp = "0"+str_temp;
          System.arraycopy(str_temp.getBytes(),0 , tmp, offset, str_temp.getBytes().length);
          offset += str_temp.getBytes().length;
          //System.out.println(str_temp);
          byte[] auth =getAuthString(str_temp);
          MD5 md5 = new MD5();
          szAuthenticator_Source = md5.getMD5ofBytes(auth,auth.length);

          Data = new byte[SourAddr.getBytes().length + szAuthenticator_Source.length + 1 +4];
          offset = 0;
          System.arraycopy(SourAddr.getBytes(),0 , Data, offset, SourAddr.getBytes().length);
          offset += SourAddr.getBytes().length;

          System.arraycopy(szAuthenticator_Source,0 , Data, offset, szAuthenticator_Source.length);
          offset += szAuthenticator_Source.length;

          Data[offset] = Version;
          offset += 1;

          byte[] timetemp = SocketCommon.toByteArray(TimeStamp);
          System.arraycopy(timetemp, 0, Data, offset, timetemp.length);
          offset += timetemp.length;

          this.TotalLen = offset + 12;
          this.CommandID = Cmpp3Command.CMPP_CONNECT;

          byte[] szCmppData = new byte[TotalLen];

          offset = 0;

          tmp = SocketCommon.toByteArray( TotalLen);
          System.arraycopy(tmp, 0, szCmppData, offset, tmp.length);
          offset += tmp.length;

          tmp = SocketCommon.toByteArray(CommandID);
          System.arraycopy(tmp, 0, szCmppData, offset, tmp.length);
          offset += tmp.length;

          tmp = SocketCommon.toByteArray(SeqID);
          System.arraycopy(tmp, 0, szCmppData, offset, tmp.length);
          offset += tmp.length;

          tmp = Data;
          System.arraycopy(tmp, 0, szCmppData, offset, tmp.length);
          offset += tmp.length;

          return szCmppData;
      }

      public String toString() {
          return "CMPP3_CONNECT: SourAddr=" + SourAddr +" SharedSecret=" + SharedSecret
                  +" Version=" + Version + " TimeStamp=" + TimeStamp;
      }



}

⌨️ 快捷键说明

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