/// <summary> /// 处理好友信息 /// </summary> /// <param name="pollData"></param> /// <returns></returns> private QQNotifyEvent ProcessBuddyMsg(JObject pollData) { /* * { * "content": [ * [ * "font", * { * "color": "000000", * "name": "微软雅黑", * "size": 10, * "style": [0, 0, 0] * } * ], * "你好!" * ], * "from_uin": 1000693217, * "msg_id": 25426, * "msg_type": 0, * "time": 1472754511, * "to_uin": 89009143 * } */ try { var store = Context.Store; var fromUin = pollData["from_uin"].ToObject <long>(); var ticks = pollData["time"].ToObject <long>() * 1000; var msg = new QQMsg { Id = pollData["msg_id"].ToObject <long>(), Type = QQMsgType.BUDDY_MSG, To = Context.Account, From = store.GetBuddyByUin(fromUin), Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks), // Id2 = pollData["msg_id2"]?.ToObject<long>() ?? 0 }; msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"])); if (msg.From == null) { var member = new QQBuddy() { Uin = fromUin }; store.AddBuddy(member); // 获取用户信息 var userModule = Context.GetModule <UserModule>(QQModuleType.USER); userModule.GetUserInfo(member); msg.From = member; } return(new QQNotifyEvent(QQNotifyEventType.ChatMsg, msg)); } catch (Exception ex) { return(new QQNotifyEvent(QQNotifyEventType.NetError, ex)); } }
/// <summary> /// 处理讨论组信息 /// </summary> /// <param name="pollData"></param> /// <returns></returns> private QQNotifyEvent ProcessDiscuzMsg(JObject pollData) { try { var store = Context.Store; var msg = new QQMsg(); var fromUin = pollData["send_uin"].ToObject <long>(); var did = pollData["did"].ToObject <long>(); msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"])); msg.Type = QQMsgType.DISCUZ_MSG; msg.Discuz = store.GetDiscuzByDid(did); msg.To = Context.Account; var ticks = pollData["time"].ToObject <long>() * 1000; msg.Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks); if (msg.Discuz == null) { var discuz = new QQDiscuz(); discuz.Did = did; store.AddDiscuz(discuz); msg.Discuz = store.GetDiscuzByDid(did); var discuzModule = Context.GetModule <DiscuzModule>(QQModuleType.DISCUZ); discuzModule.GetDiscuzInfo(discuz, null); } msg.From = msg.Discuz.GetMemberByUin(fromUin); if (msg.From == null) { var member = new QQDiscuzMember { Uin = fromUin }; msg.From = member; msg.Discuz.Members.Add(member); // 获取用户信息 var userModule = Context.GetModule <UserModule>(QQModuleType.USER); userModule.GetUserInfo(member, null); } return(new QQNotifyEvent(QQNotifyEventType.GroupMsg, msg)); } catch (Exception ex) { return(new QQNotifyEvent(QQNotifyEventType.NetError, ex)); } }
/// <summary> /// 处理好友信息 /// </summary> /// <param name="pollData"></param> /// <returns></returns> public QQNotifyEvent ProcessBuddyMsg(JObject pollData) { try { var store = Context.Store; var fromUin = pollData["from_uin"].ToObject <long>(); var msg = new QQMsg { Id = pollData["msg_id"].ToObject <long>(), Id2 = pollData["msg_id2"].ToObject <long>() }; msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"])); msg.Type = QQMsgType.BUDDY_MSG; msg.To = Context.Account; msg.From = store.GetBuddyByUin(fromUin); var ticks = pollData["time"].ToObject <long>() * 1000; msg.Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks); if (msg.From == null) { var member = new QQBuddy() { Uin = fromUin }; store.AddBuddy(member); // 获取用户信息 var userModule = Context.GetModule <UserModule>(QQModuleType.USER); userModule.GetUserInfo(member, null); msg.From = member; } return(new QQNotifyEvent(QQNotifyEventType.CHAT_MSG, msg)); } catch (Exception ex) { return(new QQNotifyEvent(QQNotifyEventType.NET_ERROR, ex)); } }
/// <summary> /// 处理临时会话消息 /// </summary> /// <param name="pollData"></param> /// <returns></returns> private QQNotifyEvent ProcessSessionMsg(JObject pollData) { // {"retcode":0,"result":[{"poll_type":"sess_message", // "value":{"msg_id":25144,"from_uin":167017143,"to_uin":1070772010,"msg_id2":139233,"msg_type":140,"reply_ip":176752037,"time":1365931836,"id":2581801127,"ruin":444674479,"service_type":1, // "flags":{"text":1,"pic":1,"file":1,"audio":1,"video":1},"content":[["font",{"size":9,"color":"000000","style":[0,0,0],"name":"Tahoma"}],"2\u8F7D3 ",["face",1]," "]}}]} try { var store = Context.Store; var msg = new QQMsg(); var fromUin = pollData["from_uin"].ToObject <long>(); var fromQQ = pollData["ruin"].ToObject <long>(); // 真实QQ var serviceType = pollData["service_type"].ToObject <int>(); // Group:0,Discuss:1 var typeId = pollData["id"].ToObject <long>(); // Group ID or Discuss ID msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"])); msg.Type = QQMsgType.SESSION_MSG; msg.To = Context.Account; var ticks = pollData["time"].ToObject <long>() * 1000; msg.Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks); QQUser user = store.GetBuddyByUin(fromUin); // 首先看看是不是自己的好友 if (user != null) { msg.Type = QQMsgType.BUDDY_MSG; // 是自己的好友 } else { if (serviceType == 0) { // 是群成员 var group = store.GetGroupByCode(typeId); if (group == null) { group = new QQGroup(); group.Code = typeId; // 获取群信息 var groupModule = Context.GetModule <GroupModule>(QQModuleType.GROUP); groupModule.GetGroupInfo(group, null); } foreach (var u in group.Members) { if (u.Uin == fromUin) { user = u; break; } } } else if (serviceType == 1) { // 是讨论组成员 var discuz = store.GetDiscuzByDid(typeId); if (discuz == null) { discuz = new QQDiscuz { Did = typeId }; // 获取讨论组信息 var discuzModule = Context.GetModule <DiscuzModule>(QQModuleType.DISCUZ); discuzModule.GetDiscuzInfo(discuz, null); } foreach (var u in discuz.Members) { if (u.Uin == fromUin) { user = u; break; } } } else { user = store.GetStrangerByUin(fromUin); // 看看陌生人列表中有木有 } if (user == null) { // 还没有就新建一个陌生人,原理来说不应该这样。后面我就不知道怎么回复这消息了,但是消息是不能丢失的 user = new QQStranger { QQ = pollData["ruin"].ToObject <long>(), Uin = fromUin, Nickname = pollData["ruin"].ToString() }; store.AddStranger((QQStranger)user); // 获取用户信息 var userModule = Context.GetModule <UserModule>(QQModuleType.USER); userModule.GetStrangerInfo(user, null); } } user.QQ = fromQQ; // 带上QQ号码 msg.From = user; return(new QQNotifyEvent(QQNotifyEventType.ChatMsg, msg)); } catch (Exception ex) { return(new QQNotifyEvent(QQNotifyEventType.NetError, ex)); } }
/// <summary> /// 处理群消息 /// </summary> /// <param name="pollData"></param> /// <returns></returns> private QQNotifyEvent ProcessGroupMsg(JObject pollData) { /* * { * "content": [ * [ * "font", * { * "color": "000000", * "name": "微软雅黑", * "size": 10, * "style": [ * 0, * 0, * 0 * ] * } * ], * "d" * ], * "from_uin": 3471070329, * "group_code": 3471070329, * "msg_id": 29208, * "msg_type": 0, * "send_uin": 1000693217, * "time": 1472803177, * "to_uin": 89009143 * } */ try { var store = Context.Store; var groupMudule = Context.GetModule <GroupModule>(QQModuleType.GROUP); var ticks = pollData["time"].ToObject <long>() * 1000; var msg = new QQMsg { Id = pollData["msg_id"].ToObject <long>(), Type = QQMsgType.GROUP_MSG, To = Context.Account, Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks), }; var fromUin = pollData["send_uin"].ToObject <long>(); var code = pollData["group_code"].ToObject <long>(); // 实际上是gid不是gcode var group = store.GetGroupById(code); if (group == null) { groupMudule.GetGroupList(); group = new QQGroup { Gid = code }; } groupMudule.GetGroupInfo(group); msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"])); msg.Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks); msg.Group = group; msg.From = group.GetMemberByUin(fromUin); if (msg.From == null) { var member = new QQGroupMember { Uin = fromUin }; msg.From = member; group.Members.Add(member); // 获取用户信息 var userModule = Context.GetModule <UserModule>(QQModuleType.USER); userModule.GetUserInfo(member); } return(new QQNotifyEvent(QQNotifyEventType.GroupMsg, msg)); } catch (Exception ex) { return(new QQNotifyEvent(QQNotifyEventType.NetError, ex)); } }
/// <summary> /// 处理群消息 /// </summary> /// <param name="pollData"></param> /// <returns></returns> public QQNotifyEvent ProcessGroupMsg(JObject pollData) { // {"retcode":0,"result":[{"poll_type":"group_message", // "value":{"msg_id":6175,"from_uin":3924684389,"to_uin":1070772010,"msg_id2":992858,"msg_type":43,"reply_ip":176621921, // "group_code":3439321257,"send_uin":1843694270,"seq":875,"time":1365934781,"info_seq":170125666,"content":[["font",{"size":10,"color":"3b3b3b","style":[0,0,0],"name":"\u5FAE\u8F6F\u96C5\u9ED1"}],"eeeeeeeee "]}}]} try { var store = Context.Store; var msg = new QQMsg { Id = pollData["msg_id"].ToObject <long>(), Id2 = pollData["msg_id2"].ToObject <long>() }; var fromUin = pollData["send_uin"].ToObject <long>(); var groupCode = pollData["group_code"].ToObject <long>(); var groupId = pollData["info_seq"].ToObject <long>(); // 真实群号码 var group = store.GetGroupByCode(groupCode); if (group == null) { var groupModule = Context.GetModule <GroupModule>(QQModuleType.GROUP); group = new QQGroup { Code = groupCode, Gid = groupId }; // put to store store.AddGroup(group); groupModule.GetGroupInfo(group, null); } if (group.Gid <= 0) { group.Gid = groupId; } msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"])); msg.Type = QQMsgType.GROUP_MSG; msg.To = Context.Account; var ticks = pollData["time"].ToObject <long>() * 1000; msg.Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks); msg.Group = group; msg.From = group.GetMemberByUin(fromUin); if (msg.From == null) { var member = new QQGroupMember { Uin = fromUin }; msg.From = member; group.Members.Add(member); // 获取用户信息 var userModule = Context.GetModule <UserModule>(QQModuleType.USER); userModule.GetUserInfo(member, null); } return(new QQNotifyEvent(QQNotifyEventType.CHAT_MSG, msg)); } catch (Exception ex) { return(new QQNotifyEvent(QQNotifyEventType.NET_ERROR, ex)); } }