Example #1
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            //{"retcode":0,"result":{"uin":236557647,"cip":1991953329,"index":1075,"port":51494,"status":"online","vfwebqq":"41778677efd86bae2ed575eea02349046a36f3f53298a34b97d75297ec1e67f6ee5226429daa6aa7","psessionid":"8368046764001d636f6e6e7365727665725f77656271714031302e3133332e342e31373200005b9200000549016e04004f95190e6d0000000a4052347371696a62724f6d0000002841778677efd86bae2ed575eea02349046a36f3f53298a34b97d75297ec1e67f6ee5226429daa6aa7","user_state":0,"f":0}}

            var str     = response.GetResponseString();
            var json    = JObject.Parse(str);
            var session = Context.Session;
            var account = Context.Account;
            var retcode = json["retcode"].ToString();

            if (retcode == "0")
            {
                var ret = json["result"].ToObject <JObject>();
                account.Uin       = ret["uin"].ToObject <long>();
                account.QQ        = ret["uin"].ToObject <long>();
                session.SessionId = ret["psessionid"].ToString();
                // session.Vfwebqq = ret["vfwebqq"].ToString();
                account.Status = QQStatus.ValueOfRaw(ret["status"].ToString());
                session.State  = QQSessionState.Online;
                session.Index  = ret["index"].ToObject <int>();
                session.Port   = ret["port"].ToObject <int>();
                NotifyActionEvent(QQActionEventType.EvtOK, null);
            }
            else
            {
                //var msg = $"errmsg: {json["errmsg"] ?? ""}, retcode: {retcode}";
                //NotifyActionEvent(QQActionEventType.EVT_ERROR, new QQException(QQErrorCode.INVALID_RESPONSE, msg));	//TODO ..
                throw new QQException(QQErrorCode.UnexpectedResponse, str);
            }
        }
Example #2
0
 /// <summary>
 /// 处理好友状态变化
 /// </summary>
 /// <param name="pollData"></param>
 /// <returns></returns>
 private QQNotifyEvent ProcessBuddyStatusChange(JObject pollData)
 {
     try
     {
         var uin   = pollData["uin"].ToObject <long>();
         var buddy = Context.Store.GetBuddyByUin(uin);
         if (buddy == null)
         {
             buddy = new QQBuddy()
             {
                 Uin = uin
             };
             Context.Store.AddBuddy(buddy);
             var userModule = Context.GetModule <UserModule>(QQModuleType.USER);
             userModule.GetUserInfo(buddy, null);
         }
         var status     = pollData["status"].ToString();
         var clientType = pollData["client_type"].ToObject <int>();
         buddy.Status     = QQStatus.ValueOfRaw(status);
         buddy.ClientType = QQClientTypeInfo.ValueOfRaw(clientType);
         return(new QQNotifyEvent(QQNotifyEventType.BuddyStatusChange, buddy));
     }
     catch (Exception ex)
     {
         return(new QQNotifyEvent(QQNotifyEventType.NetError, ex));
     }
 }
Example #3
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            var str   = response.ResponseString;
            var json  = JObject.Parse(str);
            var store = Context.Store;

            if (json["retcode"].ToString() == "0")
            {
                var result = json["result"].ToObject <JArray>();
                foreach (var token in result)
                {
                    var obj        = token.ToObject <JObject>();
                    var uin        = obj["uin"].ToObject <long>();
                    var status     = obj["status"].ToString();
                    var clientType = obj["client_type"].ToObject <int>();
                    var buddy      = store.GetBuddyByUinOrAdd(uin);
                    buddy.Status     = QQStatus.ValueOfRaw(status);
                    buddy.ClientType = QQClientTypeInfo.ValueOfRaw(clientType);
                }
                NotifyActionEvent(QQActionEventType.EvtOK, null);
            }
            else
            {
                throw new QQException(QQErrorCode.InvalidResponse, str);
            }
        }
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            JObject json  = JObject.Parse(response.GetResponseString());
            QQStore store = Context.Store;

            if (json["retcode"].ToString() == "0")
            {
                JArray result = json["result"].ToObject <JArray>();
                for (int i = 0; i < result.Count; i++)
                {
                    JObject obj        = result[i].ToObject <JObject>();
                    long    uin        = obj["uin"].ToObject <long>();
                    string  status     = obj["status"].ToString();
                    int     clientType = obj["client_type"].ToObject <int>();

                    QQBuddy buddy = store.GetBuddyByUin(uin);
                    buddy.Status     = QQStatus.ValueOfRaw(status);
                    buddy.ClientType = QQClientType.ValueOfRaw(clientType);
                }
            }

            NotifyActionEvent(QQActionEventType.EVT_OK, store.GetOnlineBuddyList());
        }
