Exemple #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            QQGlobal.loginForm = this;
            // 获取二维码
            QQGlobal.client = new WebQQClient((client, notifyEvent) =>
            {
                switch (notifyEvent.Type)
                {
                case QQNotifyEventType.LoginSuccess:
                    {
                        isLoginSuccess = true;
                        loginSuccessHandler?.Invoke();
                        OpenMainForm();
                        break;
                    }

                case QQNotifyEventType.ReloginSuccess:
                    {
                        isLoginSuccess = true;
                        break;
                    }

                case QQNotifyEventType.GroupMsg:
                    {
                        var revMsg = (QQMsg)notifyEvent.Target;
                        //判断当前群是否已开启监控
                        bool isListen = QQGlobal.listenGroups.Exists((g) => { return(g.Gid == revMsg.Group.Gid); });
                        if (isListen)
                        {
                            string msg         = revMsg.GetText();
                            List <string> urls = new List <string>();
                            urls = UrlUtils.GetUrls(msg);
                            GroupMsgHandler?.Invoke(revMsg.Id, revMsg.Group.Name, msg, urls);
                        }
                        break;
                    }

                case QQNotifyEventType.QrcodeReady:
                    {
                        var verify = (Image)notifyEvent.Target;
                        setQrCode(verify);
                        SetMsg("请使用QQ手机版扫描二维码");
                        break;
                    }

                case QQNotifyEventType.QrcodeAuth:
                    {
                        SetMsg("扫描成功,请在手机上确认是否授权登录");
                        break;
                    }

                case QQNotifyEventType.QrcodeSuccess:
                    {
                        SetMsg("二维码验证成功!正在跳转...");
                        break;
                    }

                case QQNotifyEventType.LoadGroupSuccess:
                    {
                        GroupLoadSuccessHandler?.Invoke();
                        QQGlobal.QQGroupLoadSuccess = true;
                        break;
                    }

                case QQNotifyEventType.QrcodeInvalid:
                    {
                        QrCodeInvalid = true;
                        setQrCode(Properties.Resources.QQBG);
                        break;
                    }

                case QQNotifyEventType.KickOffline:
                    {
                        isLoginSuccess = false;
                        //重新登录
                        client.Relogin(QQStatus.ONLINE, (s, c) =>
                        {
                            if (c.Type == QQActionEventType.EvtOK)
                            {
                                isLoginSuccess = true;
                            }
                        });
                        break;
                    }

                default:
                    {
                        break;
                    }
                }
            });
            QQGlobal.client.LoginWithQRCode(); // 登录之后自动开始轮训

            System.Windows.Forms.Timer pollTime = new System.Windows.Forms.Timer();
            pollTime.Interval = 10000;
            pollTime.Tick    += PollTime_Tick;
            pollTime.Start();
        }
Exemple #2
0
        private void InitQQClient()
        {
            QQGlobal.client = new WebQQClient((client, notifyEvent) =>
            {
                switch (notifyEvent.Type)
                {
                case QQNotifyEventType.LoginSuccess:
                    {
                        isLoginSuccess = true;
                        loginSuccessHandler?.Invoke();
                        OpenMainForm();
                        break;
                    }

                case QQNotifyEventType.ReloginSuccess:
                    {
                        isLoginSuccess = true;
                        break;
                    }

                case QQNotifyEventType.GroupMsg:
                    {
                        var revMsg = (QQMsg)notifyEvent.Target;
                        //判断当前群是否已开启监控
                        bool isListen = QQGlobal.listenGroups.Exists((g) => { return(g.Gid == revMsg.Group.Gid); });
                        if (isListen)
                        {
                            string msg         = revMsg.GetTextReplace();
                            List <string> urls = new List <string>();
                            urls = revMsg.GetUrls();

                            long gid = revMsg.Group.Gid;
                            GroupMsgHandler?.Invoke(revMsg.Id, gid, revMsg.Group.Name, msg, revMsg.GetText(), urls);
                        }
                        break;
                    }

                case QQNotifyEventType.QrcodeReady:
                    {
                        var verify = (Image)notifyEvent.Target;
                        setQrCode(verify);
                        SetMsg("请使用QQ手机版扫描二维码");
                        break;
                    }

                case QQNotifyEventType.QrcodeAuth:
                    {
                        SetMsg("扫描成功,请在手机上确认是否授权登录");
                        break;
                    }

                case QQNotifyEventType.QrcodeSuccess:
                    {
                        SetMsg("二维码验证成功!正在跳转...");
                        break;
                    }

                case QQNotifyEventType.LoadGroupSuccess:
                    {
                        QQGlobal.QQGroupLoadSuccess = true;
                        GroupLoadSuccessHandler?.Invoke();
                        break;
                    }

                case QQNotifyEventType.QrcodeInvalid:
                    {
                        QrCodeInvalid = true;
                        setQrCode(Properties.Resources.QQBG);
                        break;
                    }

                case QQNotifyEventType.KickOffline:
                    {
                        isLoginSuccess = false;
                        //重新登录
                        client.Relogin(QQStatus.ONLINE, (s, c) =>
                        {
                            if (c.Type == QQActionEventType.EvtOK)
                            {
                                isLoginSuccess = true;
                            }
                        });
                        break;
                    }

                default:
                    {
                        isLoginSuccess = false;
                        if (!client.IsOnline())
                        {
                            client.ChangeStatus(QQStatus.ONLINE);
                            //重新登录
                            client.Relogin(QQStatus.ONLINE, (s, c) =>
                            {
                                if (c.Type == QQActionEventType.EvtOK)
                                {
                                    isLoginSuccess = true;
                                }
                            });
                        }
                        break;
                    }
                }
            });
            QQGlobal.client.LoginWithQRCode();// 登录之后自动开始轮训
        }