Exemplo n.º 1
0
        private void TimeRun(BackgroundWorker worker)
        {
            if (worker.CancellationPending)
            {
                return;
            }
            var robot = Global.robot;

            if (robot == null)
            {
                worker.ReportProgress(1, "noRobot");
            }
            if (robot.State == 0)
            {
                worker.ReportProgress(2, "processing");
                string loginUrl = protocol.CheckLogin(robot.UUID);
                worker.ReportProgress(3, "processed");
                if (loginUrl == "408")
                {
                    //超时需要重新生成二维码
                }
                else if (loginUrl == "200")
                {
                    //已扫描待确认
                }
                else
                {
                    CookieResult cookieResult = protocol.GetCookie(loginUrl);
                    robot.CookieStr  = cookieResult.CookieStr;
                    robot.Cookie     = cookieResult.wechatCookie;
                    robot.SyncCookie = cookieResult.SyncCookie;

                    InitSyncResult initSyncResult = protocol.Init(robot.Cookie, robot.CookieStr);
                    robot.Uin = initSyncResult.Uin;

                    RobotService service = new RobotService();
                    int          robotId = service.IsRobot(robot.Uin);
                    if (robotId > 0)
                    {
                        robot.Id         = robotId;
                        robot.SyncKey    = initSyncResult.SyncKey;
                        robot.SynckeyStr = initSyncResult.SynckeyStr;
                        robot.UserName   = initSyncResult.UserName;
                        robot.NickName   = initSyncResult.Nickname;
                        protocol.StatusNotify(robot.Cookie, robot.CookieStr, robot.UserName);
                        robot.State   = 1;
                        robot.Contact = protocol.GetContact(robot.Cookie, robot.CookieStr).MemberList.ToList();
                        Global.robot  = robot;
                    }
                    else
                    {
                        loginUrl = "noRobot";
                    }
                }
                worker.ReportProgress(1, loginUrl);
            }
            else
            {
                worker.ReportProgress(1, "1");
            }
        }