Example #5
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            JObject json = JObject.Parse(response.GetResponseString());

            if (json["retcode"].ToString() == "0")
            {
                json = json["result"].ToObject <JObject>();

                // 消除所有成员状态,如果不在线的,webqq是不会返回的。
                foreach (QQGroupMember member in group.Members)
                {
                    member.Status     = QQStatus.OFFLINE;
                    member.ClientType = QQClientType.Unknown;
                }

                //result/stats
                JArray stats = json["stats"].ToObject <JArray>();
                for (int i = 0; i < stats.Count; i++)
                {
                    // 下面重新设置最新状态
                    JObject       stat   = stats[i].ToObject <JObject>();
                    QQGroupMember member = group.GetMemberByUin(stat["uin"].ToObject <long>());
                    if (member != null)
                    {
                        member.ClientType = QQClientType.ValueOfRaw(stat["client_type"].ToObject <int>());
                        member.Status     = QQStatus.ValueOfRaw(stat["stat"].ToObject <int>());
                    }
                }

                NotifyActionEvent(QQActionEventType.EVT_OK, group);
            }
            else
            {
                NotifyActionEvent(QQActionEventType.EVT_ERROR, QQErrorCode.UNEXPECTED_RESPONSE);
            }
        }
Example #6
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            var json = JObject.Parse(response.GetResponseString());

            if (json["retcode"].ToString() == "0")
            {
                json = json["result"].ToObject <JObject>();

                // 消除所有成员状态,如果不在线的,webqq是不会返回的。
                foreach (var member in _group.Members)
                {
                    member.Status     = QQStatus.OFFLINE;
                    member.ClientType = QQClientType.Unknown;
                }

                //result/stats
                var stats = json["stats"].ToObject <JArray>();
                for (var i = 0; i < stats.Count; i++)
                {
                    // 下面重新设置最新状态
                    var stat   = stats[i].ToObject <JObject>();
                    var member = _group.GetMemberByUin(stat["uin"].ToObject <long>());
                    if (member != null)
                    {
                        member.ClientType = QQClientTypeInfo.ValueOfRaw(stat["client_type"].ToObject <int>());
                        member.Status     = QQStatus.ValueOfRaw(stat["stat"].ToObject <int>());
                    }
                }

                NotifyActionEvent(QQActionEventType.EvtOK, _group);
            }
            else
            {
                NotifyActionEvent(QQActionEventType.EvtError, QQErrorCode.UnexpectedResponse);
            }
        }
