SMGP协议之Deliver

    /// <summary>
    /// 功能:SMGW向SP下发短信
    /// 作者:吕永义
    /// 时间:2011年3月31日
    /// </summary>
    public class Deliver
    {
     
        #region 参数

        /// <summary>
        /// 消息头
        /// </summary>
        private MessageHeader msgHeader;

        /// <summary>
        /// 消息头
        /// </summary>
        public MessageHeader MsgHeader
        {
            get { return msgHeader; }
            set { msgHeader = value; }
        }

        /**
         * 本人不会BCD的编码和解码 所以msgID 依然保持byte数组类型
         *

            private string msgID;


            public string MsgID
            {
                get { return msgID; }
                set { msgID = value; }
            }
         *
         */

       
        private byte[] msgID;

        /// <summary>
        /// 消息流水号
        /// </summary>
        public byte[] MsgID
        {
            get { return msgID; }
            set { msgID = value; }
        }

        /// <summary>
        /// 是否为状态报告
        /// </summary>
        private uint isReport;

        /// <summary>
        /// 是否为状态报告
        /// </summary>
        public uint IsReport
        {
            get { return isReport; }
            set { isReport = value; }
        }

        /// <summary>
        /// 短消息格式
        /// </summary>
        private uint msgFormat;

        /// <summary>
        /// 短消息格式
        /// </summary>
        public uint MsgFormat
        {
            get { return msgFormat; }
            set { msgFormat = value; }
        }
      
        /// <summary>
        /// 短消息接收时间
        /// </summary>
        private string recvTime;

        /// <summary>
        /// 短消息接收时间
        /// </summary>
        public string RecvTime
        {
            get { return recvTime; }
            set { recvTime = value; }
        }

        /// <summary>
        /// 短消息发送号码
        /// </summary>
        private string srcTermID;

        /// <summary>
        /// 短消息发送号码
        /// </summary>
        public string SrcTermID
        {
            get { return srcTermID; }
            set { srcTermID = value; }
        }
      
        /// <summary>
        /// 短消息接收号码
        /// </summary>
        private string destTermID;

        /// <summary>
        /// 短消息接收号码
        /// </summary>
        public string DestTermID
        {
            get { return destTermID; }
            set { destTermID = value; }
        }

        /// <summary>
        /// 短消息长度
        /// </summary>
        private uint msgLength;

        /// <summary>
        /// 短消息长度
        /// </summary>
        public uint MsgLength
        {
            get { return msgLength; }
            set { msgLength = value; }
        }

        /// <summary>
        /// 短消息内容
        /// </summary>
        private string msgContent;

        /// <summary>
        /// 短消息内容
        /// </summary>
        public string MsgContent
        {
            get { return msgContent; }
            set { msgContent = value; }
        }
      
        /// <summary>
        /// 保留字段
        /// </summary>
        private string reserve;

        /// <summary>
        /// 保留字段
        /// </summary>
        public string Reserve
        {
            get { return reserve; }
            set { reserve = value; }
        }

        /// <summary>
        /// 状态报告
        /// </summary>
        private Report report;

        /// <summary>
        /// 状态报告
        /// </summary>
        public Report Report
        {
            get { return report; }
            set { report = value; }
        }


        #endregion

        #region 构造函数

        public Deliver(byte[] bytes)
        {
            #region MsgHeader

            int i = 0;
            byte[] buffer = new byte[MessageHeader.HeaderLength];
            Util.ByteCopyToByte(bytes, i, buffer, 0, 12);
            this.msgHeader = new MessageHeader(buffer);
            i += 12;

            #endregion

            #region MsgID

            buffer = new byte[10];
            Util.ByteCopyToByte(bytes, i, buffer, 0, 10);
            // this.msgID = BIConvert.Byte2String(buffer);
            // this.msgID = BIConvert.Bytes2ULong(buffer).ToString();
            // this.msgID = BIConvert.Byte2MsgID(buffer);

            this.msgID = buffer;

            i = i + 10;

            #endregion

            #region IsReport

            //buffer = new byte[1];
            //Util.ByteCopyToByte(bytes, i, buffer, 0, 1);
            //this.isReport = BIConvert.Bytes2UInt(buffer);
            //i++;
            this.isReport = bytes[i++];

            #endregion

            #region MsgFormat

            //buffer = new byte[1];
            //Util.ByteCopyToByte(bytes, i, buffer, 0, 1);
            //this.msgFormat = BIConvert.Bytes2UInt(buffer);
            //i++;
            this.msgFormat = bytes[i++];

            #endregion

            #region RecvTime

            buffer = new byte[14];
            Util.ByteCopyToByte(bytes, i, buffer, 0, 14);
            this.recvTime = BIConvert.Byte2String(buffer);
            i = i + 14;

            #endregion


            #region SrcTermID

            buffer = new byte[21];
            Util.ByteCopyToByte(bytes, i, buffer, 0, 21);
            this.srcTermID = BIConvert.Byte2String(buffer);
            i = i + 21;

            #endregion

            #region DestTermID

            buffer = new byte[21];
            Util.ByteCopyToByte(bytes, i, buffer, 0, 21);
            this.destTermID = BIConvert.Byte2String(buffer);
            i = i + 21;

            #endregion

            #region MsgLength

            //buffer = new byte[1];
            //Util.ByteCopyToByte(bytes, i, buffer, 0, 1);
            //this.msgLength = BIConvert.Bytes2UInt(buffer);
            //i++;
            this.msgLength = bytes[i++];

            #endregion

            //消息上行
            if (this.isReport.Equals(0))
            {
                #region MsgContent

                buffer = new byte[this.msgLength];

                Util.ByteCopyToByte(bytes, i, buffer, 0, buffer.Length);

                switch (this.msgFormat)
                {
                    case 8:
                        this.msgContent = Encoding.BigEndianUnicode.GetString(buffer).Trim();
                        break;
                    case 15:
                        this.msgContent = Encoding.GetEncoding("gb2312").GetString(buffer).Trim();
                        break;
                    case 0: //ascii
                    case 3://短信写卡操作
                    case 4://二进制信息
                    default:
                        this.msgContent = Encoding.ASCII.GetString(buffer).ToString();
                        break;
                }
                i += (int)this.msgLength;

                #endregion
            }
            //状态报告
            else if (this.isReport.Equals(1))
            {
                this.report = new Report();

                #region report.Id

                i = i + 3;
                buffer = new byte[10];
                Util.ByteCopyToByte(bytes, i, buffer, 0, 10);

                this.report.Id = buffer;
                i = i + 10;

 

                #endregion

                #region report.sub

                i = i + 5;
                buffer = new byte[3];
                Util.ByteCopyToByte(bytes, i, buffer, 0, 3);
                this.report.Sub = BIConvert.Byte2String(buffer);
                i = i + 3;

                #endregion

                #region report.Dlvrd

                i = i + 7;
                buffer = new byte[3];
                Util.ByteCopyToByte(bytes, i, buffer, 0, 3);
                this.report.Dlvrd = BIConvert.Byte2String(buffer);
                i = i + 3;


                #endregion

                #region report.submit_date

                i = i + 13;
                buffer = new byte[10];
                Util.ByteCopyToByte(bytes, i, buffer, 0, 10);
                this.report.Submit_date = BIConvert.Byte2String(buffer);
                i = i + 10;


                #endregion

                #region report.done_date

                i = i + 11;
                buffer = new byte[10];
                Util.ByteCopyToByte(bytes, i, buffer, 0, 10);
                this.report.Done_date = BIConvert.Byte2String(buffer);
                i = i + 10;

                #endregion

                #region report.stat
                i = i + 6;
                buffer = new byte[7];
                Util.ByteCopyToByte(bytes, i, buffer, 0, 7);
                this.report.Stat = BIConvert.Byte2String(buffer);
                i = i + 7;

                #endregion

                #region report.Err

                i = i + 5;
                buffer = new byte[3];
                Util.ByteCopyToByte(bytes, i, buffer, 0, 3);
                this.report.Err = BIConvert.Byte2String(buffer);
                i = i + 3;

                #endregion

                #region report.Txt

                i = i + 6;
                buffer = new byte[20];
                Util.ByteCopyToByte(bytes, i, buffer, 0, 20);
                this.report.Txt = Util.BytesToString(buffer);
                i = i + 20;

                #endregion

            }

            #region Reserve

            buffer = new byte[8];
            Util.ByteCopyToByte(bytes, i, buffer, 0, 8);
            this.reserve = BIConvert.Byte2String(buffer);
            i = i + 8;


            #endregion


        }

 

        #endregion


    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值