Пример #1
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            // {"retcode":0,"result":{"gmasklist":[{"gid":1000,"mask":0},{"gid":1638195794,"mask":0},{"gid":321105219,"mask":0}],
            // "gnamelist":[{"flag":16777217,"name":"iQQ","gid":1638195794,"code":2357062609},{"flag":1048577,"name":"iQQ核心开发区","gid":321105219,"code":640215156}],"gmarklist":[]}}
            QQStore store = Context.Store;
            JObject json = JObject.Parse(response.GetResponseString());

            int retcode = json["retcode"].ToObject<int>();
            if (retcode == 0)
            {
                // 处理好友列表
                JObject results = json["result"].ToObject<JObject>();
                JArray groupJsonList = results["gnamelist"].ToObject<JArray>();	// 群列表

                // 禁止接收群消息标志:正常 0, 接收不提醒 1, 完全屏蔽 2
                JArray groupMaskJsonList = results["gmasklist"].ToObject<JArray>();

                foreach (JToken t in groupJsonList)
                {
                    JObject groupJson = t.ToObject<JObject>();
                    QQGroup group = new QQGroup();
                    group.Gin = groupJson["gid"].ToObject<long>();
                    group.Code = groupJson["code"].ToObject<long>();
                    group.Flag = groupJson["flag"].ToObject<int>();
                    group.Name = groupJson["name"].ToString();
                    //添加到Store
                    store.AddGroup(group);
                }

                foreach (JToken t in groupMaskJsonList)
                {
                    JObject maskObj = t.ToObject<JObject>();
                    long gid = maskObj["gid"].ToObject<long>();
                    int mask = maskObj["mask"].ToObject<int>();
                    QQGroup group = store.GetGroupByGin(gid);
                    if (group != null)
                    {
                        group.Mask = mask;
                    }
                }

                NotifyActionEvent(QQActionEventType.EVT_OK, store.GetGroupList());

            }
            else
            {
                // LOG.warn("unknown retcode: " + retcode);
                NotifyActionEvent(QQActionEventType.EVT_ERROR, null);
            }

        }
Пример #2
0
 public GetGroupInfoAction(IQQContext context, QQActionListener listener, QQGroup group)
     : base(context, listener)
 {
     this._group = group;
 }
Пример #3
0
 public GetGroupMemberStatusAction(QQContext context, QQActionEventHandler listener, QQGroup group)
     : base(context, listener)
 {
     this.group = group;
 }
Пример #4
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);
            }
        }
Пример #5
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            /*
                {
                    "retcode": 0,
                    "result": {
                        "gmasklist": [
                            {
                                "gid": 1000,
                                "mask": "3"
                            }
                        ],
                        "gnamelist": [
                            {
                                "flag": 184550417,
                                "name": "iQQ",
                                "gid": 2920037469,
                                "code": 1478013841
                            },
                        ],
                        "gmarklist": []
                    }
                }
            */
            var store = Context.Store;
            var str = response.GetResponseString();
            var json = JObject.Parse(str);

            var retcode = json["retcode"].ToString();
            if (retcode == "0")
            {
                // 处理好友列表
                var results = json["result"].ToObject<JObject>();
                var groupJsonList = results["gnamelist"].ToObject<JArray>();	// 群列表

                // 禁止接收群消息标志:正常 0, 接收不提醒 1, 完全屏蔽 2
                var groupMaskJsonList = results["gmasklist"].ToObject<JArray>();

                foreach (var t in groupJsonList)
                {
                    var groupJson = t.ToObject<JObject>();
                    var group = new QQGroup()
                    {
                        Gid = groupJson["gid"].ToObject<long>(),
                        Code = groupJson["code"].ToObject<long>(),
                        Flag = groupJson["flag"].ToObject<long>(),
                        Name = groupJson["name"].ToString(),
                    };
                    group.Gin = group.Gid;
                    //添加到Store
                    store.AddGroup(group);
                }

                foreach (var t in groupMaskJsonList)
                {
                    var maskObj = t.ToObject<JObject>();
                    var gid = maskObj["gid"].ToObject<long>();
                    var mask = maskObj["mask"].ToObject<int>();
                    var group = store.GetGroupByGin(gid);
                    if (group != null)
                    {
                        group.Mask = mask;
                    }
                }

                NotifyActionEvent(QQActionEventType.EvtOK, store.GetGroupList());

            }
            else
            {
                // LOG.warn("unknown retcode: " + retcode);
                // NotifyActionEvent(QQActionEventType.EVT_ERROR, null);
                throw new QQException(QQErrorCode.InvalidResponse, str);
            }
        }
Пример #6
0
        /// <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);
            }
        }
Пример #7
0
 public IQQActionFuture GetGroupGid(QQGroup group, QQActionListener listener = null)
 {
     return PushHttpAction(new GetGroupAccoutAction(Context, listener, group));
 }
Пример #8
0
 public IQQActionFuture GetMemberStatus(QQGroup group, QQActionListener listener = null)
 {
     return PushHttpAction(new GetGroupMemberStatusAction(Context, listener, group));
 }
Пример #9
0
 public void AddGroup(QQGroup group)
 {
     _groupMap[group.Code] = group;
 }
Пример #10
0
 public void DeleteGroup(QQGroup group)
 {
     _groupMap.TryRemove(group.Gin, out group);
 }
Пример #11
0
 public void DeleteGroup(QQGroup group)
 {
     _groupMap.Remove(group.Gin);
 }
Пример #12
0
 public void AddGroup(QQGroup group)
 {
     _groupMap.Add(group.Code, group, AddChoice.Update);
 }
Пример #13
0
 public QQActionFuture GetMemberStatus(QQGroup group, QQActionEventHandler listener)
 {
     return PushHttpAction(new GetGroupMemberStatusAction(Context, listener, group));
 }
Пример #14
0
 public QQActionFuture GetGroupGid(QQGroup group, QQActionEventHandler listener)
 {
     return PushHttpAction(new GetGroupAccoutAction(Context, listener, group));
 }
Пример #15
0
 public GetGroupAccoutAction(QQContext context, QQActionEventHandler listener, QQGroup group)
     : base(context, listener)
 {
     this.group = group;
 }