private void Form1_Load(object sender, EventArgs e) { // 获取二维码 qq = new WebQQClient("", "", Listener, new SimpleActorDispatcher(), new QQConsoleLogger()); qq.LoginWithQRCode(); // 登录之后自动开始轮训 new Thread(() => { while (qrCodeImage == null) { } setQrCode(qrCodeImage); while (!LoginSuccess) { } OpenMainForm(); }) { IsBackground = true }.Start(); }
static void Main(string[] args) { #if NETCORE Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); #endif // 测试每一种控制台颜色 //foreach (var @enum in EnumExtension.GetValues<ConsoleColor>()) //{ // Console.ForegroundColor = @enum; // Console.WriteLine("颜色和编码测试"); //} // 获取二维码 var qq = new WebQQClient("", "", Listener, new SimpleActorDispatcher(), new QQConsoleLogger()); qq.LoginWithQRCode(); // 登录之后自动开始轮训 //var qq = new WebQQClient(); //var timeSpan = TestAction(() => //{ // var @event = qq.LoginWithQRCode().WaitFinalEvent(); // if (@event.Type != QQActionEventType.EvtOK) // { // Console.WriteLine("xxxxxxxxxxxxxx"); // } //}, 100); //Console.WriteLine(timeSpan.TotalMilliseconds); Console.Read(); }
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(); }
private async void Login() { _cts = new CancellationTokenSource(); btnLogin.InvokeIfRequired(() => btnLogin.Text = "取消登录"); while (!_cts.IsCancellationRequested) { var client = new WebQQClient(notifyListener: _notifyListener, logger: new RichTextBoxLogger(tbMessage)); var result = await client.LoginWithQRCode().WhenFinalEvent(_cts.Token).ConfigureAwait(false); if (result.Type == QQActionEventType.EvtOK) { var key = client.Account.QQ.ToString(); if (_qqClients.ContainsKey(key)) { client.Destroy(); } else { _qqClients.Add(key, client); lvQQList.InvokeIfRequired(() => { AddQQToLv(client); }); } } } _cts = null; }
private static async Task TestQQ() { var client = new WebQQClient(m => new QQConsoleLogger(m, LogLevel.Debug), _qqListener); if ((await client.Login()).IsOk()) { client.BeginPoll(); } }
public static void Main(string[] args) { #if NETCORE Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); #endif // 获取二维码 var qq = new WebQQClient(Listener); qq.Login().Wait(); Console.Read(); }
public static void Main(string[] args) { #if NETCORE Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); #endif var client = new WebQQClient(m => new QQConsoleLogger(m, LogLevel.Debug), Listener); client.Login().Wait(); client.BeginPoll(); Console.Read(); }
private void AddQQToList(string qqNum, string qqPassword, string type = "webqq") { IQQClient iqqClient = null; switch (type.ToLower()) { case "webqq": iqqClient = new WebQQClient(qqNum, qqPassword, _notifyHandler, _threadActorDispatcher); break; default: iqqClient = new WebQQClient(qqNum, qqPassword, _notifyHandler, _threadActorDispatcher); break; } _qqClients.Add(qqNum, iqqClient, AddChoice.Update); AddQQInfo(iqqClient); }
public static void Main2(string[] args) { var threadActorDispatcher = new SimpleActorDispatcher(); IQQClient client = null; start: Console.Write("请输入QQ号:"); var username = Console.ReadLine(); Console.Write("请输入QQ密码:"); var password = Console.ReadLine(); client = new WebQQClient(username, password, Listener, threadActorDispatcher); //测试同步模式登录 var future = client.Login(QQStatus.ONLINE, null); client.Logger.LogInformation(client.Account.Username + "-登录中......"); var Event = future.WaitFinalEvent(); if (Event.Type == QQActionEventType.EvtOK) { client.Logger.LogInformation(client.Account.Username + "-登录成功!!!!"); var getUserInfoEvent = client.GetUserInfo(client.Account, null).WaitFinalEvent(); if (getUserInfoEvent.Type == QQActionEventType.EvtOK) { client.Logger.LogInformation(client.Account.QQ + "-用户信息:" + getUserInfoEvent.Target); client.GetBuddyList(null).WaitFinalEvent(); client.Logger.LogInformation(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; client.Logger.LogInformation($"{buddy.QQ}, {name}"); } } //所有的逻辑完了后,启动消息轮询 client.BeginPollMsg(); } else if (Event.Type == QQActionEventType.EvtError) { var ex = (QQException)Event.Target; client.Logger.LogInformation(ex.Message); client.Destroy(); goto start; } else { client.Logger.LogInformation(client.Account.Username + "-登录失败"); client.Destroy(); goto start; } client.Logger.LogInformation("按任意键退出"); Console.ReadLine(); }
private async void Login() { _cts = new CancellationTokenSource(); btnLogin.InvokeIfRequired(() => btnLogin.Text = "取消登录"); while (!_cts.IsCancellationRequested) { var client = new WebQQClient(notifyListener: _notifyListener, logger: new RichTextBoxLogger(tbMessage)); var result = await client.LoginWithQRCode().WhenFinalEvent(_cts.Token).ConfigureAwait(false); if (result.Type == QQActionEventType.EvtOK) { var key = client.Account.QQ.ToString(); if (_qqClients.ContainsKey(key)) client.Destroy(); else { _qqClients.Add(key, client); lvQQList.InvokeIfRequired(() => { AddQQToLv(client); }); } } } _cts = null; }