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

📄 sgip_command.java

📁 短信服务的源码,可以连接联通SMG等短信网关进行短信发送
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name:   SGIP_Command.java

package spApi;

import java.io.*;

// Referenced classes of package spApi:
//            MsgHead, Seq, SubmitResp, Deliver,
//            Bind, BindResp, Unbind, UnbindResp,
//            Report, TraceResp, Userrpt

public class SGIP_Command
{

    protected byte bodybytes[];
    protected MsgHead head;
    protected int TotalLength;
    protected static Seq seq = null;
    public static final int LEN_SGIP_HEADER = 20;
    public static final int LEN_SGIP_BIND = 41;
    public static final int LEN_SGIP_BIND_RESP = 9;
    public static final int LEN_SGIP_UNBIND = 0;
    public static final int LEN_SGIP_UNBIND_RESP = 0;
    public static final int LEN_SGIP_SUBMIT = 123;
    public static final int LEN_SGIP_SUBMIT_RESP = 9;
    public static final int LEN_SGIP_DELIVER = 57;
    public static final int LEN_SGIP_DELIVER_RESP = 9;
    public static final int LEN_SGIP_REPORT = 44;
    public static final int LEN_SGIP_REPORT_RESP = 9;
    public static final int LEN_SGIP_USERRPT = 51;
    public static final int LEN_SGIP_USERRPT_RESP = 9;
    public static final int LEN_SGIP_TRACE = 41;
    public static final int LEN_SGIP_TRACE_RESP = 48;
    public static final int LEN_MAX_CONTENT = 160;
    public static final int TIMEOUT = 60000;
    public static final int SUBMIT_OK = 0;
    public static final int SUBMIT_ERROR_STRUCTURE = 1;
    public static final int SUBMIT_ERROR_COMMANDTYPE = 2;
    public static final int SUBMIT_ERROR_SEQ_DUPLICATE = 3;
    public static final int SUBMIT_ERROR_MSG_LENGTH = 4;
    public static final int SUBMIT_ERROR_FEECODE = 5;
    public static final int SUBMIT_ERROR_CONTENT_LENGTH_EXCEED = 6;
    public static final int SUBMIT_ERROR_SERVERID = 7;
    public static final int SUBMIT_ERROR_FLOW_CONTROL = 8;
    public static final int SUBMIT_ERROR_OTHERS = 9;
    public static final int ID_SGIP_BIND = 1;
    public static final int ID_SGIP_BIND_RESP = 0x80000001;
    public static final int ID_SGIP_UNBIND = 2;
    public static final int ID_SGIP_UNBIND_RESP = 0x80000002;
    public static final int ID_SGIP_SUBMIT = 3;
    public static final int ID_SGIP_SUBMIT_RESP = 0x80000003;
    public static final int ID_SGIP_DELIVER = 4;
    public static final int ID_SGIP_DELIVER_RESP = 0x80000004;
    public static final int ID_SGIP_REPORT = 5;
    public static final int ID_SGIP_REPORT_RESP = 0x80000005;
    public static final int ID_SGIP_USERRPT = 17;
    public static final int ID_SGIP_USERRPT_RESP = 0x80000011;
    public static final int ID_SGIP_TRACE = 4096;
    public static final int ID_SGIP_TRACE_RESP = 0x80001000;
    public static final int MSG_TYPE_ASCII = 0;
    public static final int MSG_TYPE_WRITECARD = 3;
    public static final int MSG_TYPE_BINARY = 4;
    public static final int MSG_TYPE_UCS2 = 8;
    public static final int MSG_TYPE_CHINESE = 15;
    public static final int READ_SGIP_INVALID = 0;
    public static final int READ_SGIP_DELIVER = 1;
    public static final int READ_SGIP_REPORT = 2;
    public static final int READ_SGIP_USERRPT = 3;
    public static final int READ_SGIP_UNBIND = 4;

    public SGIP_Command()
    {
        TotalLength = 0;
        head = new MsgHead();
        if(seq == null)
            seq = new Seq();
    }

    public SGIP_Command(long l)
    {
        TotalLength = 0;
        head = new MsgHead();
        if(seq == null)
            seq = new Seq();
        seq.setNodeId(l);
    }

