예제 #1
0
        public override QQHttpRequest OnBuildRequest()
        {
/*
 *          retype:1 app:EQQ
 *          itemlist:{"groupmask":{"321105219":"1","1638195794":"0","cAll":0,"idx":1075,"port":37883}}
 *          vfwebqq:8b26c442e239630f250e1e74d135fd85ab78c38e7b8da1c95a2d1d560bdebd2691443df19d87e70d
 */
            QQStore       store   = Context.Store;
            QQSession     session = Context.Session;
            QQHttpRequest req     = CreateHttpRequest("POST", QQConstants.URL_GROUP_MESSAGE_FILTER);

            req.AddPostValue("retype", "1");    // 群???
            req.AddPostValue("app", "EQQ");

            JObject groupmask = new JObject();

            groupmask.Add("cAll", 0);
            groupmask.Add("idx", session.Index);
            groupmask.Add("port", session.Port);
            foreach (QQGroup g in store.GetGroupList())
            {
                if (g.Gin > 0)
                {
                    groupmask.Add(g.Gin + "", g.Mask + "");
                }
            }
            JObject itemlist = new JObject();

            itemlist.Add("groupmask", groupmask);
            req.AddPostValue("itemlist", itemlist.ToString());
            req.AddPostValue("vfwebqq", Context.Session.Vfwebqq);
            return(req);
        }
예제 #2
0
        /// <summary>
        /// 构造方法,初始化模块和服务
        /// </summary>
        ///// <param name="username">账号(二维码登录留空)</param>
        ///// <param name="password">密码(二维码登录留空)</param>
        /// <param name="notifyListener">监听器</param>
        /// <param name="actorDispatcher">线程执行器</param>
        /// <param name="logger">日志记录器</param>
        public WebQQClient(QQNotifyListener notifyListener    = null,
                           IQQActorDispatcher actorDispatcher = null, IQQLogger logger = null)
        {
            _modules  = new Dictionary <QQModuleType, IQQModule>();
            _services = new Dictionary <QQServiceType, IQQService>();

            _modules.Add(QQModuleType.LOGIN, new LoginModule());
            _modules.Add(QQModuleType.PROC, new ProcModule());
            _modules.Add(QQModuleType.USER, new UserModule());
            _modules.Add(QQModuleType.BUDDY, new BuddyModule());
            _modules.Add(QQModuleType.CATEGORY, new CategoryModule());
            _modules.Add(QQModuleType.GROUP, new GroupModule());
            _modules.Add(QQModuleType.CHAT, new ChatModule());
            _modules.Add(QQModuleType.DISCUZ, new DiscuzModule());
            _modules.Add(QQModuleType.EMAIL, new EmailModule());
            _services.Add(QQServiceType.HTTP, new HttpService());

            Account = new QQAccount
            {
                Username = string.Empty,
                Password = string.Empty
            };
            Session          = new QQSession();
            Store            = new QQStore();
            NotifyListener   = notifyListener;
            _actorDispatcher = actorDispatcher ?? new SimpleActorDispatcher();
            Logger           = logger ?? new EmptyQQLogger();
            Logger.Context   = this;
            Init();
        }
예제 #3
0
        /// <summary>
        /// 构造方法,初始化模块和服务
        /// </summary>
        /// <param name="username">账号</param>
        /// <param name="password">密码</param>
        /// <param name="notifyListener">监听器</param>
        /// <param name="actorDispatcher">线程执行器</param>
        public WebQQClient(string username, string password,
                           QQNotifyHandler notifyListener, IQQActorDispatcher actorDispatcher)
        {
            _modules  = new Dictionary <QQModuleType, IQQModule>();
            _services = new Dictionary <QQServiceType, IQQService>();

            _modules.Add(QQModuleType.LOGIN, new LoginModule());
            _modules.Add(QQModuleType.PROC, new ProcModule());
            _modules.Add(QQModuleType.USER, new UserModule());
            _modules.Add(QQModuleType.BUDDY, new BuddyModule());
            _modules.Add(QQModuleType.CATEGORY, new CategoryModule());
            _modules.Add(QQModuleType.GROUP, new GroupModule());
            _modules.Add(QQModuleType.CHAT, new ChatModule());
            _modules.Add(QQModuleType.DISCUZ, new DiscuzModule());
            _modules.Add(QQModuleType.EMAIL, new EmailModule());
            _services.Add(QQServiceType.HTTP, new HttpService());

            Account = new QQAccount
            {
                Username = username,
                Password = password
            };
            Session          = new QQSession();
            Store            = new QQStore();
            NotifyListener   = notifyListener;
            _actorDispatcher = actorDispatcher;

            Init();
        }
