コード例 #1
0
        /// <summary>
        /// 登录状态
        /// </summary>
        public static bool login(string url, string username, string userpass, CookieContainer webCookie, int tryMax)
        {
            bool isSuccess = false;
            int  tryCount  = 0;

            try
            {
                while (true)
                {
                    #region 获取验证码

                    //图像验证码
                    string validateCode = "";
                    string urlVali      = url + "/user/ValidateImage.aspx?time=0." + DateTime.Now.Ticks;
                    Bitmap bitmap;

                    validateCode = ServerCommon.GetValidateCode(urlVali, webCookie, out bitmap);

                    #endregion 获取验证码

                    #region 登录

                    if (validateCode.Length == 4)
                    {
                        //登录获取Cookie
                        string resultLogin = HttpHelps.Post("loginName=" + username + "&loginPwd=" + userpass + "&ValidateCode=" + validateCode,
                                                            url + "/user/login_validate.aspx", webCookie, Encoding.Default);

                        if (resultLogin.IndexOf("系統已經自動把你列入黑名單") > -1)
                        {
                            //密碼輸入多次不正確,系統已經自動把你列入黑名單!!!
                            isSuccess = false;
                            break;
                        }
                        else if (resultLogin.IndexOf("驗證碼輸入不正確") == -1 && resultLogin.IndexOf("帳號或密碼不正確") == -1)
                        {
                            //
                            if (checkLogin(url, webCookie))
                            {
                                //登录成功
                                isSuccess = true;
                                function.log("顺丰登录成功");
                                break;
                            }
                        }
                        else
                        {
                            tryCount++;
                        }

                        function.log("顺丰登录失败,重新尝试");
                        Thread.Sleep(500);
                    }

                    #endregion 登录


                    if (tryCount > tryMax)
                    {
                        function.log("尝试登录次数过多");
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                function.log("尝试登录错误" + ex.Message);
            }

            return(isSuccess);
        }
コード例 #2
0
        /// <summary>
        /// 登录状态
        /// </summary>
        public static bool login(string url, string username, string userpass, CookieContainer webCookie, out string postUrl)
        {
            if (username.Length == 0 || userpass.Length == 0)
            {
                postUrl = "";
                return(false);
            }


            bool   loginSuccess = false;
            string formPost     = "";

            postUrl = "";
            string hidden_verificationToken  = "";
            string hidden_VIEWSTATE          = "";
            string hidden_VIEWSTATEGENERATOR = "";

            //登录获取Cookie

            //

            for (int i = 0; i < 3; i++)
            {
                string frameUrl = "";
                for (int j = 0; j < 2; j++)
                {
                    string resultMain = HttpHelps.Get(url, webCookie, Encoding.Default, 3000);

                    //string resultMain = HttpHelps.Post("", url, webCookie, Encoding.Default);

                    frameUrl = function.middlestring(resultMain, "<iframe src=\"", "\" width=\"100%\"");
                    if (!string.IsNullOrWhiteSpace(frameUrl))
                    {
                        function.log("实际地址" + frameUrl);
                        break;
                    }
                }
                if (frameUrl.Length > 0)
                {
                    Uri    frameUri    = new Uri(frameUrl);
                    string resultFrame = HttpHelps.Get(frameUrl, webCookie, Encoding.UTF8);

                    formPost = function.middlestring(resultFrame, "<form name=\"form1\" method=\"post\" action=\"./?", "\" id=");
                    if (formPost.Length == 0)
                    {
                        formPost = function.middlestring(resultFrame, "<form name=\"form1\" method=\"post\" action=\"?", "\" id=");
                    }
                    hidden_verificationToken  = function.middlestring(resultFrame, "__RequestVerificationToken\" type=\"hidden\" value=\"", "\" />");
                    hidden_VIEWSTATE          = function.middlestring(resultFrame, "__VIEWSTATE\" value=\"", "\" />");
                    hidden_VIEWSTATEGENERATOR = function.middlestring(resultFrame, "__VIEWSTATEGENERATOR\" value=\"", "\" />");
                    postUrl = "http://" + frameUri.Host;
                    if (hidden_verificationToken.Length > 0)
                    {
                        if (hidden_VIEWSTATEGENERATOR.Length > 0)
                        {
                        }
                        break;
                    }

                    string jsCookie = HttpHelps.Post("", postUrl + "/cp2-dfgj-mb/bk.aspx/GetCookie", webCookie, Encoding.Default);
                }
                Thread.Sleep(100);
            }


            int tryCount = 0;

            while (true)
            {
                if (string.IsNullOrWhiteSpace(postUrl))
                {
                    loginSuccess = false;
                    break;
                }

                #region 获取验证码

                //图像验证码
                string validateCode = "";
                Bitmap bitmap;
                validateCode = ServerCommon.GetValidateCode(postUrl + "/cp2-dfgj-mb/checknum.aspx?ts=" + DateTime.Now.Ticks,
                                                            webCookie, out bitmap);



                #endregion 获取验证码

                #region 登录

                if (validateCode.Length == 4)
                {
                    string resultCredits = HttpHelps.Post("txt_U_name=" + username + "&txt_U_Password="******"&txt_validate=" + validateCode
                                                          + "&__VIEWSTATE=" + hidden_VIEWSTATE + "&__VIEWSTATEGENERATOR=" + hidden_VIEWSTATEGENERATOR + "&__RequestVerificationToken=" + hidden_verificationToken,
                                                          postUrl + "/cp2-dfgj-mb/" + "?" + formPost, webCookie, Encoding.UTF8);

                    string resultLeft = HttpHelps.Post("", postUrl + "/cp2-dfgj-mb/ch/left.aspx", webCookie, Encoding.UTF8);

                    if (resultLeft.Length > 2000)
                    {
                        loginSuccess = true;
                        function.log("永利登录成功");
                        break;
                    }
                    else
                    {
                        tryCount++;
                        loginSuccess = false;
                    }

                    function.log("永利登录失败,重新尝试");
                    Thread.Sleep(500);
                }

                #endregion 登录

                if (tryCount > 10)
                {
                    function.log("尝试登录次数过多");
                    break;
                }
            }

            return(loginSuccess);
        }