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); }
public static API.GroupWithdrawInfo SendGroupMsg(long thisQQ, long GroupId, byte[] MsgBytes, API.MsgType MsgTypes, long sendQQ = 0) { byte[] bytes = null; var timestamp = long.Parse(Convert.ToInt64(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds).ToString().Substring(0, 10)); List <SendMessages> MsgList = new List <SendMessages>(); if (MsgTypes == API.MsgType.TextMsg) //文字消息 { SendMessages MsgListStruct = new SendMessages { SendContent = new SendContents { Content = Encoding.UTF8.GetString(MsgBytes) } }; if (sendQQ != 0) { SendMessages MsgListAtStruct = new SendMessages { SendContent = new SendContents { Content = "@" + sendQQ.ToString(), AtHash = new byte[] { 0x0, 0x1, 0x0, 0x0, 0x0, 0x4, 0x0, 0x2, 0x3B, 0xD7, 0x86, 0x0, 0x0 } } }; MsgList.Add(MsgListAtStruct); } MsgList.Add(MsgListStruct); } else if (MsgTypes == API.MsgType.XmlMsg) { SendMessages MsgListStruct = new SendMessages { GroupXmlMsg = new GroupXmlContents { Content = MsgBytes, flag = 1 } }; SendMessages XmlFlagStruct = new SendMessages { GroupXmlFlag = new GroupXmlFlags { BuddleID = (new Random()).Next(1000001, 1000037) } }; MsgList.Add(MsgListStruct); MsgList.Add(XmlFlagStruct); } else if (MsgTypes == API.MsgType.PicMsg) //图片消息 { MsgBytes = MsgBytes.Skip(4).ToArray(); using (var ms = new MemoryStream(MsgBytes)) { var result = Serializer.Deserialize <GroupPicGuidStruct>(ms); if (result.GroupPicGuidInfo.uKey != null) //'服务器没有该图片的hash { var uKey = result.GroupPicGuidInfo.uKey; var Ip = API.Int32ToIP(result.GroupPicGuidInfo.Ip[0]); var Port = result.GroupPicGuidInfo.Port[0]; UploadGroupPicByTCP(sendQQ, GroupId, uKey, Ip, Port); } SendMessages msg = new SendMessages { SendGroupPicInfo = new SendGroupPicInfos { PicName = BitConverter.ToString(API.FileHash).Replace("-", "") + ".jpg", PicId1 = 3013326518, PicId2 = 1883293792, picIconWidth = 80, picIconHeigh = 66, picMD5 = "VdcrgQM3T3AaJPtM", picAmount = 1, picHash = API.FileHash, picType = 4, picPix = 1000, picWidth = 100, picHeigh = 104, picSize = 2500, Field26 = 0, Field29 = 0, Field30 = 0 } }; MsgList.Add(msg); } } SendGroupMsgStuct SendGroupMessage = new SendGroupMsgStuct { GroupInformation = new GroupInformations { GroupFrom = new GroupFroms { GroupId = GroupId } }, GroupMsgId = new byte[] { 8, 1, 0x10, 0, 0x18, 0 }, SendGroupMsgInfo = new SendGroupMsgInfos { SendGroupMsg = new SendGroupMsgs { SendMessage = MsgList } }, MsgReqId = API.QQ.mRequestID, MsgRandomId = (new Random()).Next(1, 1879048191) + 268435457, Groupcount = 0 }; API.GroupWithdraw.MsgReqId = API.QQ.mRequestID; API.GroupWithdraw.MsgRandomId = SendGroupMessage.MsgRandomId; using (var ms = new MemoryStream()) { Serializer.Serialize(ms, SendGroupMessage); Debug.Print("发送群消息:" + ms.ToArray().Length.ToString() + "\r\n" + BitConverter.ToString(ms.ToArray()).Replace("-", " ")); var SendBytes = API.PackCmdHeader("MessageSvc.PbSendMsg", ms.ToArray()); API.TClient.SendData(API.PackAllHeader(SendBytes)); } return(API.GroupWithdraw); }