예제 #4
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            //{"retcode":0,"result":{"dnamelist":[{"did":3536443553,"name":"\u8FD9\u662F\u6807\u9898"},
            //{"did":625885728,"name":""}],"dmasklist":[{"did":1000,"mask":0}]}}

            JObject json  = JObject.Parse(response.GetResponseString());
            QQStore store = Context.Store;

            if (json["retcode"].ToString() == "0")
            {
                JObject result  = json["result"].ToObject <JObject>();
                JArray  dizlist = result["dnamelist"].ToObject <JArray>();
                for (int i = 0; i < dizlist.Count; i++)
                {
                    QQDiscuz discuz  = new QQDiscuz();
                    JObject  dizjson = dizlist[i].ToObject <JObject>();
                    discuz.Did  = dizjson["did"].ToObject <long>();
                    discuz.Name = dizjson["name"].ToString();
                    store.AddDiscuz(discuz);
                }
                NotifyActionEvent(QQActionEventType.EVT_OK, store.GetDiscuzList());
            }
            else
            {
                NotifyActionEvent(QQActionEventType.EVT_ERROR, new QQException(QQErrorCode.UNEXPECTED_RESPONSE));
            }
        }
예제 #5
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            JObject       json    = JObject.Parse(response.GetResponseString());
            List <object> recents = new List <object>();
            QQStore       store   = Context.Store;

            if (json["retcode"].ToString() == "0")
            {
                JArray result = json["result"].ToObject <JArray>();
                for (int i = 0; i < result.Count; i++)
                {
                    JObject rejson = result[i].ToObject <JObject>();
                    switch (rejson["type"].ToObject <int>())
                    {
                    case 0:
                    {           //好友
                        QQBuddy buddy = store.GetBuddyByUin(rejson["uin"].ToObject <long>());
                        if (buddy != null)
                        {
                            recents.Add(buddy);
                        }
                        break;
                    }

                    case 1:
                    {           //群
                        QQGroup group = store.GetGroupByCode(rejson["uin"].ToObject <long>());
                        if (group != null)
                        {
                            recents.Add(group);
                        }
                        break;
                    }

                    case 2:
                    {           //讨论组
                        QQDiscuz discuz = store.GetDiscuzByDid(rejson["uin"].ToObject <long>());
                        if (discuz != null)
                        {
                            recents.Add(discuz);
                        }
                        break;
                    }
                    }
                }
                NotifyActionEvent(QQActionEventType.EVT_OK, recents);
            }
            else
            {
                NotifyActionEvent(QQActionEventType.EVT_ERROR, new QQException(QQErrorCode.UNEXPECTED_RESPONSE));
            }
        }
예제 #6
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);
            }

        }
예제 #7
0
        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());
        }
예제 #8
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            JObject json  = JObject.Parse(response.GetResponseString());
            QQStore store = Context.Store;

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

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

                //result/mem_list
                JArray memlist = result["mem_info"].ToObject <JArray>();
                foreach (JToken t in memlist)
                {
                    JObject        memjson = t.ToObject <JObject>();
                    QQDiscuzMember 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
                JArray statlist = result["mem_status"].ToObject <JArray>();
                foreach (JToken t in statlist)
                {
                    // 下面重新设置最新状态
                    JObject statjson = t.ToObject <JObject>();
                    QQUser  member   = discuz.GetMemberByUin(statjson["uin"].ToObject <long>());
                    if (statjson["client_type"] != null && member != null)
                    {
                        member.ClientType = QQClientType.ValueOfRaw(statjson["client_type"].ToObject <int>());
                        member.Status     = QQStatus.ValueOfRaw(statjson["status"].ToString());
                    }
                }

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

                NotifyActionEvent(QQActionEventType.EVT_OK, store.GetDiscuzList());
            }
            else
            {
                NotifyActionEvent(QQActionEventType.EVT_ERROR, new QQException(QQErrorCode.UNEXPECTED_RESPONSE));
            }
        }