Example #7
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            JObject json = JObject.Parse(response.GetResponseString());

            if (json["retcode"].ToString() == "0")
            {
                json = json["result"].ToObject <JObject>();
                JObject ginfo = json["ginfo"].ToObject <JObject>();
                group.Memo       = ginfo["memo"].ToString();
                group.Level      = ginfo["level"].ToObject <int>();
                group.CreateTime = new DateTime(ginfo["createtime"].ToObject <int>());

                JArray members = ginfo["members"].ToObject <JArray>();
                for (int i = 0; i < members.Count; i++)
                {
                    JObject       memjson = members[i].ToObject <JObject>();
                    QQGroupMember member  = group.GetMemberByUin(memjson["muin"].ToObject <long>());
                    if (member == null)
                    {
                        member = new QQGroupMember();
                        group.Members.Add(member);
                    }
                    member.Uin   = memjson["muin"].ToObject <long>();
                    member.Group = group;
                    //memjson["mflag"]; //TODO ...
                }

                //result/minfo
                JArray minfos = json["minfo"].ToObject <JArray>();
                for (int i = 0; i < minfos.Count; i++)
                {
                    JObject       minfo  = minfos[i].ToObject <JObject>();
                    QQGroupMember member = group.GetMemberByUin(minfo["uin"].ToObject <int>());
                    member.Nickname = minfo["nick"].ToString();
                    member.Province = minfo["province"].ToString();
                    member.Country  = minfo["country"].ToString();
                    member.City     = minfo["city"].ToString();
                    member.Gender   = minfo["gender"].ToString();
                }

                //result/stats
                JArray stats = json["stats"].ToObject <JArray>();
                for (int i = 0; i < stats.Count; i++)
                {
                    // 下面重新设置最新状态
                    JObject       stat   = stats[i].ToObject <JObject>();
                    QQGroupMember member = group.GetMemberByUin(stat["uin"].ToObject <long>());
                    member.ClientType = QQClientType.ValueOfRaw(stat["client_type"].ToObject <int>());
                    member.Status     = QQStatus.ValueOfRaw(stat["stat"].ToObject <int>());
                }

                //results/cards
                if (json["cards"] != null)
                {
                    JArray cards = json["cards"].ToObject <JArray>();
                    for (int i = 0; i < cards.Count; i++)
                    {
                        JObject       card   = cards[i].ToObject <JObject>();
                        QQGroupMember member = group.GetMemberByUin(card["muin"].ToObject <long>());
                        if (card["card"] != null && member != null)
                        {
                            member.Card = card["card"].ToString();
                        }
                    }
                }

                //results/vipinfo
                JArray vipinfos = json["vipinfo"].ToObject <JArray>();
                for (int i = 0; i < vipinfos.Count; i++)
                {
                    JObject       vipinfo = vipinfos[i].ToObject <JObject>();
                    QQGroupMember member  = group.GetMemberByUin(vipinfo["u"].ToObject <long>());
                    member.VipLevel = vipinfo["vip_level"].ToObject <int>();
                    member.IsVip    = (vipinfo["is_vip"].ToString() != "0");
                }

                NotifyActionEvent(QQActionEventType.EVT_OK, group);
            }
            else
            {
                NotifyActionEvent(QQActionEventType.EVT_ERROR, QQErrorCode.UNEXPECTED_RESPONSE);
            }
        }
Example #8
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            var json  = JObject.Parse(response.GetResponseString());
            var store = Context.Store;

            if (json["retcode"].ToString() == "0")
            {
                var result = json["result"].ToObject <JObject>();

                //result/info
                var info = result["info"].ToObject <JObject>();
                discuz.Name  = info["discu_name"].ToString();
                discuz.Owner = info["discu_owner"].ToObject <long>();

                //result/mem_list
                var memlist = result["mem_info"].ToObject <JArray>();
                foreach (var t in memlist)
                {
                    var memjson = t.ToObject <JObject>();
                    var member  = discuz.GetMemberByUin(memjson["uin"].ToObject <long>());
                    if (member == null)
                    {
                        member = new QQDiscuzMember();
                        discuz.AddMemeber(member);
                    }
                    member.Uin      = memjson["uin"].ToObject <long>();
                    member.QQ       = memjson["uin"].ToObject <long>(); //这里有用户真实的QQ号
                    member.Nickname = memjson["nick"].ToString();
                    member.Discuz   = discuz;
                }

                // 消除所有成员状态,如果不在线的,webqq是不会返回的。
                discuz.ClearStatus();
                //result/mem_status
                var statlist = result["mem_status"].ToObject <JArray>();
                foreach (var t in statlist)
                {
                    // 下面重新设置最新状态
                    var    statjson = t.ToObject <JObject>();
                    QQUser member   = discuz.GetMemberByUin(statjson["uin"].ToObject <long>());
                    if (statjson["client_type"] != null && member != null)
                    {
                        member.ClientType = QQClientTypeInfo.ValueOfRaw(statjson["client_type"].ToObject <int>());
                        member.Status     = QQStatus.ValueOfRaw(statjson["status"].ToString());
                    }
                }

                //result/mem_info
                var infolist = result["mem_info"].ToObject <JArray>();
                foreach (var t in infolist)
                {
                    var    infojson = t.ToObject <JObject>();
                    QQUser member   = discuz.GetMemberByUin(infojson["uin"].ToObject <long>());
                    member.Nickname = infojson["nick"].ToString();
                }

                NotifyActionEvent(QQActionEventType.EvtOK, store.GetDiscuzList());
            }
            else
            {
                NotifyActionEvent(QQActionEventType.EvtError, new QQException(QQErrorCode.UnexpectedResponse));
            }
        }
