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

📄 sgip.cs

📁 联通的SGIP发送代码
💻 CS
📖 第 1 页 / 共 5 页
字号:
        private byte _result; //1, Trace命令在该节点是否成功接收。十六进制数字 0:接收成功 1:等待处理 其它:错误码
        private string _nodeId = ""; //6, 节点编号
        private string _receiveTime = ""; //16, 被跟踪的短消息到达该节点时刻,格式为“yymmddhhmmss”
        private string _sendTime = ""; //16, 该节点发出被跟踪的短消息时刻,格式为“yymmddhhmmss”
        private byte[] _reserved = new byte[8]; //保留,扩展用

        /// <summary>
        /// 被跟踪MT短消息经过的节点个数,当被跟踪短消息经过多个节点时,以下各个字段可重复
        /// </summary>
        public byte Count
        {
            get
            {
                return _count;
            }
            set
            {
                _count = value;
            }
        }

        /// <summary>
        /// Trace命令在该节点是否成功接收。十六进制数字 0:接收成功 1:等待处理 其它:错误码
        /// </summary>
        public byte Result
        {
            get
            {
                return _result;
            }
            set
            {
                _result = value;
            }
        }

        /// <summary>
        /// 节点编号
        /// </summary>
        public string NodeId
        {
            get { return _nodeId; }
            set
            {
                SgipHelper.CheckMaxBytes(value, 6);
                _nodeId = value;
            }
        }

        /// <summary>
        /// 被跟踪的短消息到达该节点时刻,格式为“yymmddhhmmss”
        /// </summary>
        public string ReceiveTime
        {
            get { return _receiveTime; }
            set
            {
                SgipHelper.CheckMaxBytes(value, 16);
                _receiveTime = value;
            }
        }

        /// <summary>
        /// 该节点发出被跟踪的短消息时刻,格式为“yymmddhhmmss”
        /// </summary>
        public string SendTime
        {
            get { return _sendTime; }
            set
            {
                SgipHelper.CheckMaxBytes(value, 16);
                _sendTime = value;
            }
        }

        /// <summary>
        /// 保留,最多8个字节
        /// </summary>
        public byte[] Reserved
        {
            get { return _reserved; }
            set
            {
                SgipHelper.CheckMaxBytes(value, 8);
                _reserved = value;
            }
        }

        public override uint GetCommandID()
        {
            return Command.SGIP_TRACE_RESP;
        }

        public override byte[] GetBytes()
        {
            byte[] buffer = new byte[this.GetLength()];
            int nIndex = 0;
            buffer[nIndex++] = _count;
            buffer[nIndex++] = _result;
            Encoding.ASCII.GetBytes(_nodeId).CopyTo(buffer, nIndex);
            nIndex += 6;
            Encoding.ASCII.GetBytes(_receiveTime).CopyTo(buffer, nIndex);
            nIndex += 16;
            Encoding.ASCII.GetBytes(_sendTime).CopyTo(buffer, nIndex);
            nIndex += 16;
            _reserved.CopyTo(buffer, nIndex);
            return buffer;
        }

        public override int GetLength()
        {
            return 48;
        }

        internal override void ReadFromBytes(byte[] buffer, int startIndex)
        {
            int nIndex = startIndex;
            _count = buffer[nIndex++];
            _result = buffer[nIndex++];
            _nodeId = SgipHelper.GetASCIIString(buffer, nIndex, 6);
            nIndex += 6;
            _receiveTime = SgipHelper.GetASCIIString(buffer, nIndex, 16);
            nIndex += 16;
            _sendTime = SgipHelper.GetASCIIString(buffer, nIndex, 16);
            nIndex += 16;
            Buffer.BlockCopy(buffer, nIndex, _reserved, 0, 8);
        }
    }

    /// <summary>
    /// 自定义的命令
    /// </summary>
    public class KeepAlive : Body
    {
        public override uint GetCommandID()
        {
            return Command.SGIP_KEEPALIVE;
        }
    }

    /// <summary>
    /// 自定义的命令
    /// </summary>
    public class KeepAlive_Resp : Body
    {
        public override uint GetCommandID()
        {
            return Command.SGIP_KEEPALIVE_RESP;
        }
    }

    public class Command
    {
        #region 命令ID
        public const uint SGIP_BIND = 0x1;
        public const uint SGIP_BIND_RESP = 0x80000001;
        public const uint SGIP_UNBIND = 0x2;
        public const uint SGIP_UNBIND_RESP = 0x80000002;
        public const uint SGIP_SUBMIT = 0x3;
        public const uint SGIP_SUBMIT_RESP = 0x80000003;
        public const uint SGIP_DELIVER = 0x4;
        public const uint SGIP_DELIVER_RESP = 0x80000004;
        public const uint SGIP_REPORT = 0x5;
        public const uint SGIP_REPORT_RESP = 0x80000005;
        public const uint SGIP_ADDSP = 0x6;
        public const uint SGIP_ADDSP_RESP = 0x80000006;
        public const uint SGIP_MODIFYSP = 0x7;
        public const uint SGIP_MODIFYSP_RESP = 0x80000007;
        public const uint SGIP_DELETESP = 0x8;
        public const uint SGIP_DELETESP_RESP = 0x80000008;
        public const uint SGIP_QUERYROUTE = 0x9;
        public const uint SGIP_QUERYROUTE_RESP = 0x80000009;
        public const uint SGIP_ADDTELESEG = 0xa;
        public const uint SGIP_ADDTELESEG_RESP = 0x8000000a;
        public const uint SGIP_MODIFYTELESEG = 0xb;
        public const uint SGIP_MODIFYTELESEG_RESP = 0x8000000b;
        public const uint SGIP_DELETETELESEG = 0xc;
        public const uint SGIP_DELETETELESEG_RESP = 0x8000000c;
        public const uint SGIP_ADDSMG = 0xd;
        public const uint SGIP_ADDSMG_RESP = 0x8000000d;
        public const uint SGIP_MODIFYSMG = 0xe;
        public const uint SGIP_MODIFYSMG_RESP = 0x0000000e;
        public const uint SGIP_DELETESMG = 0xf;
        public const uint SGIP_DELETESMG_RESP = 0x8000000f;
        public const uint SGIP_CHECKUSER = 0x10;
        public const uint SGIP_CHECKUSER_RESP = 0x80000010;
        public const uint SGIP_USERRPT = 0x11;
        public const uint SGIP_USERRPT_RESP = 0x80000011;
        public const uint SGIP_TRACE = 0x1000;
        public const uint SGIP_TRACE_RESP = 0x80001000;
        //下面两个命令是自定义的
        public const uint SGIP_KEEPALIVE = 0x10000001;
        public const uint SGIP_KEEPALIVE_RESP = 0x10000010;
        #endregion

        #region 错误代码
        /// <summary>
        /// 无错误,命令正确接收
        /// </summary>
        public const byte ERR_Success = 0; 
        public const byte ERR_InvalidLogin = 1; //非法登录,如登录名、口令出错、登录名与口令不符等。
        public const byte ERR_RepeatLogin = 2; //重复登录,如在同一TCP/IP连接中连续两次以上请求登录。
        public const byte ERR_TooMuchLink = 3; //连接过多,指单个节点要求同时建立的连接数过多。
        public const byte ERR_LoginTypeError = 4; //登录类型错,指bind命令中的logintype字段出错。
        public const byte ERR_ParFormatError = 5; //参数格式错,指命令中参数值与参数类型不符或与协议规定的范围不符。
        public const byte ERR_InvalidPhone = 6; //非法手机号码,协议中所有手机号码字段出现非86130号码或手机号码前未加"86"时都应报错。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
        public const byte ERR_MessageIDError = 7; //消息ID错
        public const byte ERR_MessageLenError = 8; //信息长度错
        public const byte ERR_InvalidSerialNo = 9; //非法序列号,包括序列号重复、序列号格式错误等
        public const byte ERR_InvalidOper = 10; //非法操作GNS
        public const byte ERR_ComputerBusy = 11; //节点忙,指本节点存储队列满或其他原因,暂时不能提供服务的情况
        public const byte ERR_DestCantReach = 21; //目的地址不可达,指路由表存在路由且消息路由正确但被路由的节点暂时不能提供服务的情况
        public const byte ERR_RoutError = 22; //路由错,指路由表存在路由但消息路由出错的情况,如转错SMG等
        public const byte ERR_RoutNotExist = 23; //路由不存在,指消息路由的节点在路由表中不存在
        public const byte ERR_FeeNoInvalid = 24; //计费号码无效,鉴权不成功时反馈的错误信息
        public const byte ERR_UserCantCommu = 25; //用户不能通信(如不在服务区、未开机等情况)
        public const byte ERR_MobileMemoLack = 26; //手机内存不足
        public const byte ERR_MobileNosupportSMG = 27; //手机不支持短消息
        public const byte ERR_MobileReceiError = 28; //手机接收短消息出现错误
        public const byte ERR_NoThisUser = 29; //不知道的用户
        public const byte ERR_NoThisFunction = 30; //不提供此功能
        public const byte ERR_InvalidDevice = 31; //非法设备
        public const byte ERR_SysError = 32; //系统失败
        public const byte ERR_SMGQueFull = 33; //短信中心队列满
        #endregion

        private Head _head = null;
        private Body _body = null;

        public Head Head
        {
            get { return _head; }
            set { _head = value; }
        }

        public Body Body
        {
            get { return _body; }
            set { _body = value; }
        }

        public int GetLength()
        {
            return _head.GetLength() + _body.GetLength();
        }

        public byte[] GetBytes()
        {
            byte[] result = new byte[this.GetLength()];
            Buffer.BlockCopy(_head.GetBytes(), 0, result, 0, _head.GetLength());
            Buffer.BlockCopy(_body.GetBytes(), 0, result, _head.GetLength(), _body.GetLength());
            return result;
        }

        internal void ReadFromBytes(byte[] buffer, int startIndex)
        {
            _head.ReadFromBytes(buffer, startIndex);
            _body.ReadFromBytes(buffer, startIndex + _head.GetLength());
        }

        /// <summary>
        /// 用户须调用 ToCommand或CreateCommand方法创建该类的对象
        /// </summary>
        internal Command()
        {
        }

        public static Command ToCommand(byte[] buffer, int startIndex)
        {
            Command cmd = new Command();
            cmd.Head = Head.ToHead(buffer, startIndex);
            switch (cmd.Head.CommandID)
            {
                case Command.SGIP_BIND:
                    cmd.Body = new Bind();
                    break;
                case Command.SGIP_BIND_RESP:
                    cmd.Body = new Bind_Resp();
                    break;
                case Command.SGIP_UNBIND:
                    cmd.Body = new Unbind();
                    break;
                case Command.SGIP_UNBIND_RESP:
                    cmd.Body = new Unbind_Resp();
                    break;
                case Command.SGIP_SUBMIT:
                    cmd.Body = new Submit();
                    break;
                case Command.SGIP_SUBMIT_RESP:
                    cmd.Body = new Submit_Resp();
                    break;
                case Command.SGIP_DELIVER:
                    cmd.Body = new Deliver();
                    break;
                case Command.SGIP_DELIVER_RESP:
                    cmd.Body = new Deliver_Resp();
                    break;
                case Command.SGIP_REPORT:
                    cmd.Body = new Report();
                    break;
                case Command.SGIP_REPORT_RESP:
                    cmd.Body = new Report_Resp();
                    break;
                case Command.SGIP_TRACE:
                    cmd.Body = new Trace();
                    break;
                case Command.SGIP_TRACE_RESP:
                    cmd.Body = new Trace_Resp();
                    break;
                case Command.SGIP_USERRPT:
                    cmd.Body = new UserRpt();
                    break;
                case Command.SGIP_USERRPT_RESP:
                    cmd.Body = new UserRpt_Resp();
                    break;
                case Command.SGIP_KEEPALIVE:
                    cmd.Body = new KeepAlive();
                    break;
                case Command.SGIP_KEEPALIVE_RESP:
                    cmd.Body = new KeepAlive_Resp();
                    break;
                default:
                    throw new InvalidCastException("未知命令!无法解析.");
            } // end of switch
            cmd.Body.ReadFromBytes(buffer, startIndex + cmd.Head.GetLength());
            return cmd;
        }

        /// <summary>
        /// 创建一个命令,多在发送命令时用
        /// </summary>
        /// <param name="body"></param>
        /// <returns></returns>
        public static Command CreateCommand(Body body)
        {
            return Command.CreateCommand(SequenceNumber.CreateSequenceNumber(), body);
        }

        /// <summary>
        /// 创建一个命令(多在应答时用)
        /// </summary>
        /// <param name="sequenceNumber"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public static Command CreateCommand(SequenceNumber sequenceNumber, Body body)
        {
            Command cmd = new Command();
            cmd.Body = body;

            cmd.Head = new Head();
            cmd.Head.CommandID = body.GetCommandID();
            cmd.Head.MessageLength = (uint)cmd.GetLength();
            cmd.Head.SequenceNumber.Assign(sequenceNumber);

            return cmd;
        }
    }

}

⌨️ 快捷键说明

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