예제 #9
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            JObject json = JObject.Parse(response.GetResponseString());
            string  str  = JsonConvert.SerializeObject(json);


            int retcode = json["retcode"].ToObject <int>();

            if (retcode == 0)
            {
                QQStore store = Context.Store;
                // 处理好友列表
                JObject results = json["result"].ToObject <JObject>();
                // 获取JSON列表信息
                JArray jsonCategories = results["categories"].ToObject <JArray>();
                // 获取JSON好友基本信息列表 flag/uin/categories
                JArray jsonFriends = results["friends"].ToObject <JArray>();
                // face/flag/nick/uin
                JArray jsonInfo = results["info"].ToObject <JArray>();
                // uin/markname/
                JArray jsonMarknames = results["marknames"].ToObject <JArray>();
                // vip_level/u/is_vip
                JArray jsonVipinfo = results["vipinfo"].ToObject <JArray>();

                // 默认好友列表
                QQCategory c = new QQCategory()
                {
                    Index = 0, Name = "我的好友", Sort = 0
                };
                store.AddCategory(c);
                // 初始化好友列表
                foreach (JToken t in jsonCategories)
                {
                    JObject    jsonCategory = t.ToObject <JObject>();
                    QQCategory qqc          = new QQCategory();
                    qqc.Index = jsonCategory["index"].ToObject <int>();
                    qqc.Name  = jsonCategory["name"].ToString();
                    qqc.Sort  = jsonCategory["sort"].ToObject <int>();
                    store.AddCategory(qqc);
                }
                // 处理好友基本信息列表 flag/uin/categories
                foreach (JToken t in jsonFriends)
                {
                    QQBuddy buddy      = new QQBuddy();
                    JObject jsonFriend = t.ToObject <JObject>();
                    long    uin        = jsonFriend["uin"].ToObject <long>();
                    buddy.Uin        = uin;
                    buddy.Status     = QQStatus.OFFLINE;
                    buddy.ClientType = QQClientType.Unknown;
                    // 添加到列表中
                    int        category   = jsonFriend["categories"].ToObject <int>();
                    QQCategory qqCategory = store.GetCategoryByIndex(category);
                    buddy.Category = qqCategory;
                    qqCategory.BuddyList.Add(buddy);

                    // 记录引用
                    store.AddBuddy(buddy);
                }
                // face/flag/nick/uin
                foreach (JToken t in jsonInfo)
                {
                    JObject info  = t.ToObject <JObject>();
                    long    uin   = info["uin"].ToObject <long>();
                    QQBuddy buddy = store.GetBuddyByUin(uin);
                    buddy.Nickname = info["nick"].ToString();
                }
                // uin/markname
                foreach (JToken t in jsonMarknames)
                {
                    JObject jsonMarkname = t.ToObject <JObject>();
                    long    uin          = jsonMarkname["uin"].ToObject <long>();
                    QQBuddy buddy        = store.GetBuddyByUin(uin);
                    if (buddy != null)
                    {
                        buddy.MarkName = jsonMarkname["markname"].ToString();
                    }
                }
                // vip_level/u/is_vip
                foreach (JToken t in jsonVipinfo)
                {
                    JObject vipInfo = t.ToObject <JObject>();
                    long    uin     = vipInfo["u"].ToObject <long>();
                    QQBuddy buddy   = store.GetBuddyByUin(uin);
                    buddy.VipLevel = vipInfo["vip_level"].ToObject <int>();
                    int isVip = vipInfo["is_vip"].ToObject <int>();
                    if (isVip != 0)
                    {
                        buddy.IsVip = true;
                    }
                    else
                    {
                        buddy.IsVip = false;
                    }
                }

                NotifyActionEvent(QQActionEventType.EVT_OK, store.GetCategoryList());
            }
            else
            {
                // LOG.warn("unknown retcode: " + retcode);
                NotifyActionEvent(QQActionEventType.EVT_ERROR, new QQException(QQErrorCode.ERROR_HTTP_STATUS, "unknown retcode: " + retcode));
            }
        }