/// <summary> /// 打包包头 /// </summary> /// <returns></returns> protected byte[] Header(CmppHeaderModel _head) { ArrayList al = new ArrayList(this.Uint4ToBytes(_head.Total_Length)); al.AddRange(this.Uint4ToBytes(_head.Command_Id)); al.AddRange(this.Uint4ToBytes(_head.Sequence_Id)); return(al.ToArray(typeof(byte)) as byte[]); }
public override byte[] Encode() { CmppHeaderModel head = new CmppHeaderModel(); head.Command_Id = (uint)Cmpp_Command.CMPP_TERMINATE; head.Total_Length = GlobalModel.HeaderLength; head.Sequence_Id = Tools.GetSequence_Id(); return(this.Header(head)); }
public override void Decode(System.IO.BinaryReader br) { CmppHeaderModel hh = new CmppHeaderModel(); hh.Total_Length = (uint)this.ReadInt(br, 4); hh.Command_Id = (uint)this.ReadInt(br, 4); hh.Sequence_Id = (uint)this.ReadInt(br, 4); this.Header = hh; }
public override byte[] Encode() { CmppHeaderModel head = new CmppHeaderModel(); head.Command_Id = (uint)Cmpp_Command.CMPP_ACTIVE_TEST_RESP; head.Total_Length = GlobalModel.HeaderLength + 1; _reserved = head.Sequence_Id = SequenceId; byte[] headb = this.Header(head); ArrayList al = new ArrayList(headb); al.AddRange(this.Uint1ToBytes(_reserved)); return(al.ToArray(typeof(byte)) as byte[]); }
public override byte[] Encode() { CmppHeaderModel head = new CmppHeaderModel(); head.Command_Id = (uint)Cmpp_Command.CMPP_DELIVER_RESP; head.Total_Length = GlobalModel.HeaderLength + 9; head.Sequence_Id = _seq; byte[] headb = this.Header(head); ArrayList al = new ArrayList(headb); al.AddRange(this.Uint64ToBytes(_msg_Id, 8)); al.AddRange(this.Uint1ToBytes(_result)); return(al.ToArray(typeof(byte)) as byte[]); }
public override byte[] Encode() { ArrayList body = new ArrayList(); body.AddRange(this.UintToBytes(_submit.Msg_Id, 8)); body.AddRange(this.Uint1ToBytes(_submit.Pk_total)); body.AddRange(this.Uint1ToBytes(_submit.Pk_number)); body.AddRange(this.Uint1ToBytes(_submit.Registered_Delivery)); body.AddRange(this.Uint1ToBytes(_submit.Msg_level)); body.AddRange(this.StringToBytes(_submit.Service_Id, 10)); body.AddRange(this.Uint1ToBytes(_submit.Fee_UserType)); body.AddRange(this.UintToBytes(_submit.Fee_terminal_Id, 21)); body.AddRange(this.Uint1ToBytes(_submit.TP_pId)); body.AddRange(this.Uint1ToBytes(_submit.TP_udhi)); body.AddRange(this.Uint1ToBytes(_submit.Msg_Fmt)); body.AddRange(this.StringToBytes(_submit.Msg_src, 6)); body.AddRange(this.StringToBytes(_submit.FeeType, 2)); body.AddRange(this.StringToBytes(_submit.FeeCode, 6)); body.AddRange(this.StringToBytes(_submit.ValId_Time, 17)); body.AddRange(this.StringToBytes(_submit.At_Time, 17)); body.AddRange(this.StringToBytes(_submit.Src_Id, 21)); body.AddRange(this.Uint1ToBytes(_submit.DestUsr_tl)); body.AddRange(this.StringToBytes(_submit.Dest_terminal_Id, 21)); byte[] msgb = Tools.MsgContentToBytes(_submit.Msg_Content, (MsgContentFormat)_submit.Msg_Fmt); body.AddRange(this.Uint1ToBytes((uint)_submit.Msg_Length)); TP_UdhiHeader udhi = new TP_UdhiHeader(_submit.Pk_total, _submit.Pk_number);//长短信标识 body.AddRange(udhi.Encode()); body.AddRange(msgb); body.AddRange(this.StringToBytes(_submit.Reserve, 8)); byte[] bodybt = body.ToArray(typeof(byte)) as byte[]; //头 CmppHeaderModel head = new CmppHeaderModel(); head.Command_Id = (uint)Cmpp_Command.CMPP_SUBMIT; head.Total_Length = (uint)bodybt.Length + GlobalModel.HeaderLength; head.Sequence_Id = _submit.Sequence_Id; ArrayList submit = new ArrayList(this.Header(head)); submit.AddRange(bodybt); byte[] submitb = submit.ToArray(typeof(byte)) as byte[]; return(submitb); }
public override byte[] Encode() { //head CmppHeaderModel head = new CmppHeaderModel(); head.Command_Id = (uint)Cmpp_Command.CMPP_CONNECT; head.Total_Length = GlobalModel.HeaderLength + 27; head.Sequence_Id = Tools.GetSequence_Id(); byte[] headb = this.Header(head); ArrayList al = new ArrayList(headb); //body byte[] timeStampbytes = this.Uint4ToBytes(_cc.Timestamp); string source_addr = _cc.Source_Addr.Length > 6 ? _cc.Source_Addr.Substring(0, 6) : _cc.Source_Addr;//企业id长度6 string ts = _cc.Timestamp.ToString(); if (ts.Length == 9) { ts = "0" + ts; } //f1 string authenticatorSource = source_addr + "\0\0\0\0\0\0\0\0\0" + _cc.Password + ts; byte[] authenticatorSourcebytes_test = Tools.GetMd5Bytes(authenticatorSource); //f2 Source_Addr=002122,Timestamp=812184445,Version=20 // source_addr = "002122"; // _cc.Password = "******"; // ts = "812184445"; ArrayList aslist = new ArrayList(Encoding.ASCII.GetBytes(source_addr)); aslist.AddRange(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }); aslist.AddRange(Encoding.ASCII.GetBytes(_cc.Password)); aslist.AddRange(Encoding.ASCII.GetBytes(ts)); byte[] authenB = aslist.ToArray(typeof(byte)) as byte[]; MD5 md5 = new MD5CryptoServiceProvider(); byte[] authenBs = md5.ComputeHash(authenB); SMSLog.Log("CMPP_CONNECT==>Source_Addr=" + source_addr + ",Timestamp=" + ts + ",Password="******",authenBs=" + Encoding.ASCII.GetString(authenBs)); //f3 byte[] authenticatorSourcebytes = Tools.MakeMd5AuthCode(_cc.Source_Addr, _cc.Password.ToString(), ts); byte[] verbyte = Uint1ToBytes(_cc.Version); //new byte[1]; // verbyte[0] =(byte) _cc.Version; // Array.Reverse(verbyte); //byte[] sourceb = Encoding.ASCII.GetBytes(source_addr); // byte[] sourceb = new byte[6]; // byte[] byteaddr=Encoding.ASCII.GetBytes(source_addr); // Array.Copy(byteaddr, sourceb, byteaddr.Length); //byte[] sourceb = Encoding.ASCII.GetBytes(source_addr); al.AddRange(StringToBytes(source_addr, 6)); //for (int i = 0; i < 6-source_addr.Length;i++ ) //{ // al.AddRange(new byte[] { 0 }); //} al.AddRange(authenBs); al.AddRange(verbyte); al.AddRange(timeStampbytes); byte[] resultbyte = al.ToArray(typeof(byte)) as byte[]; Console.WriteLine("Source_Addr=" + _cc.Source_Addr + ",Timestamp=" + _cc.Timestamp + ",Version=" + _cc.Version); return(resultbyte); }