/// <summary> /// 获取请求的字节流 /// </summary> /// <returns></returns> public override byte[] ToBytes() { MsgHeader.TotalLength = MsgHeaderEnt.HeaderLength + 6 + 16 + 1 + 4; int i = 0; byte[] bytes = new byte[MsgHeader.TotalLength]; //header 12 byte[] buffer = MsgHeader.ToHeaderBytes(); Buffer.BlockCopy(buffer, 0, bytes, i, MsgHeaderEnt.HeaderLength); //Source_Addr 6 i += MsgHeaderEnt.HeaderLength; AddAsciiByteToBytes(SourceAddr, bytes, i); //AuthenticatorSource 16 i += 6; buffer = AuthenticatorSource; Buffer.BlockCopy(buffer, 0, bytes, i, 16); //16 //version 1 i += 16; bytes[i++] = (byte)Version; //版本 //Timestamp AddUInt4ByteToBytes(Timestamp, bytes, i); return(bytes); }
public override byte[] ToBytes() { MsgHeader.TotalLength = MsgHeaderEnt.HeaderLength + 1; int i = 0; byte[] bytes = new byte[MsgHeader.TotalLength]; byte[] buffer = MsgHeader.ToHeaderBytes(); Buffer.BlockCopy(buffer, 0, bytes, 0, buffer.Length); i += MsgHeaderEnt.HeaderLength; //Reserved bytes[i] = 0; return(bytes); }
/// <summary> /// /// </summary> /// <returns></returns> public override byte[] ToBytes() { MsgHeader.TotalLength = MsgHeaderEnt.HeaderLength; return(MsgHeader.ToHeaderBytes()); }
public override byte[] ToBytes() { //Msg_Length Msg_Content uint destTerminalIdLength = (uint)DestId.Length * 21; var msgContentBytes = GetContentByte(MsgFmt); MsgHeader.TotalLength = (uint)(MsgHeaderEnt.HeaderLength + FixedBodyLength + destTerminalIdLength + msgContentBytes.Length); int i = 0; byte[] bytes = new byte[MsgHeader.TotalLength]; byte[] buffer = MsgHeader.ToHeaderBytes(); Buffer.BlockCopy(buffer, 0, bytes, 0, buffer.Length); i += MsgHeaderEnt.HeaderLength; //Msg_Id //8 [12,19] // 发送时不需要填写 //buffer = BitConverter.GetBytes(MsgId); //Array.Reverse(buffer); //Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length); //_Pk_total i += 8; bytes[i++] = (byte)PkTotal; //[20,20] bytes[i++] = (byte)PkNumber; //[21,21] bytes[i++] = (byte)RegisteredDelivery; //[22,22] bytes[i++] = (byte)MsgLevel; //[23,23] //Service_Id AddAsciiByteToBytes(ServiceId, bytes, i); //Fee_UserType i += 10; bytes[i++] = (byte)FeeUserType; //[34,34] //Fee_terminal_Id 21 AddAsciiByteToBytes(FeeTerminalId, bytes, i); // i += 21; bytes[i++] = (byte)TpPId; //[56,56] bytes[i++] = (byte)TpUdhi; //[57,57] bytes[i++] = (byte)MsgFmt; //[58,58] //Msg_src AddAsciiByteToBytes(MsgSrc, bytes, i); //FeeType i += 6; AddAsciiByteToBytes(FeeType, bytes, i); //FeeCode i += 2; AddAsciiByteToBytes(FeeCode, bytes, i); //ValId_Time i += 6; AddAsciiByteToBytes(ValIdTime, bytes, i); //At_Time i += 17; AddAsciiByteToBytes(AtTime, bytes, i); //Src_Id i += 17; AddAsciiByteToBytes(SrcId, bytes, i); //DestUsr_tl i += 21; DestUsrTl = (uint)DestId.Length; bytes[i++] = (byte)DestUsrTl; //[128,128] //Dest_terminal_Id foreach (string s in DestId) { if (string.IsNullOrEmpty(s)) { continue; } AddAsciiByteToBytes(s, bytes, i); i += 21; } //Msg_Length bytes[i++] = (byte)msgContentBytes.Length; //Msg_Content Buffer.BlockCopy(msgContentBytes, 0, bytes, i, msgContentBytes.Length); //Reserve i += msgContentBytes.Length; AddAsciiByteToBytes(Reserve, bytes, i); return(bytes); }