public static API.FriendWithdrawInfo ParsingFriendMsg(byte[] byteIn) { string TextMsg = ""; string FaceMsg = ""; string HotPicMsg = ""; string PicMsg = ""; string AudioMsg = ""; string VideoMsg = ""; string ReplyMsg = ""; string XmlMsg = ""; byteIn = byteIn.Skip(4).ToArray(); using (MemoryStream ms = new MemoryStream(byteIn)) { try { var result = Serializer.Deserialize <FriendMsgStuct>(ms); long qqid = result.MessageInfo[0].QQInfo.QQFromInfo.QQId; long qqfromid = result.MessageInfo[0].QQInfo.QQFromInfo.QQFromId; API.FriendWithdraw.MsgReqId = result.MessageInfo[0].QQInfo.QQFromInfo.fromReq; API.FriendWithdraw.MsgTimeStamp = result.MessageInfo[0].QQInfo.QQFromInfo.RecvTime; if (result.MessageInfo[0].QQInfo.MsgInfo.FileUploadInfo != null) //文件上传消息 { Debug.Print("朋友文件上传:" + "\r\n" + BitConverter.ToString(result.MessageInfo[0].QQInfo.MsgInfo.FileUploadInfo).Replace("-", " ")); using (MemoryStream mStream = new MemoryStream(result.MessageInfo[0].QQInfo.MsgInfo.FileUploadInfo)) { var MsgResult = Serializer.Deserialize <FileMessageStruct>(mStream); var fileName = MsgResult.FileInfo.FileName; var fileSize = MsgResult.FileInfo.FileSize; API.FriendWithdraw.MsgRandomId = MsgResult.FileInfo.FileRandId; } } if (result.MessageInfo[0].QQInfo.MsgInfo.MsgTextInfo.fonts != null) { API.FriendWithdraw.MsgRandomId = result.MessageInfo[0].QQInfo.MsgInfo.MsgTextInfo.fonts.fromRandom; } if (result.MessageInfo[0].QQInfo.MsgInfo.MsgTextInfo.MsgContent != null) { var msgByte = result.MessageInfo[0].QQInfo.MsgInfo.MsgTextInfo.MsgContent; Debug.Print("朋友消息内容:" + "\r\n" + BitConverter.ToString(msgByte).Replace("-", " ")); using (MemoryStream mStream = new MemoryStream(msgByte)) { var MsgResult = Serializer.Deserialize <MessageStruct>(mStream); if (MsgResult.ReplyMessage != null) //是带回复的消息 { string replyContent = ""; for (var i = 0; i < MsgResult.ReplyMessage.OldMsgContent.Count; i++) { replyContent = replyContent + MsgResult.ReplyMessage.OldMsgContent[i].content.Replace("\n", "").Replace("\r", "").Replace("\r\n", ""); } ReplyMsg = " [Reply=@" + MsgResult.ReplyMessage.thisQQId.ToString() + "内容:" + replyContent + "]"; } if (MsgResult.TextMessageContent != null) //有文本或小表情或热图内容 { for (var i = 0; i < MsgResult.TextMessageContent.Count; i++) { TextMsg = TextMsg + MsgResult.TextMessageContent[i].content; } } if (MsgResult.BigFace != null) //有大表情内容 { for (var i = 0; i < MsgResult.BigFace.Count; i++) { var FaceId = MsgResult.BigFace[i].FaceId; FaceMsg = FaceMsg + " [BigFaceId=" + FaceId.ToString() + "]"; } } if (MsgResult.PicMessageContent != null) //有图片内容 { for (var i = 0; i < MsgResult.PicMessageContent.Count; i++) { PicMsg = PicMsg + "https://c2cpicdw.qpic.cn/offpic_new/" + MsgResult.PicMessageContent[i].PicGuid + "/0 "; } PicMsg = "[pic,link=" + PicMsg + "]"; } //If Not MsgResult.XMLMessage Is Nothing Then '有XML内容 // Dim xmlByte = MsgResult.XMLMessage // XmlMsg = Encoding.UTF8.GetString(xmlByte) //End If if (result.MessageInfo[0].QQInfo.MsgInfo.MsgTextInfo.AudioContent != null) //有语音内容 { using (MemoryStream msStream = new MemoryStream(result.MessageInfo[0].QQInfo.MsgInfo.MsgTextInfo.AudioContent)) { var Ret = Serializer.Deserialize <AudioMessageStruct>(msStream); AudioMsg = Ret.AudioUrl; } } if (MsgResult.VideoMessageContent != null) //有视频内容 { for (var i = 0; i < MsgResult.VideoMessageContent.Count; i++) { VideoMsg = VideoMsg + "[video,guid=" + MsgResult.VideoMessageContent[i].VideoGuid + "]"; } } SDK.GetResult(qqfromid.ToString(), qqfromid.ToString(), ReplyMsg + FaceMsg + HotPicMsg + TextMsg + PicMsg + AudioMsg + VideoMsg); } } var MsgTimeStamp = result.MessageInfo[0].QQInfo.QQFromInfo.RecvTime; using (var mMemoryStream = new MemoryStream()) { Serializer.Serialize(mMemoryStream, result.SyncCoookie); MakeReadedFriendMsg(qqfromid, mMemoryStream.ToArray(), MsgTimeStamp); } } catch (Exception ex) { Debug.Print(ex.Message.ToString()); } } return(API.FriendWithdraw); }
public static API.GroupWithdrawInfo ParsingGroupMsg(byte[] byteIn) { string TextMsg = ""; string FaceMsg = ""; string HotPicMsg = ""; string PicMsg = ""; string AudioMsg = ""; string VideoMsg = ""; string ReplyMsg = ""; var byteLen = BitConverter.ToInt32(byteIn.Take(4).ToArray().Reverse().ToArray(), 0); byteIn = byteIn.Skip(4).ToArray(); using (MemoryStream ms = new MemoryStream(byteIn)) { try { var result = Serializer.Deserialize <GroupMsgStuct>(ms); long QQId = result.GroupInfo.GroupQQInfo.thisQQId; long QQFromId = result.GroupInfo.GroupQQInfo.QQFromId; long GroupId = result.GroupInfo.GroupQQInfo.GroupInfo.GroupId; string GroupName = result.GroupInfo.GroupQQInfo.GroupInfo.GroupName; API.GroupWithdraw.MsgReqId = result.GroupInfo.GroupQQInfo.fromReq; API.GroupWithdraw.MsgRandomId = result.GroupInfo.GroupMessageInfo.GroupMsgInfo.FontInfo.fromRandom; if (QQId == QQFromId) { return(API.GroupWithdraw); } var msgByte = result.GroupInfo.GroupMessageInfo.GroupMsgInfo.GroupMsgContent; Debug.Print("群消息内容:" + "\r\n" + BitConverter.ToString(msgByte).Replace("-", " ")); using (MemoryStream mStream = new MemoryStream(msgByte)) { var MsgResult = Serializer.Deserialize <GroupMessageStruct>(mStream); API.NickName = MsgResult.SendNick.NickName; if (MsgResult.GroupFileMessage != null) //有文件上传的消息 { var FileHash = MsgResult.GroupFileMessage.FileHash; } if (MsgResult.GroupReplyMessage != null) //是带回复的消息 { string replyContent = ""; for (var i = 0; i < MsgResult.GroupReplyMessage.OldMsgContent.Count; i++) { replyContent = replyContent + MsgResult.GroupReplyMessage.OldMsgContent[i].content.Replace("\n", "").Replace("\r", "").Replace("\r\n", ""); } ReplyMsg = " [Reply=@" + MsgResult.GroupReplyMessage.thisQQId.ToString() + "内容:" + replyContent + "]"; } if (MsgResult.GroupTextMsgContent != null) //有文本或小表情或热图内容 { for (var i = 0; i < MsgResult.GroupTextMsgContent.Count; i++) { TextMsg = TextMsg + MsgResult.GroupTextMsgContent[i].content; } } if (MsgResult.BigFace != null) //有大表情内容 { for (var i = 0; i <= MsgResult.BigFace.Count; i++) { var FaceId = MsgResult.BigFace[i].FaceId; FaceMsg = FaceMsg + " [BigFaceId=" + FaceId.ToString() + "]"; } } if (MsgResult.GroupPicMessageContent != null) //有图片内容 { for (var i = 0; i < MsgResult.GroupPicMessageContent.Count; i++) { PicMsg = PicMsg + "https://gchat.qpic.cn" + MsgResult.GroupPicMessageContent[i].PicAddr1.Substring(0, MsgResult.GroupPicMessageContent[i].PicAddr1.LastIndexOf("/")) + "/0 "; } PicMsg = "[pic,link=" + PicMsg + "]"; } if (result.GroupInfo.GroupMessageInfo.GroupMsgInfo.GroupAudioMsgContent != null) //有语音内容 { using (MemoryStream msStream = new MemoryStream(result.GroupInfo.GroupMessageInfo.GroupMsgInfo.GroupAudioMsgContent)) { var Ret = Serializer.Deserialize <AudioMessageStruct>(msStream); AudioMsg = "[Audio,link=" + "http://grouptalk.c2c.qq.com" + Ret.AudioUrl; } } if (MsgResult.GroupVideoMessageContent != null) //有视频内容 { for (var i = 0; i < MsgResult.GroupVideoMessageContent.Count; i++) { VideoMsg = VideoMsg + "[video,guid=" + MsgResult.GroupVideoMessageContent[i].VideoGuid + "]"; } } } SDK.GetResult(GroupId.ToString(), QQFromId.ToString(), "[" + GroupName + "]" + ReplyMsg + FaceMsg + HotPicMsg + TextMsg + PicMsg + AudioMsg + VideoMsg); var MsgSeq = result.GroupInfo.GroupQQInfo.fromReq; MakeReadedGroupMsg(GroupId, MsgSeq); } catch (Exception ex) { Debug.Print(ex.Message.ToString()); } } return(API.GroupWithdraw); }