public void TestDecompressString() { var stringHandlingPackets = new StringHandlingPackets(); stringHandlingPackets.Add(""); var result = GZipByteArray.DecompressString(stringHandlingPackets.GetBytes()); }
public void TestCompressBytes() { var input = "<?xml version='1.0' encoding='utf-8'?><msg templateID='12345' action='web' brief='芒果科技 的分享' serviceID='2' url='http://music.163.com/song/33668486/'> <item layout='2'> <audio src='http://m2.music.126.net/66NgS6mnDITOLBtojRlG2g==/3359008023015680.mp3' cover='http://www.qqmango.com/xz/baoshixit.png'/><title><![CDATA[[机器人昵称]为您报时]]></title><summary><![CDATA[[时间]]]></summary> </item> <item layout='0'><summary><![CDATA[[星期]-[农历]]]></summary></item> <source action='web' name='报时系统' icon='http://www.qqmango.com/xz/baoshixit.png' url='http://www.baidu.com'/></msg>"; var result = GZipByteArray.CompressBytes(input); var resultStr = Util.ToHex(result); }
/// <summary> /// 初始化包体 /// </summary> /// <param name="buf">The buf.</param> protected override void PutBody() { var _DateTime = Util.GetTimeSeconds(DateTime.Now); var _Md5 = user.QQ_SessionKey; if (_messageType == FriendMessageType.Xml) { var compressMsg = GZipByteArray.CompressBytes(Encoding.UTF8.GetString(_message)); bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x04 }); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }); bodyWriter.Write(new byte[] { 0x37, 0x0F }); bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(_Md5); bodyWriter.Write(new byte[] { 0x00, 0x0B }); bodyWriter.Write(Util.RandomKey(2)); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, _packetCount, _packetIndex, 0x00, 0x00, 0x01, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.Write(SendXML(_DateTime, compressMsg)); } else if (_messageType == FriendMessageType.Shake) { bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }); bodyWriter.Write(new byte[] { 0x37, 0x0F }); bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(Util.RandomKey()); bodyWriter.Write(new byte[] { 0x00, 0xAF }); bodyWriter.Write(Util.RandomKey(2)); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.Write(Util.RandomKey(4)); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }); } else if (_messageType == FriendMessageType.Message) { bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x0D, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x01 }); bodyWriter.Write(new byte[] { 0x36, 0x43 }); bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(_Md5); bodyWriter.Write(new byte[] { 0x00, 0x0B }); bodyWriter.Write(Util.RandomKey(2)); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(new byte[] { 0x02, 0x34, 0x00, 0x00, 0x00, 0x00, _packetCount, _packetIndex, 0x00, 0x00, 0x01, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(Util.RandomKey(4)); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); bodyWriter.Write(new byte[] { 0x00, 0x06 }); bodyWriter.Write(new byte[] { 0xE5, 0xAE, 0x8B, 0xE4, 0xBD, 0x93 }); bodyWriter.Write(new byte[] { 0x00, 0x00 }); if (Encoding.UTF8.GetString(_message).Contains("[face") && Encoding.UTF8.GetString(_message).Contains(".gif]")) { var MessageData = ConstructMessage(Encoding.UTF8.GetString(_message)); if (MessageData.Length != 0) { bodyWriter.Write(MessageData); } } else { //普通消息 ConstructMessage(bodyWriter, _message); } } }
/// <summary> /// 初始化包体 /// </summary> /// <param name="buf">The buf.</param> protected override void PutBody() { var _DateTime = Util.GetTimeSeconds(DateTime.Now); var group = GroupToGid(_group); if (_messageType.HasFlag(MessageType.Xml)) { bodyWriter.Write((byte)0x2A); bodyWriter.BEWrite(group); var compressMsg = GZipByteArray.CompressBytes(Encoding.UTF8.GetString(_message)); bodyWriter.BEWrite((ushort)(compressMsg.Length + 64)); bodyWriter.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.Write(SendXML(_DateTime, compressMsg)); } else if (_messageType.HasFlag(MessageType.Picture)) { bodyWriter.Write((byte)0x2A); bodyWriter.BEWrite(group); var Guid = Encoding.UTF8.GetBytes(Util.GetMD5ToGuidHashFromFile(Encoding.UTF8.GetString(_message))); bodyWriter.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(Util.RandomKey(4)); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); bodyWriter.Write(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x03, 0x00, 0xCB, 0x02 }); bodyWriter.Write(new byte[] { 0x00, 0x2A }); bodyWriter.Write(Guid); bodyWriter.Write(new byte[] { 0x04, 0x00, 0x04 }); bodyWriter.Write(new byte[] { 0x9B, 0x53, 0xB0, 0x08, 0x05, 0x00, 0x04, 0xD9, 0x8A, 0x5A, 0x70, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0x50, 0x07, 0x00, 0x01, 0x43, 0x08, 0x00, 0x00, 0x09, 0x00, 0x01, 0x01, 0x0B, 0x00, 0x00, 0x14, 0x00, 0x04, 0x11, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x00, 0x02, 0xBC, 0x16, 0x00, 0x04, 0x00, 0x00, 0x02, 0xBC, 0x18, 0x00, 0x04, 0x00, 0x00, 0x7D, 0x5E, 0xFF, 0x00, 0x5C, 0x15, 0x36, 0x20, 0x39, 0x32, 0x6B, 0x41, 0x31, 0x43, 0x39, 0x62, 0x35, 0x33, 0x62, 0x30, 0x30, 0x38, 0x64, 0x39, 0x38, 0x61, 0x35, 0x61, 0x37, 0x30 }); bodyWriter.Write(new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x35, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }); bodyWriter.Write(Guid); bodyWriter.Write(0x41); } else if (_messageType.HasFlag(MessageType.ExitGroup)) { bodyWriter.Write(new byte[] { 0x09 }); bodyWriter.BEWrite(group); } else // Send_0x0002是群消息,不需要进行判断 { bodyWriter.Write((byte)0x2A); bodyWriter.BEWrite(group); bodyWriter.BEWrite((ushort)(_message.Length + 56)); bodyWriter.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(Util.RandomKey(4)); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); bodyWriter.Write(new byte[] { 0x00, 0x0C }); bodyWriter.Write(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); bodyWriter.Write(new byte[] { 0x00, 0x00 }); if (Encoding.UTF8.GetString(_message).Contains("[face") && Encoding.UTF8.GetString(_message).Contains(".gif]")) { var MessageData = ConstructMessage(Encoding.UTF8.GetString(_message)); if (MessageData.Length != 0) { bodyWriter.Write(MessageData); } } else { //普通消息 ConstructMessage(bodyWriter, _message); } } }
/// <summary> /// 初始化包体 /// </summary> protected override void PutBody() { var dateTime = Util.GetTimeSeconds(DateTime.Now); var group = ConvertQQGroupId(_group); switch (Message.Snippets[0].Type) { case MessageType.At: case MessageType.Normal: case MessageType.Emoji: { BodyWriter.Write((byte)0x2A); BodyWriter.BeWrite(group); BodyWriter.BeWrite((ushort)(_data.Length + 50)); // 字符串长度 + 56,但是_data里面包含了和长度有关的额外六个byte BodyWriter.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); BodyWriter.BeWrite(dateTime); BodyWriter.Write(Util.RandomKey(4)); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); BodyWriter.Write(new byte[] { 0x00, 0x0C }); BodyWriter.Write(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); BodyWriter.Write(new byte[] { 0x00, 0x00 }); BodyWriter.Write(_data); break; } case MessageType.Xml: { BodyWriter.Write((byte)0x2A); BodyWriter.BeWrite(group); var compressMsg = GZipByteArray.CompressBytes(Message.Snippets[0].Content); BodyWriter.BeWrite((ushort)(compressMsg.Length + 64)); BodyWriter.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); BodyWriter.BeWrite(dateTime); BodyWriter.Write(SendXml(compressMsg)); break; } case MessageType.Picture: { HttpUpLoadGroupImg(_group, User.Ukey, Message.Snippets[0].Content); BodyWriter.Write((byte)0x2A); BodyWriter.BeWrite(group); var guid = Encoding.UTF8.GetBytes(Util.GetMD5ToGuidHashFromFile(Message.Snippets[0].Content)); BodyWriter.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); BodyWriter.BeWrite(dateTime); BodyWriter.Write(Util.RandomKey(4)); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); BodyWriter.Write(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x03, 0x00, 0xCB, 0x02 }); BodyWriter.Write(new byte[] { 0x00, 0x2A }); BodyWriter.Write(guid); BodyWriter.Write(new byte[] { 0x04, 0x00, 0x04 }); BodyWriter.Write(new byte[] { 0x9B, 0x53, 0xB0, 0x08, 0x05, 0x00, 0x04, 0xD9, 0x8A, 0x5A, 0x70, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0x50, 0x07, 0x00, 0x01, 0x43, 0x08, 0x00, 0x00, 0x09, 0x00, 0x01, 0x01, 0x0B, 0x00, 0x00, 0x14, 0x00, 0x04, 0x11, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x00, 0x02, 0xBC, 0x16, 0x00, 0x04, 0x00, 0x00, 0x02, 0xBC, 0x18, 0x00, 0x04, 0x00, 0x00, 0x7D, 0x5E, 0xFF, 0x00, 0x5C, 0x15, 0x36, 0x20, 0x39, 0x32, 0x6B, 0x41, 0x31, 0x43, 0x39, 0x62, 0x35, 0x33, 0x62, 0x30, 0x30, 0x38, 0x64, 0x39, 0x38, 0x61, 0x35, 0x61, 0x37, 0x30 }); BodyWriter.Write(new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x35, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }); BodyWriter.Write(guid); BodyWriter.Write(0x41); break; } case MessageType.AddGroup: { BodyWriter.Write(new byte[] { 0x08 }); BodyWriter.BeWrite(group); BodyWriter.Write(new byte[] { 0x01 }); BodyWriter.BeWrite((ushort)User.AddFriend0020Value.Length); BodyWriter.Write(User.AddFriend0020Value); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00 }); //备注信息 var messageData = Encoding.UTF8.GetBytes(Message.Snippets[0].Content); Writer.BeWrite((ushort)messageData.Length); Writer.Write(messageData); BodyWriter.Write(new byte[] { 0x01, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x09 }); break; } case MessageType.GetGroupImformation: { BodyWriter.Write(new byte[] { 0x72 }); BodyWriter.BeWrite(group); break; } case MessageType.ExitGroup: { BodyWriter.Write(new byte[] { 0x09 }); BodyWriter.BeWrite(group); break; } default: { throw new NotImplementedException(); } } }
public static List <byte[]> ConstructMessage(QQUser user, Richtext message, long toQQ) { var dateTime = Util.GetTimeSeconds(DateTime.Now); var md5 = user.QQ_SessionKey; var ret = new List <byte[]>(); var writer = new BinaryWriter(new MemoryStream()); // FIXME: 使用正确的_packetCount和_packetIndex进行分段 byte _packetCount = 1, _packetIndex = 0; void Init() { writer.BEWrite(user.QQ); writer.BEWrite(toQQ); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x0D, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x01 }); writer.Write(new byte[] { 0x36, 0x43 }); writer.BEWrite(user.QQ); writer.BEWrite(toQQ); writer.Write(md5); writer.Write(new byte[] { 0x00, 0x0B }); writer.Write(Util.RandomKey(2)); writer.BEWrite(dateTime); writer.Write(new byte[] { 0x02, 0x34, 0x00, 0x00, 0x00, 0x00, _packetCount, _packetIndex, 0x00, 0x00, 0x01, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); writer.BEWrite(dateTime); writer.Write(Util.RandomKey(4)); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); writer.Write(new byte[] { 0x00, 0x06 }); writer.Write(new byte[] { 0xE5, 0xAE, 0x8B, 0xE4, 0xBD, 0x93 }); writer.Write(new byte[] { 0x00, 0x00 }); } foreach (var snippet in message.Snippets) { switch (snippet.Type) { case MessageType.Xml: { var compressMsg = GZipByteArray.CompressBytes(snippet.Content); writer.BEWrite(user.QQ); writer.BEWrite(toQQ); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x04 }); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }); writer.Write(new byte[] { 0x37, 0x0F }); writer.BEWrite(user.QQ); writer.BEWrite(toQQ); writer.Write(md5); writer.Write(new byte[] { 0x00, 0x0B }); writer.Write(Util.RandomKey(2)); writer.BEWrite(dateTime); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, _packetCount, _packetIndex, 0x00, 0x00, 0x01, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); writer.BEWrite(dateTime); writer.Write(Util.RandomKey(4)); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); writer.Write(new byte[] { 0x00, 0x0C }); writer.Write( new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); writer.Write(new byte[] { 0x00, 0x00, 0x14 }); writer.BEWrite((ushort)(compressMsg.Length + 11)); writer.Write((byte)0x01); writer.BEWrite((ushort)(compressMsg.Length + 1)); writer.Write((byte)0x01); writer.Write(compressMsg); writer.Write(new byte[] { 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x4D }); ret.Add(writer.BaseStream.ToBytesArray()); return(ret); } case MessageType.Shake: { writer.BEWrite(user.QQ); writer.BEWrite(toQQ); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }); writer.Write(new byte[] { 0x37, 0x0F }); writer.BEWrite(user.QQ); writer.BEWrite(toQQ); writer.Write(Util.RandomKey()); writer.Write(new byte[] { 0x00, 0xAF }); writer.Write(Util.RandomKey(2)); writer.BEWrite(dateTime); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); writer.Write(Util.RandomKey(4)); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }); ret.Add(writer.BaseStream.ToBytesArray()); return(ret); } case MessageType.Normal: { if (writer.BaseStream.Position + snippet.Length > 699) { ret.Add(writer.BaseStream.ToBytesArray()); writer = new BinaryWriter(new MemoryStream()); } if (writer.BaseStream.Position == 0) { Init(); } var messageData = Encoding.UTF8.GetBytes(snippet.Content); writer.Write(new byte[] { 0x01 }); writer.BEWrite((ushort)(messageData.Length + 3)); writer.Write(new byte[] { 0x01 }); writer.BEWrite((ushort)messageData.Length); writer.Write(messageData); break; } case MessageType.Emoji: { if (writer.BaseStream.Position + snippet.Length > 699) { ret.Add(writer.BaseStream.ToBytesArray()); writer = new BinaryWriter(new MemoryStream()); } if (writer.BaseStream.Position == 0) { Init(); } var faceIndex = byte.Parse(snippet.Content); writer.Write(new byte[] { 0x02, 0x00, 0x14, 0x01, 0x00, 0x01 }); writer.Write(faceIndex); writer.Write(new byte[] { 0xFF, 0x00, 0x02, 0x14 }); writer.Write((byte)(faceIndex + 65)); writer.Write(new byte[] { 0x0B, 0x00, 0x08, 0x00, 0x01, 0x00, 0x04, 0x52, 0xCC, 0x85, 0x50 }); break; } default: { throw new NotImplementedException(); } } ret.Add(writer.BaseStream.ToBytesArray()); writer = new BinaryWriter(new MemoryStream()); } return(ret); }
/// <summary> /// 初始化包体 /// </summary> protected override void PutBody() { var dateTime = Util.GetTimeSeconds(DateTime.Now); var group = ConvertQQGroupId(_group); switch (Message.Snippets[0].Type) { case MessageType.At: case MessageType.Normal: case MessageType.Emoji: { BodyWriter.Write((byte)0x2A); BodyWriter.BeWrite(group); BodyWriter.BeWrite((ushort)(_data.Length + 50)); // 字符串长度 + 56,但是_data里面包含了和长度有关的额外六个byte BodyWriter.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); BodyWriter.BeWrite(dateTime); BodyWriter.Write(Util.RandomKey(4)); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); BodyWriter.Write(new byte[] { 0x00, 0x0C }); BodyWriter.Write(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); BodyWriter.Write(new byte[] { 0x00, 0x00 }); BodyWriter.Write(_data); break; } case MessageType.Xml: { BodyWriter.Write((byte)0x2A); BodyWriter.BeWrite(group); var compressMsg = GZipByteArray.CompressBytes(Message.Snippets[0].Content); BodyWriter.BeWrite((ushort)(compressMsg.Length + 64)); BodyWriter.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); BodyWriter.BeWrite(dateTime); BodyWriter.Write(SendXml(compressMsg)); break; } case MessageType.Picture: { var _Snippets = Message.Snippets[0]; BodyWriter.Write((byte)0x2A); BodyWriter.BeWrite(group); var guid = Encoding.UTF8.GetBytes(Util.GetMD5ToGuidHashFromFile(Message.Snippets[0].Content) + Path.GetExtension(_Snippets.Content)); BodyWriter.Write(new byte[] { 0x01, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); BodyWriter.BeWrite(dateTime); BodyWriter.Write(Util.RandomKey(4)); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x22 }); BodyWriter.WriteKey(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x03, 0x00, 0xCB, 0x02 }); BodyWriter.WriteKey(guid); BodyWriter.Write((byte)0x04); BodyWriter.WriteKey(Util.HexStringToByteArray(_Snippets["30Key"].ToString())); BodyWriter.Write((byte)0x05); BodyWriter.WriteKey(Util.HexStringToByteArray(_Snippets["48Key"].ToString())); BodyWriter.Write(new byte[] { 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0x50, 0x07, 0x00, 0x01, 0x43, 0x08, 0x00, 0x00, 0x09, 0x00, 0x01, 0x01, 0x0b, 0x00, 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x00, 0x05, 0xa0, 0x16, 0x00, 0x04, 0x00, 0x00, 0x04, 0x38, 0x18, 0x00, 0x04, 0x00, 0x01, 0xf5, 0x62, 0xff }); var data = new BinaryWriter(new MemoryStream()); data.Write(new byte[] { 0x15, 0x36, 0x20 }); data.Write(new byte[] { 0x39, 0x32, 0x6b, 0x41, 0x31, 0x43, 0x61, 0x37, 0x64, 0x63, 0x66, 0x34, 0x38, 0x37, 0x34, 0x39, 0x38, 0x64, 0x33, 0x33, 0x37, 0x39 }); data.Write(new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x35, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }); data.Write(guid); data.Write((byte)0x41); BodyWriter.WriteKey(data.BaseStream.ToBytesArray()); break; } case MessageType.AddGroup: { BodyWriter.Write(new byte[] { 0x08 }); BodyWriter.BeWrite(group); BodyWriter.Write(new byte[] { 0x01 }); BodyWriter.BeWrite((ushort)User.AddFriend0020Value.Length); BodyWriter.Write(User.AddFriend0020Value); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00 }); //备注信息 var messageData = Encoding.UTF8.GetBytes(Message.Snippets[0].Content); Writer.BeWrite((ushort)messageData.Length); Writer.Write(messageData); BodyWriter.Write(new byte[] { 0x01, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x09 }); break; } case MessageType.GetGroupImformation: { BodyWriter.Write(new byte[] { 0x72 }); BodyWriter.BeWrite(group); BodyWriter.BeWrite(0x00); break; } case MessageType.ExitGroup: { BodyWriter.Write(new byte[] { 0x09 }); BodyWriter.BeWrite(group); break; } default: { throw new NotImplementedException(); } } }
/// <summary> /// 初始化包体 /// </summary> protected override void PutBody() { var _DateTime = Util.GetTimeSeconds(DateTime.Now); var group = GroupToGid(_group); foreach (var snippet in _message.Snippets) { switch (snippet.Type) { case MessageType.Xml: { bodyWriter.Write((byte)0x2A); bodyWriter.BEWrite(group); var compressMsg = GZipByteArray.CompressBytes(snippet.Content); bodyWriter.BEWrite((ushort)(compressMsg.Length + 64)); bodyWriter.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.Write(SendXML(_DateTime, compressMsg)); break; } case MessageType.Picture: { HttpUpLoadGroupImg(_group, user.Ukey, snippet.Content); bodyWriter.Write((byte)0x2A); bodyWriter.BEWrite(group); var Guid = Encoding.UTF8.GetBytes(Util.GetMD5ToGuidHashFromFile(snippet.Content)); bodyWriter.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(Util.RandomKey(4)); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); bodyWriter.Write(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x03, 0x00, 0xCB, 0x02 }); bodyWriter.Write(new byte[] { 0x00, 0x2A }); bodyWriter.Write(Guid); bodyWriter.Write(new byte[] { 0x04, 0x00, 0x04 }); bodyWriter.Write(new byte[] { 0x9B, 0x53, 0xB0, 0x08, 0x05, 0x00, 0x04, 0xD9, 0x8A, 0x5A, 0x70, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0x50, 0x07, 0x00, 0x01, 0x43, 0x08, 0x00, 0x00, 0x09, 0x00, 0x01, 0x01, 0x0B, 0x00, 0x00, 0x14, 0x00, 0x04, 0x11, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x00, 0x02, 0xBC, 0x16, 0x00, 0x04, 0x00, 0x00, 0x02, 0xBC, 0x18, 0x00, 0x04, 0x00, 0x00, 0x7D, 0x5E, 0xFF, 0x00, 0x5C, 0x15, 0x36, 0x20, 0x39, 0x32, 0x6B, 0x41, 0x31, 0x43, 0x39, 0x62, 0x35, 0x33, 0x62, 0x30, 0x30, 0x38, 0x64, 0x39, 0x38, 0x61, 0x35, 0x61, 0x37, 0x30 }); bodyWriter.Write(new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x35, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }); bodyWriter.Write(Guid); bodyWriter.Write(0x41); break; } case MessageType.AddGroup: { bodyWriter.Write(new byte[] { 0x08 }); bodyWriter.BEWrite(group); bodyWriter.Write(new byte[] { 0x01 }); bodyWriter.BEWrite((ushort)user.AddFriend_0020Value.Length); bodyWriter.Write(user.AddFriend_0020Value); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00 }); //备注信息 var _messageData = Encoding.UTF8.GetBytes(snippet.Content); writer.BEWrite((ushort)_messageData.Length); writer.Write(_messageData); bodyWriter.Write(new byte[] { 0x01, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x09 }); break; } case MessageType.GetGroupImformation: { bodyWriter.Write(new byte[] { 0x72 }); bodyWriter.BEWrite(group); break; } case MessageType.ExitGroup: { bodyWriter.Write(new byte[] { 0x09 }); bodyWriter.BEWrite(group); break; } case MessageType.Normal: { bodyWriter.Write((byte)0x2A); bodyWriter.BEWrite(group); var _messageData = Encoding.UTF8.GetBytes(snippet.Content); bodyWriter.BEWrite((ushort)(_messageData.Length + 56)); bodyWriter.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(Util.RandomKey(4)); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); bodyWriter.Write(new byte[] { 0x00, 0x0C }); bodyWriter.Write(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); bodyWriter.Write(new byte[] { 0x00, 0x00 }); ConstructMessage(bodyWriter, _messageData); break; } case MessageType.Emoji: { bodyWriter.Write((byte)0x2A); bodyWriter.BEWrite(group); var _messageData = Encoding.UTF8.GetBytes(snippet.Content); bodyWriter.BEWrite((ushort)(_messageData.Length + 56)); bodyWriter.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(Util.RandomKey(4)); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); bodyWriter.Write(new byte[] { 0x00, 0x0C }); bodyWriter.Write(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); bodyWriter.Write(new byte[] { 0x00, 0x00 }); var MessageData = ConstructMessage(snippet.Content); if (MessageData.Length != 0) { bodyWriter.Write(MessageData); } break; } default: { throw new NotImplementedException(); } } } }
/// <summary> /// 初始化包体 /// </summary> protected override void PutBody() { var _DateTime = Util.GetTimeSeconds(DateTime.Now); var _Md5 = user.QQ_SessionKey; foreach (var snippet in _message.Snippets) { switch (snippet.Type) { case MessageType.Xml: { var compressMsg = GZipByteArray.CompressBytes(snippet.Content); bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x04 }); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }); bodyWriter.Write(new byte[] { 0x37, 0x0F }); bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(_Md5); bodyWriter.Write(new byte[] { 0x00, 0x0B }); bodyWriter.Write(Util.RandomKey(2)); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, _packetCount, _packetIndex, 0x00, 0x00, 0x01, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.Write(SendXML(_DateTime, compressMsg)); break; } case MessageType.Shake: { bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }); bodyWriter.Write(new byte[] { 0x37, 0x0F }); bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(Util.RandomKey()); bodyWriter.Write(new byte[] { 0x00, 0xAF }); bodyWriter.Write(Util.RandomKey(2)); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.Write(Util.RandomKey(4)); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }); break; } case MessageType.Normal: { bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x0D, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x01 }); bodyWriter.Write(new byte[] { 0x36, 0x43 }); bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(_Md5); bodyWriter.Write(new byte[] { 0x00, 0x0B }); bodyWriter.Write(Util.RandomKey(2)); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(new byte[] { 0x02, 0x34, 0x00, 0x00, 0x00, 0x00, _packetCount, _packetIndex, 0x00, 0x00, 0x01, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(Util.RandomKey(4)); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); bodyWriter.Write(new byte[] { 0x00, 0x06 }); bodyWriter.Write(new byte[] { 0xE5, 0xAE, 0x8B, 0xE4, 0xBD, 0x93 }); bodyWriter.Write(new byte[] { 0x00, 0x00 }); var _messageData = Encoding.UTF8.GetBytes(snippet.Content); ConstructMessage(bodyWriter, _messageData); break; } case MessageType.Emoji: { bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x0D, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x01 }); bodyWriter.Write(new byte[] { 0x36, 0x43 }); bodyWriter.BEWrite(user.QQ); bodyWriter.BEWrite(_toQQ); bodyWriter.Write(_Md5); bodyWriter.Write(new byte[] { 0x00, 0x0B }); bodyWriter.Write(Util.RandomKey(2)); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(new byte[] { 0x02, 0x34, 0x00, 0x00, 0x00, 0x00, _packetCount, _packetIndex, 0x00, 0x00, 0x01, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); bodyWriter.BEWrite(_DateTime); bodyWriter.Write(Util.RandomKey(4)); bodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); bodyWriter.Write(new byte[] { 0x00, 0x06 }); bodyWriter.Write(new byte[] { 0xE5, 0xAE, 0x8B, 0xE4, 0xBD, 0x93 }); bodyWriter.Write(new byte[] { 0x00, 0x00 }); var MessageData = ConstructMessage(snippet.Content); if (MessageData.Length != 0) { bodyWriter.Write(MessageData); } break; } default: { throw new NotImplementedException(); } } } }
public static List <byte[]> ConstructMessage(QQUser user, Richtext message, long groupNum) { var dateTime = Util.GetTimeSeconds(DateTime.Now); var group = GroupToGid(groupNum); var ret = new List <byte[]>(); var writer = new BinaryWriter(new MemoryStream()); // FIXME: 使用正确的_packetCount和_packetIndex进行分段 byte _packetCount = 1, _packetIndex = 0; foreach (var snippet in message.Snippets) { switch (snippet.Type) { case MessageType.Xml: { writer.Write((byte)0x2A); writer.BEWrite(group); var compressMsg = GZipByteArray.CompressBytes(snippet.Content); writer.BEWrite((ushort)(compressMsg.Length + 64)); writer.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); writer.BEWrite(dateTime); writer.Write(Util.RandomKey(4)); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); writer.Write(new byte[] { 0x00, 0x0C }); writer.Write(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); writer.Write(new byte[] { 0x00, 0x00, 0x14 }); writer.BEWrite((ushort)(compressMsg.Length + 11)); writer.Write((byte)0x01); writer.BEWrite((ushort)(compressMsg.Length + 1)); writer.Write((byte)0x01); writer.Write(compressMsg); writer.Write(new byte[] { 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x4D }); break; } case MessageType.Picture: { HttpUpLoadGroupImg(user, groupNum, user.Ukey, snippet.Content); writer.Write((byte)0x2A); writer.BEWrite(group); writer.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); var guid = Encoding.UTF8.GetBytes(Util.GetMD5ToGuidHashFromFile(snippet.Content)); writer.BEWrite(dateTime); writer.Write(Util.RandomKey(4)); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); writer.Write(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); writer.Write(new byte[] { 0x00, 0x00, 0x03, 0x00, 0xCB, 0x02 }); writer.Write(new byte[] { 0x00, 0x2A }); writer.Write(guid); writer.Write(new byte[] { 0x04, 0x00, 0x04 }); writer.Write(new byte[] { 0x9B, 0x53, 0xB0, 0x08, 0x05, 0x00, 0x04, 0xD9, 0x8A, 0x5A, 0x70, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0x50, 0x07, 0x00, 0x01, 0x43, 0x08, 0x00, 0x00, 0x09, 0x00, 0x01, 0x01, 0x0B, 0x00, 0x00, 0x14, 0x00, 0x04, 0x11, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x00, 0x02, 0xBC, 0x16, 0x00, 0x04, 0x00, 0x00, 0x02, 0xBC, 0x18, 0x00, 0x04, 0x00, 0x00, 0x7D, 0x5E, 0xFF, 0x00, 0x5C, 0x15, 0x36, 0x20, 0x39, 0x32, 0x6B, 0x41, 0x31, 0x43, 0x39, 0x62, 0x35, 0x33, 0x62, 0x30, 0x30, 0x38, 0x64, 0x39, 0x38, 0x61, 0x35, 0x61, 0x37, 0x30 }); writer.Write(new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x35, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }); writer.Write(guid); writer.Write(0x41); break; } case MessageType.AddGroup: { writer.Write(new byte[] { 0x08 }); writer.BEWrite(group); writer.Write(new byte[] { 0x01 }); writer.BEWrite((ushort)user.AddFriend_0020Value.Length); writer.Write(user.AddFriend_0020Value); writer.Write(new byte[] { 0x00, 0x00, 0x00 }); //备注信息 var messageData = Encoding.UTF8.GetBytes(snippet.Content); writer.BEWrite((ushort)messageData.Length); writer.Write(messageData); writer.Write(new byte[] { 0x01, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x09 }); break; } case MessageType.GetGroupImformation: { writer.Write(new byte[] { 0x72 }); writer.BEWrite(group); break; } case MessageType.ExitGroup: { writer.Write(new byte[] { 0x09 }); writer.BEWrite(group); break; } case MessageType.Normal: { writer.Write((byte)0x2A); writer.BEWrite(group); var messageData = Encoding.UTF8.GetBytes(snippet.Content); writer.BEWrite((ushort)(messageData.Length + 56)); writer.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); writer.BEWrite(dateTime); writer.Write(Util.RandomKey(4)); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); writer.Write(new byte[] { 0x00, 0x0C }); writer.Write(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); writer.Write(new byte[] { 0x00, 0x00 }); writer.Write(new byte[] { 0x01 }); writer.BEWrite((ushort)(messageData.Length + 3)); writer.Write(new byte[] { 0x01 }); writer.BEWrite((ushort)messageData.Length); writer.Write(messageData); break; } case MessageType.Emoji: { writer.Write((byte)0x2A); writer.BEWrite(group); var messageData = Encoding.UTF8.GetByteCount(snippet.Content); writer.BEWrite((ushort)(messageData + 56)); writer.Write(new byte[] { 0x00, 0x01, _packetCount, _packetIndex, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); writer.BEWrite(dateTime); writer.Write(Util.RandomKey(4)); writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); writer.Write(new byte[] { 0x00, 0x0C }); writer.Write(new byte[] { 0xE5, 0xBE, 0xAE, 0xE8, 0xBD, 0xAF, 0xE9, 0x9B, 0x85, 0xE9, 0xBB, 0x91 }); writer.Write(new byte[] { 0x00, 0x00 }); var faceIndex = byte.Parse(snippet.Content); writer.Write(new byte[] { 0x02, 0x00, 0x14, 0x01, 0x00, 0x01 }); writer.Write(faceIndex); writer.Write(new byte[] { 0xFF, 0x00, 0x02, 0x14 }); writer.Write((byte)(faceIndex + 65)); writer.Write(new byte[] { 0x0B, 0x00, 0x08, 0x00, 0x01, 0x00, 0x04, 0x52, 0xCC, 0x85, 0x50 }); break; } default: { throw new NotImplementedException(); } } ret.Add(writer.BaseStream.ToBytesArray()); writer = new BinaryWriter(new MemoryStream()); } return(ret); }
/// <summary> /// 初始化包体 /// </summary> protected override void PutBody() { var dateTime = Util.GetTimeSeconds(DateTime.Now); var md5 = User.TXProtocol.SessionKey; switch (Message?.Snippets[0].Type ?? MessageType.Normal) { case MessageType.At: case MessageType.Normal: case MessageType.Picture: case MessageType.Emoji: { BodyWriter.BeWrite(User.QQ); BodyWriter.BeWrite(_toQQ); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x0D, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x01 }); BodyWriter.Write(new byte[] { 0x36, 0x43 }); BodyWriter.BeWrite(User.QQ); BodyWriter.BeWrite(_toQQ); BodyWriter.Write(md5); BodyWriter.Write(new byte[] { 0x00, 0x0B }); BodyWriter.Write(Util.RandomKey(2)); BodyWriter.BeWrite(dateTime); BodyWriter.Write(new byte[] { 0x02, 0x34, 0x00, 0x00, 0x00, 0x00, _packetCount, _packetIndex, 0x00, 0x00, 0x01, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); BodyWriter.BeWrite(dateTime); BodyWriter.Write(Util.RandomKey(4)); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x86, 0x00 }); BodyWriter.Write(new byte[] { 0x00, 0x06 }); BodyWriter.Write(new byte[] { 0xE5, 0xAE, 0x8B, 0xE4, 0xBD, 0x93 }); BodyWriter.Write(new byte[] { 0x00, 0x00 }); BodyWriter.Write(_data); break; } case MessageType.Xml: { BodyWriter.BeWrite(User.QQ); BodyWriter.BeWrite(_toQQ); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x04 }); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }); BodyWriter.Write(new byte[] { 0x37, 0x0F }); BodyWriter.BeWrite(User.QQ); BodyWriter.BeWrite(_toQQ); BodyWriter.Write(md5); BodyWriter.Write(new byte[] { 0x00, 0x0B }); BodyWriter.Write(Util.RandomKey(2)); BodyWriter.BeWrite(dateTime); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, _packetCount, _packetIndex, 0x00, 0x00, 0x01, 0x4D, 0x53, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }); BodyWriter.BeWrite(dateTime); BodyWriter.Write(SendXml(GZipByteArray.CompressBytes(Message.Snippets[0].Content))); break; } case MessageType.Shake: { BodyWriter.BeWrite(User.QQ); BodyWriter.BeWrite(_toQQ); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }); BodyWriter.Write(new byte[] { 0x37, 0x0F }); BodyWriter.BeWrite(User.QQ); BodyWriter.BeWrite(_toQQ); BodyWriter.Write(Util.RandomKey()); BodyWriter.Write(new byte[] { 0x00, 0xAF }); BodyWriter.Write(Util.RandomKey(2)); BodyWriter.BeWrite(dateTime); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); BodyWriter.Write(Util.RandomKey(4)); BodyWriter.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }); break; } default: { throw new NotImplementedException(); } } }