    public SGIP_Command(MsgHead msghead)
    {
        TotalLength = 0;
        head = msghead;
        if(seq == null)
            seq = new Seq();
    }

    public SGIP_Command(SGIP_Command sgip_command)
    {
        TotalLength = 0;
        head = sgip_command.head;
        bodybytes = sgip_command.bodybytes;
        TotalLength = sgip_command.TotalLength;
        seq = seq;
    }

    public SGIP_Command(long l, int i, int j, int k, int i1)
    {
        TotalLength = 0;
        if(seq == null)
            seq = new Seq(i, j);
        seq.setNodeId(l);
        TotalLength = 20 + k;
        head = new MsgHead();
        head.setTotalLength(TotalLength);
        head.setCommandID(i1);
        head.setSeq_1(seq.getGlobalSeq_1());
        head.setSeq_2(seq.getGlobalSeq_2());
        head.setSeq_3(seq.getGlobalSeq_3());
        bodybytes = new byte[k];
    }

    public SGIP_Command(MsgHead msghead, int i, int j)
    {
        TotalLength = 0;
        if(seq == null)
            seq = new Seq();
        TotalLength = 20 + i;
        head = new MsgHead();
        head.setTotalLength(TotalLength);
        head.setCommandID(j);
        head.setSeq_1(msghead.getSeq_1());
        head.setSeq_2(msghead.getSeq_2());
        head.setSeq_3(msghead.getSeq_3());
        bodybytes = new byte[i];
    }

    public SGIP_Command(long l, int i, int j)
    {
        TotalLength = 0;
        if(seq == null)
            seq = new Seq();
        seq.setNodeId(l);
        TotalLength = 20 + i;
        head = new MsgHead();
        head.setTotalLength(TotalLength);
        head.setCommandID(j);
        head.setSeq_1(seq.getGlobalSeq_1());
        head.setSeq_2(seq.getGlobalSeq_2());
        head.setSeq_3(seq.getGlobalSeq_3());
        bodybytes = new byte[i];
    }

    public SGIP_Command(int i, int j)
    {
        TotalLength = 0;
        if(seq == null)
            seq = new Seq();
        TotalLength = 20 + i;
        head = new MsgHead();
        head.setTotalLength(TotalLength);
        head.setCommandID(j);
        head.setSeq_1(seq.getGlobalSeq_1());
        head.setSeq_2(seq.getGlobalSeq_2());
        head.setSeq_3(seq.getGlobalSeq_3());
        bodybytes = new byte[i];
    }

    public int write(OutputStream outputstream)
    {
        try
        {
            byte abyte0[] = new byte[TotalLength];
            synchronized(Seq.seqclass)
            {
                Seq.computeSequence();
                head.setSeq_2(seq.getGlobalSeq_2());
                head.setSeq_3(seq.getGlobalSeq_3());
            }
            BytesCopy(head.Head, abyte0, 0, 19, 0);
            BytesCopy(bodybytes, abyte0, 0, TotalLength - 20 - 1, 20);
            outputstream.write(abyte0);
            return 0;
        }
        catch(Exception exception)
        {
            System.out.println(exception.toString());
        }
        return -1;
    }

    public SGIP_Command read(InputStream inputstream)
        throws IOException, Exception
    {
        try {
          head.read(inputstream);
        }
        catch (Exception ex) {
          System.out.println("-------head.read 异常:" + ex.toString());
        }
        try {
          readdataintobody(inputstream);
        }
        catch (IOException ex1) {
          System.out.println("-------readdataintobody 异常:" + ex1.toString());
        }
        catch (Exception ex1) {
          System.out.println("-------readdataintobody 异常:" + ex1.toString());
        }
        switch(head.getCommandID())
        {
        case -2147483645:
            return new SubmitResp(this);

        case 4: // '\004'
            return new Deliver(this);

        case 1: // '\001'
            return new Bind(this);

        case -2147483647:
            return new BindResp(this);

        case 2: // '\002'
            return new Unbind(this);

        case -2147483646:
            return new UnbindResp(this);

        case 5: // '\005'
            return new Report(this);

        case -2147479552:
            return new TraceResp(this);

        case 17: // '\021'
            return new Userrpt(this);
        }
        return null;
    }

