Exemple #1
0
        /// <summary>
        /// 处理临时会话消息
        /// </summary>
        /// <param name="pollData"></param>
        /// <returns></returns>
        public 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 (QQGroupMember 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 (QQDiscuzMember 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"] + ""
                        };
                        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.CHAT_MSG, msg);
            }
            catch (Exception ex)
            {
                return new QQNotifyEvent(QQNotifyEventType.NET_ERROR, ex);
            }
        }
Exemple #2
0
 public IQQActionFuture GetSessionMsgSig(QQStranger user, QQActionListener listener)
 {
     return PushHttpAction(new GetSessionMsgSigAction(Context, listener, user));
 }
 public GetSessionMsgSigAction(QQContext context, QQActionEventHandler listener,
         QQStranger user)
     : base(context, listener)
 {
     this.user = user;
 }
Exemple #4
0
 public void AddStranger(QQStranger stranger)
 {
     _strangerMap[stranger.Uin] = stranger;
 }
Exemple #5
0
 public void DeleteStranger(QQStranger stranger)
 {
     _strangerMap.TryRemove(stranger.Uin, out stranger);
 }
Exemple #6
0
 public void DeleteStranger(QQStranger stranger)
 {
     _strangerMap.Remove(stranger.Uin);
 }
Exemple #7
0
 public void AddStranger(QQStranger stranger)
 {
     _strangerMap.Add(stranger.Uin, stranger, AddChoice.Update);
 }
Exemple #8
0
 public QQActionFuture GetSessionMsgSig(QQStranger user, QQActionEventHandler listener)
 {
     return PushHttpAction(new GetSessionMsgSigAction(this.Context, listener, user));
 }