Example #9
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            var str  = response.GetResponseString();
            var json = JObject.Parse(str);

            if (json["retcode"].ToString() == "0")
            {
                var result = json["result"].ToObject <JObject>();
                var ginfo  = result["ginfo"].ToObject <JObject>();
                _group.Memo  = ginfo["memo"].ToString();
                _group.Level = ginfo["level"].ToObject <int>();
                var ticks = ginfo["createtime"].ToObject <long>() * 1000;
                _group.CreateTime = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks);

                var members = ginfo["members"].ToObject <JArray>();
                for (var i = 0; i < members.Count; i++)
                {
                    var memjson = members[i].ToObject <JObject>();
                    var member  = _group.GetMemberByUin(memjson["muin"].ToObject <long>());
                    if (member == null)
                    {
                        member = new QQGroupMember();
                        _group.Members.Add(member);
                    }
                    member.Uin   = memjson["muin"].ToObject <long>();
                    member.Group = _group;
                    //memjson["mflag"]; //TODO ...
                }

                //result/minfo
                var minfos = result["minfo"].ToObject <JArray>();
                foreach (var token in minfos)
                {
                    var minfo  = token.ToObject <JObject>();
                    var member = _group.GetMemberByUin(minfo["uin"].ToObject <long>());
                    member.Nickname = minfo["nick"].ToString();
                    member.Province = minfo["province"].ToString();
                    member.Country  = minfo["country"].ToString();
                    member.City     = minfo["city"].ToString();
                    member.Gender   = minfo["gender"].ToString();
                }

                //result/stats
                var stats = result["stats"].ToObject <JArray>();
                for (var i = 0; i < stats.Count; i++)
                {
                    // 下面重新设置最新状态
                    var stat   = stats[i].ToObject <JObject>();
                    var member = _group.GetMemberByUin(stat["uin"].ToObject <long>());
                    member.ClientType = QQClientTypeInfo.ValueOfRaw(stat["client_type"].ToObject <int>());
                    member.Status     = QQStatus.ValueOfRaw(stat["stat"].ToObject <int>());
                }

                //results/cards
                if (result["cards"] != null)
                {
                    var cards = result["cards"].ToObject <JArray>();
                    for (var i = 0; i < cards.Count; i++)
                    {
                        var card   = cards[i].ToObject <JObject>();
                        var member = _group.GetMemberByUin(card["muin"].ToObject <long>());
                        if (card["card"] != null && member != null)
                        {
                            member.Card = card["card"].ToString();
                        }
                    }
                }

                //results/vipinfo
                var vipinfos = result["vipinfo"].ToObject <JArray>();
                for (var i = 0; i < vipinfos.Count; i++)
                {
                    var vipinfo = vipinfos[i].ToObject <JObject>();
                    var member  = _group.GetMemberByUin(vipinfo["u"].ToObject <long>());
                    member.VipLevel = vipinfo["vip_level"].ToObject <int>();
                    member.IsVip    = (vipinfo["is_vip"].ToString() != "0");
                }

                NotifyActionEvent(QQActionEventType.EvtOK, _group);
            }
            else
            {
                // NotifyActionEvent(QQActionEventType.EVT_ERROR, QQErrorCode.UNEXPECTED_RESPONSE);
                throw new QQException(QQErrorCode.UnexpectedResponse, str);
            }
        }
