public static bool SendFriendAudio(long thisQQ, long sendQQ, byte[] BytesIn, byte[] filekey) { byte[] bytes = null; List <byte[]> ListBytes = new List <byte[]>(); ListBytes.Add(new byte[] { 0x4A, 0x2, 0x28, 0x0 }); ListBytes.Add(new byte[] { 0xAA, 0x2, 0x3, 0x88, 1, 0 }); byte[] array = ListBytes.SelectMany((a) => a).ToArray(); BytesIn = BytesIn.Skip(4).ToArray(); using (var ms = new MemoryStream(BytesIn)) { var result = Serializer.Deserialize <AudioHashStruct>(ms); var sAddr = result.AudioHashInfo.IP; var Port = result.AudioHashInfo.Port; var uKey = result.AudioHashInfo.ukey; var token = result.AudioHashInfo.token; SendAudioInfos msg = new SendAudioInfos { Field1 = 4, thisQQ = thisQQ, token = "[Audio,hash=" + BitConverter.ToString(filekey).Replace("-", "") + ",token=" + Encoding.UTF8.GetString(token) + "]", AudioHash = filekey, AudioName = BitConverter.ToString(filekey).Replace("-", "") + ".amr", AudioSize = 6390, uKey = new byte[] { 0x3, 0x8, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1, 0x9, 0x0, 0x4, 0x0, 0x0, 0x0, 0x5, 0xA, 0x0, 0x2, 0x8, 0x0 }, Field9 = 3030587005, Port = 80, Field11 = 1 }; using (MemoryStream mStream = new MemoryStream()) { Serializer.Serialize(mStream, msg); bytes = mStream.ToArray(); Debug.Print("发送好友语音结构:" + bytes.Length.ToString() + "\r\n" + BitConverter.ToString(bytes).Replace("-", " ")); } SendFriendMsgStuct SendMsg = new SendFriendMsgStuct { SendFromInfo = new SendQQFrom { FromInfo = new FromInfos { FromId = sendQQ } }, MsgId = new byte[] { 8, 1, 0x10, 0, 0x18, 0 }, MsgInfo = new MsgInfos { MsgTextInfo = new MsgTextInfos { MsgContent = array, AudioContent = bytes } }, RequestId = API.QQ.mRequestID, TimeStamp = long.Parse(Convert.ToInt64(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds).ToString().Substring(0, 10)), SyncCoookie = new SyncCoookies { timestamp2 = long.Parse(Convert.ToInt64(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds).ToString().Substring(0, 10)), Field5 = 1634440201, Field6 = 916698971, Field7 = 2800362740, Field10 = 0 } }; using (var mStream = new MemoryStream()) { Serializer.Serialize(mStream, SendMsg); Debug.Print("发送好友语音消息:" + mStream.ToArray().Length.ToString() + "\r\n" + BitConverter.ToString(mStream.ToArray()).Replace("-", " ")); var SendBytes = API.PackCmdHeader("MessageSvc.PbSendMsg", mStream.ToArray()); API.TClient.SendData(API.PackAllHeader(SendBytes)); } } return(true); }
public static API.FriendWithdrawInfo SendFriendMsg(long thisQQ, long sendQQ, byte[] MsgBytes, API.MsgType MsgTypes) { byte[] bytes = null; List <TextMessageContents> MsgList = new List <TextMessageContents>(); List <byte[]> ListBytes = new List <byte[]>(); var timestamp = long.Parse(Convert.ToInt64(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds).ToString().Substring(0, 10)); if (MsgTypes == API.MsgType.TextMsg) //文字消息 { TextMessageContents MsgListStruct = new TextMessageContents { content = Encoding.UTF8.GetString(MsgBytes) }; MsgList.Add(MsgListStruct); MessageStruct msg = new MessageStruct { TextMessageContent = MsgList }; using (MemoryStream mStream = new MemoryStream()) { Serializer.Serialize(mStream, msg); bytes = mStream.ToArray(); } } else if (MsgTypes == API.MsgType.XmlMsg) { TextMessageContents MsgListStruct = new TextMessageContents { XmlContent = new XmlContents { Content = MsgBytes, flag = 1 } }; MsgList.Add(MsgListStruct); MessageStruct msg = new MessageStruct { TextMessageContent = MsgList }; using (MemoryStream mStream = new MemoryStream()) { Serializer.Serialize(mStream, msg); bytes = mStream.ToArray(); } } else if (MsgTypes == API.MsgType.PicMsg) //图片消息 { MsgBytes = MsgBytes.Skip(4).ToArray(); try { using (var ms = new MemoryStream(MsgBytes)) { var result = Serializer.Deserialize <PicGuidStruct>(ms); if (result.PicGuidInfo.uKey != null) //服务器没有该图片的hash { var uKey = result.PicGuidInfo.uKey; var Ip = API.Int32ToIP(result.PicGuidInfo.Ip[0]); var Port = result.PicGuidInfo.Port[0]; UploadFriendPicByTCP(sendQQ, uKey, Ip, Port); } SendFriendPicStruct msg = new SendFriendPicStruct { SendFriendPicInfo = new SendFriendPicInfos { PicName = BitConverter.ToString(API.FileHash).Replace("-", "") + ".jpg", PicHash = API.FileHash, PicGuid = result.PicGuidInfo.PicGuid, PicPix = 1000, PicWidth = 647, PicHeigh = 980 } }; using (MemoryStream mStream = new MemoryStream()) { Serializer.Serialize(mStream, msg); bytes = mStream.ToArray(); } } } catch (Exception ex) { Debug.Print(ex.Message.ToString()); } } ListBytes.Add(bytes); SendFriendMsgStuct SendMsg = new SendFriendMsgStuct { SendFromInfo = new SendQQFrom { FromInfo = new FromInfos { FromId = sendQQ } }, MsgId = new byte[] { 8, 1, 0x10, 0, 0x18, 0 }, MsgInfo = new MsgInfos { MsgTextInfo = new MsgTextInfos { MsgContent = bytes } }, RequestId = API.QQ.mRequestID, TimeStamp = long.Parse(Convert.ToInt64(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds).ToString().Substring(0, 10)), count = 1, SyncCoookie = new SyncCoookies { timestamp1 = timestamp, timestamp2 = timestamp, timestamp3 = timestamp, Field3 = 805979870, Field4 = 3344460674, Field5 = 82343012, Field6 = 3281833389, Field7 = 2696570484, Field8 = 81, Field10 = 0 } }; API.FriendWithdraw.MsgReqId = API.QQ.mRequestID; API.FriendWithdraw.MsgTimeStamp = SendMsg.TimeStamp; API.FriendWithdraw.MsgRandomId = SendMsg.TimeStamp; using (var ms = new MemoryStream()) { Serializer.Serialize(ms, SendMsg); Debug.Print("发送好友消息:" + "\r\n" + BitConverter.ToString(ms.ToArray()).Replace("-", " ")); var SendBytes = API.PackCmdHeader("MessageSvc.PbSendMsg", ms.ToArray()); API.TClient.SendData(API.PackAllHeader(SendBytes)); } return(API.FriendWithdraw); }