示例#1
0
        public static void Main(string[] args)
        {
            var threadActorDispatcher = new ThreadActorDispatcher();
            IQQClient client = null;

start:
            Console.Write("请输入QQ号:");
            var username = Console.ReadLine();
            Console.Write("请输入QQ密码:");
            var password = Console.ReadLine();
            client = new WebQQClient(username, password, handler, threadActorDispatcher);


            //测试同步模式登录
            var future = client.Login(QQStatus.ONLINE, null);
            Console.WriteLine(client.Account.Username + "-登录中......");

            var Event = future.WaitFinalEvent();
            if (Event.Type == QQActionEventType.EVT_OK)
            {
                Console.WriteLine(client.Account.Username + "-登录成功!!!!");

                var getUserInfoEvent = client.GetUserInfo(client.Account, null).WaitFinalEvent();

                if (getUserInfoEvent.Type == QQActionEventType.EVT_OK)
                {
                    Console.WriteLine(client.Account.QQ + "-用户信息:" + getUserInfoEvent.Target);


                    client.GetBuddyList(null).WaitFinalEvent();
                    Console.WriteLine(client.Account.QQ + "-Buddy count: " + client.GetBuddyList().Count);

                    foreach (var buddy in client.GetBuddyList())
                    {
                        var f = client.GetUserQQ(buddy, null);
                        var e = f.WaitFinalEvent();
                        var name = string.IsNullOrEmpty(buddy.MarkName) ? buddy.Nickname : buddy.MarkName;
                        Console.WriteLine("{0}, {1}", buddy.QQ, name);
                    }
                }
                //所有的逻辑完了后,启动消息轮询
                client.BeginPollMsg();
            }
            else if (Event.Type == QQActionEventType.EVT_ERROR)
            {
                var ex = (QQException)Event.Target;
                Console.WriteLine(ex.Message);
                client.Destroy();
                goto start;
            }
            else
            {
                Console.WriteLine(client.Account.Username + "-登录失败");
                client.Destroy();
                goto start;
            }

            Console.WriteLine("按任意键退出");
            Console.ReadLine();
        }
示例#2
0
文件: Test.cs 项目: weikety/iQQ.Net
        public static void Main(string[] args)
        {
            var threadActorDispatcher = new ThreadActorDispatcher();
            var qqList = new List<WebQQClient>()
            {
                // 19FDCB35E0946A62E84C8C9B9B34DFF1
                new WebQQClient("2027044668", "19FDCB35E0946A62E84C8C9B9B34DFF1", handler, threadActorDispatcher),
            };

            for (var i = 0; i < qqList.Count; ++i)
            {
                var client = qqList[i];

                //测试同步模式登录
                var future = client.Login(QQStatus.ONLINE, null);
                Console.WriteLine(client.Account.Username + "-登录中......");

                var Event = future.WaitFinalEvent();
                if (Event.Type == QQActionEventType.EVT_OK)
                {
                    Console.WriteLine(client.Account.Username + "-登录成功!!!!");

                    var getUserInfoEvent = client.GetUserInfo(client.Account, null).WaitFinalEvent();

                    if (getUserInfoEvent.Type == QQActionEventType.EVT_OK)
                    {
                        Console.WriteLine(client.Account.QQ + "-用户信息:" + getUserInfoEvent.Target);


                        client.GetBuddyList(null).WaitFinalEvent();
                        Console.WriteLine(client.Account.QQ + "-Buddy count: " + client.GetBuddyList().Count);

                        foreach (var buddy in client.GetBuddyList())
                        {
                            var f = client.GetUserQQ(buddy, null);
                            var e = f.WaitFinalEvent();
                            var name = string.IsNullOrEmpty(buddy.MarkName) ? buddy.Nickname : buddy.MarkName;
                            Console.WriteLine("{0}, {1}", buddy.QQ, name);
                        }
                    }

                    //所有的逻辑完了后,启动消息轮询
                    client.BeginPollMsg();
                }
                else if (Event.Type == QQActionEventType.EVT_ERROR)
                {
                    var ex = (QQException)Event.Target;
                    Console.WriteLine(ex.Message);
                }
                else
                {
                    Console.WriteLine(client.Account.Username + "-登录失败");
                }
            }
            Console.ReadLine();
        }