Exemple #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="head"></param>
 /// <param name="byts"></param>
 public override void ReadBytes(byte[] byts)
 {
     MyHead                 = CMPPMsgHeader.Read(byts);
     this.Status            = ReverseByteOrder.ReverseBytes(BitConverter.ToUInt32(byts, 12));
     this.AuthenticatorISMG = BitConverter.ToString(byts, 16, 16).Replace("-", "");
     Version                = byts[32];
 }
Exemple #2
0
        /// <summary>
        /// 从网络流中读取一个缓冲对象,对象大小由长度字段指定。
        /// </summary>
        /// <param name="ns"></param>
        /// <returns></returns>
        private byte[] readBuffer(System.Net.Sockets.NetworkStream ns)
        {
            System.IO.BinaryReader br = new System.IO.BinaryReader(ns);
            byte[] len        = br.ReadBytes(4);//头四个字节为命令长度
            uint   size       = ReverseByteOrder.ReverseBytes(BitConverter.ToUInt32(len, 0));
            int    buffersize = 0;

            if (size > 40960)//不处理大于40k的数据包
            {
                throw new Exception("数据大于40K");
            }
            else
            {
                buffersize = (int)size;
            }
            byte[] result = new byte[buffersize];
            int    count  = br.Read(result, 4, buffersize - 4);

            if (count != buffersize - 4)
            {
                throw new Exception("不完整的数据");
            }
            //将头长度拷贝入结果
            Buffer.BlockCopy(len, 0, result, 0, 4);
            return(result);
        }
Exemple #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="byts"></param>
 public void ReadMessage(byte[] byts)
 {
     Msg_Id           = ReverseByteOrder.ReverseBytes(BitConverter.ToUInt64(byts, 0));
     State            = Tools.BytesToString(byts, 8, 7);
     Submit_time      = Tools.BytesToString(byts, 15, 10);
     Done_time        = Tools.BytesToString(byts, 25, 10);
     Dest_terminal_Id = Tools.BytesToString(byts, 35, 32).TrimEnd('\0');
     SMSC_sequence    = ReverseByteOrder.ReverseBytes(BitConverter.ToUInt32(byts, 67));
 }
Exemple #4
0
        public override byte[] WriteBytes()
        {
            byte[] msg = new byte[MyHead.Total_Length];
            Tools.CopyAll(0, MyHead.Write(), ref msg);
            Tools.CopyAll(12, BitConverter.GetBytes(ReverseByteOrder.ReverseBytes(Msg_Id)), ref msg);
            Tools.CopyAll(20, BitConverter.GetBytes(ReverseByteOrder.ReverseBytes(Result)), ref msg);

            return(msg);
        }
Exemple #5
0
        public byte[] Write()
        {
            byte[] byts = new byte[12];

            Buffer.BlockCopy(BitConverter.GetBytes(ReverseByteOrder.ReverseBytes(Total_Length)), 0, byts, 0, 4);
            Buffer.BlockCopy(BitConverter.GetBytes(ReverseByteOrder.ReverseBytes((uint)Command_Id)), 0, byts, 4, 4);
            Buffer.BlockCopy(BitConverter.GetBytes(ReverseByteOrder.ReverseBytes(Sequence_Id)), 0, byts, 8, 4);

            return(byts);
        }
Exemple #6
0
        public static CMPPMsgHeader Read(byte[] byts)
        {
            if (byts.Length >= 12)
            {
                CMPPMsgHeader head = new CMPPMsgHeader();
                head.Total_Length = ReverseByteOrder.ReverseBytes(BitConverter.ToUInt32(byts, 0));
                head.Command_Id   = (Command_Id)ReverseByteOrder.ReverseBytes(BitConverter.ToUInt32(byts, 4));
                head.Sequence_Id  = ReverseByteOrder.ReverseBytes(BitConverter.ToUInt32(byts, 8));

                return(head);
            }
            return(null);
        }
Exemple #7
0
 public override void ReadBytes(byte[] byts)
 {
     MyHead              = CMPPMsgHeader.Read(byts);
     Msg_Id              = ReverseByteOrder.ReverseBytes(BitConverter.ToUInt64(byts, 12));
     Dest_Id             = Tools.BytesToString(byts, 20, 21);
     Service_Id          = Tools.BytesToString(byts, 41, 10);
     TP_pid              = byts[51];
     TP_udhi             = byts[52];
     Msg_Fmt             = byts[53];
     Src_terminal_Id     = Tools.BytesToString(byts, 54, 32);
     Src_terminal_type   = byts[86];
     Registered_Delivery = byts[87];
     Msg_Length          = byts[88];
     Msg_Content         = new byte[Msg_Length];
     Buffer.BlockCopy(byts, 89, Msg_Content, 0, Msg_Length);
 }
Exemple #8
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override byte[] WriteBytes()
        {
            byte[] msgByts      = new byte[MyHead.Total_Length];
            string strTimestamp = DateTime.Now.ToString("MMddHHmmss");

            Timestamp = UInt32.Parse(strTimestamp);
            //
            AuthenticatorSource = SP_ID + "\0\0\0\0\0\0\0\0\0" + _pwd + strTimestamp;
            //
            Tools.CopyAll(0, MyHead.Write(), ref msgByts);
            Tools.CopyAll(12, Tools.StringToBytes(SP_ID), ref msgByts, 6);
            Tools.CopyAll(18, MyMD5.GetMD5Byts_32(AuthenticatorSource), ref msgByts);
            msgByts[34] = Version;
            Tools.CopyAll(35, BitConverter.GetBytes(ReverseByteOrder.ReverseBytes(Timestamp)), ref msgByts);
            //
            return(msgByts);
        }
Exemple #9
0
 public override void ReadBytes(byte[] byts)
 {
     MyHead = CMPPMsgHeader.Read(byts);
     Msg_Id = ReverseByteOrder.ReverseBytes(BitConverter.ToUInt64(byts, 12));
     Result = (DeliverResult)ReverseByteOrder.ReverseBytes(BitConverter.ToUInt32(byts, 20));
 }