Example #10
0
        private async Task LoginAsync()
        {
            var loginStatusIndex = 0;

            cboLoginStatus.Invoke(new MethodInvoker(() =>
            {
                loginStatusIndex = cboLoginStatus.SelectedIndex;
            }));
            var status = QQStatus.ValueOfRaw(LoginStatus[1][loginStatusIndex]);

            var qqCount = 0;

            lvQQList.Invoke(new MethodInvoker(() =>
            {
                qqCount = lvQQList.Items.Count;
            }));
            for (var i = 0; i < qqCount; ++i)
            {
                var qqNumber = "";
                var index    = i;
                lvQQList.Invoke(new MethodInvoker(() =>
                {
                    qqNumber = lvQQList.Items[index].SubItems[1].Text;
                    lvQQList.SelectedIndices.Clear();
                    lvQQList.Focus();
                    lvQQList.Items[index].Selected = true;
                    lvQQList.Items[index].EnsureVisible();
                    lvQQList.Items[index].SubItems[4].Text = "正在登录";
                }));

                var client = _qqClients[qqNumber];
                if (QQStatus.IsGeneralOnline(client.Account.Status))
                {
                    if (client.Account.Status != status)
                    {
                        client.ChangeStatus(status).WaitFinalEvent(1000);
                    }
                    UpdateQQInfo(client, i);
                    continue;
                }
                (client as WebQQClient)?.ReadCookie();
                //测试同步模式登录
                var future = client.Login(status, _eventHandler);
                ShowMessage(client.Account.Username + "-登录中......");

                var Event = await future.WhenFinalEvent();

                if (Event.Type == QQActionEventType.EVT_OK)
                {
                    ShowMessage(client.Account.Username + "-登录成功!!!");
                    (client as WebQQClient)?.SaveCookie();
                    await client.GetUserInfo(client.Account, _eventHandler).WhenFinalEvent();

                    await client.GetUserLevel(client.Account, _eventHandler).WhenFinalEvent();

                    UpdateQQInfo(client, i);

                    if (qqCount < 5)
                    {
                        var actionEvent = await client.GetBuddyList(_eventHandler).WhenFinalEvent();

                        ShowMessage(QQActionEventType.EVT_OK == actionEvent.Type
                            ? $"{client.Account.Username}-好友数量:{client.GetBuddyList().Count}"
                            : string.Format(client.Account.Username + "-获取好友列表失败"));

                        actionEvent = await client.GetGroupList(_eventHandler).WhenFinalEvent();

                        ShowMessage(QQActionEventType.EVT_OK == actionEvent.Type
                            ? $"{client.Account.Username}-群数量:{client.GetGroupList().Count}"
                            : string.Format(client.Account.Username + "-获取群列表失败"));
                    }

                    client.BeginPollMsg();
                }
                else if (Event.Type == QQActionEventType.EVT_ERROR)
                {
                    client.Account.Status = QQStatus.OFFLINE;
                    var ex = (QQException)Event.Target;
                    ShowMessage(ex.Message);
                    UpdateQQInfo(client);
                }
                else
                {
                    client.Account.Status = QQStatus.OFFLINE;
                    ShowMessage(client.Account.Username + "-登录失败");
                    UpdateQQInfo(client);
                }
            }
            lvQQList.Invoke(new MethodInvoker(() =>
            {
                lvQQList.SelectedIndices.Clear();
            }));
        }