예제 #1
0
        private void btn_jwlogin_Click(object sender, EventArgs e)
        {
            EasLogin jwxt = new EasLogin(Convert.ToString(BotQQ.Id), tb_QQ.Text, tb_StuID.Text, tb_jwPw.Text, 3);

            try
            {
                if (jwxt.TryLogin() == true)
                {
                    EasGetScore jwscore = new EasGetScore();
                    jwscore.GetScore(jwxt);
                    EasGetCourse jwcourse = new EasGetCourse();
                    jwcourse.GetCourse(jwxt);
                    MessageBox.Show(jwxt.StuName + " " + jwxt.College, "登录成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    bindingSource_StudentDB.DataSource = EasOP.GetAll(Convert.ToString(BotQQ.Id));
                    dataGridView_StuList.DataSource    = bindingSource_StudentDB;

                    //课程表 数据绑定
                    stuDataGridView.DataSource = bindingSource_StudentDB;

                    tab2Init();
                    tab3Init();
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "密码错误")
                {
                    MessageBox.Show("用户名或密码错误。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (ex.Message == "验证码错误")
                {
                    MessageBox.Show("验证码错误次数达到上限,可稍后尝试重新登录再试。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    throw ex;
                }
            }
        }
예제 #2
0
        public override int HandleImpl()
        {
            string msg      = message.Replace(" ", ""); //去除空格
            var    StuID    = textOp.GetMiddleText(msg, "绑定教务系统", "|");
            var    Password = textOp.GetRightText(msg, "|");

            if (StuID == "" || Password == "")
            {
                CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "命令格式错误,请检查输入信息。\n命令格式:绑定教务系统 学号|密码");
                return(1);
            }
            EasLogin jwxt         = new EasLogin(botQQ, fromQQ, StuID, Password, 3);
            string   AppDirectory = CQ.Api.AppDirectory;

            for (int i = 0; i <= jwxt.TryNum; i++)
            {
                try
                {
                    if (EasOP.StuExist(StuID) == false)
                    {
                        jwxt.LoginSys();
                        CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "【登录成功】\n", jwxt.College, " ", jwxt.StuName);
                        ini.Write(AppDirectory + @"\配置.ini", fromQQ, "学号", StuID);
                        ini.Write(AppDirectory + @"\配置.ini", fromQQ, "密码", DESTool.Encrypt(Password, "jw*1"));

                        EasGetCourse jwcourse = new EasGetCourse();
                        jwcourse.GetCourse(jwxt);
                        EasGetScore jwScore = new EasGetScore();
                        jwScore.GetScore(jwxt);

                        break;
                    }
                    else
                    {
                        CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "【绑定失败】\n当前学号已被QQ:", EasOP.GetStuQQ(StuID), "绑定,不能再次绑定。");
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message == "密码错误")
                    {
                        CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "【用户名或密码错误】\n请确认无误后重新发送命令再试。");
                    }
                    else if (ex.Message == "验证码错误")
                    {
                        if (i == jwxt.TryNum)
                        {
                            CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "验证码错误已达最大尝试上限,如需继续登录可重新发送命令再试。");
                        }
                        else
                        {
                            CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "【验证码错误】\n正在重试。");
                            System.Threading.Thread.Sleep(1000);    //休眠1s后重试请求
                            continue;
                        }
                    }
                    else
                    {
                        CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "发生未知错误,请联系机器人主人。");
                        CQ.Log.Error("发生未知错误", ex.ToString());
                        break;
                    }
                }
            }

            return(0);
        }