    private void readdataintobody(InputStream inputstream)
        throws IOException, Exception
    {
        TotalLength = head.getTotalLength();
        System.out.println("-----readdataintobody TotalLength:" + TotalLength);
        bodybytes = new byte[TotalLength - 20];
        inputstream.read(bodybytes);
    }

    public int getTotalLength()
    {
        return head.getTotalLength();
    }

    public long getSeqno_1()
    {
        return head.getSeq_1();
    }

    public int getSeqno_2()
    {
        return head.getSeq_2();
    }

    public int getSeqno_3()
   {
        return head.getSeq_3();
    }

    public MsgHead getMsgHead()
    {
        return head;
    }

    public void setSeqno_1(long l)
    {
        head.setSeq_1(l);
    }

    public int getCommandID()
    {
        return head.getCommandID();
    }

    protected static int ByteToInt(byte byte0)
    {
        return byte0;
    }

    protected static byte IntToByte(int i)
    {
        return (byte)i;
    }

    protected static int BytesToInt(byte abyte0[])
    {
        return ((0xff & abyte0[0]) << 8) + abyte0[1];
    }

    protected static byte[] IntToBytes(int i)
    {
        byte abyte0[] = new byte[2];
        abyte0[1] = (byte)(0xff & i);
        abyte0[0] = (byte)((0xff00 & i) >> 8);
        return abyte0;
    }

    protected static byte[] IntToBytes4(int i)
    {
        byte abyte0[] = new byte[4];
        abyte0[3] = (byte)(0xff & i);
        abyte0[2] = (byte)((0xff00 & i) >> 8);
        abyte0[1] = (byte)((0xff0000 & i) >> 16);
        abyte0[0] = (byte)((0xff000000 & i) >> 24);
        return abyte0;
    }

    protected static byte[] LongToBytes4(long l)
    {
        byte abyte0[] = new byte[4];
        abyte0[3] = (byte)(int)(255L & l);
        abyte0[2] = (byte)(int)((65280L & l) >> 8);
        abyte0[1] = (byte)(int)((0xff0000L & l) >> 16);
        abyte0[0] = (byte)(int)((0xffffffffff000000L & l) >> 24);
        return abyte0;
    }

    protected static void LongToBytes4(long l, byte abyte0[])
    {
        abyte0[3] = (byte)(int)(255L & l);
        abyte0[2] = (byte)(int)((65280L & l) >> 8);
        abyte0[1] = (byte)(int)((0xff0000L & l) >> 16);
        abyte0[0] = (byte)(int)((0xffffffffff000000L & l) >> 24);
    }

    protected static void IntToBytes(int i, byte abyte0[])
    {
        abyte0[1] = (byte)(0xff & i);
        abyte0[0] = (byte)((0xff00 & i) >> 8);
    }

    protected static void IntToBytes4(int i, byte abyte0[])
    {
        abyte0[3] = (byte)(0xff & i);
        abyte0[2] = (byte)((0xff00 & i) >> 8);
        abyte0[1] = (byte)((0xff0000 & i) >> 16);
        abyte0[0] = (byte)(int)((0xffffffffff000000L & (long)i) >> 24);
    }

    protected static int Bytes4ToInt(byte abyte0[])
    {
        return (0xff & abyte0[0]) << 24 | (0xff & abyte0[1]) << 16 | (0xff & abyte0[2]) << 8 | 0xff & abyte0[3];
    }

    protected static long Bytes4ToLong(byte abyte0[])
    {
        return (255L & (long)abyte0[0]) << 24 | (255L & (long)abyte0[1]) << 16 | (255L & (long)abyte0[2]) << 8 | 255L & (long)abyte0[3];
    }

    protected static void BytesCopy(byte abyte0[], byte abyte1[], int i, int j, int k)
    {
        int i1 = 0;
        for(int l = i; l <= j; l++)
        {
            abyte1[k + i1] = abyte0[l];
            i1++;
        }

    }

}

⌨️ 快捷键说明

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