Exemple #1
0
        private string GetLoginSig()
        {
            String     forCheckUrl = "https://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http://game.qq.com/comm-htdocs/milo/proxy.html&appid=21000111&f_url=loginerroralert&target=self&qtarget=self&s_url=http%3A//xinyue.qq.com/comm-htdocs/login/logincallback.htm&no_verifyimg=1&daid=8&qlogin_jumpname=jump&qlogin_param=u1%3Dhttp%3A//xinyue.qq.com/comm-htdocs/login/logincallback.htm";
            HttpHelper helper      = new HttpHelper();

            outcomeFromCheck = helper.GetHtml(new HttpItem {
                URL = forCheckUrl
            });
            MessageBox.Show(outcomeFromCheck.Cookie);
            return(HttpCookieHelper.GetCookieValue("pt_login_sig", outcomeFromCheck.Cookie));
        }
Exemple #2
0
        private void GetCheck()
        {
            //获取验证信息
            //验证信息格式为:ptui_checkVC('0','!MIW','\x00\x00\x00\x00\x9a\x65\x0f\xd7')
            //其中分为三部分,第一个值0或1判断是否需要图片验证码
            //                          第二个值是默认验证码,若不需要图片验证码,就用此验证码来提交
            //                          第三部分是所使用的QQ号码的16进制形式
            pt_login_sig = GetLoginSig();

            //https://ssl.ptlogin2.qq.com/check?regmaster=&pt_tea=2&pt_vcode=1&uin=66456804&appid=21000111&js_ver=10232&js_type=1&login_sig=-PB6vLz9Tbc*6XY0haBM1qyXFU-3dn70pj0uX6-wNeLO8oz4k2u9tKuaC2PO-fJv&u1=http%3A%2F%2Fxinyue.qq.com%2Fcomm-htdocs%2Flogin%2Flogincallback.htm&r=0.00668773893967356&pt_uistyle=40&pt_jstoken=3611214356
            String          forCheckUrl = "https://ssl.ptlogin2.qq.com/check?regmaster=&pt_tea=2&pt_vcode=1&uin=" + QQ + "&appid=21000111&js_ver=10232&js_type=1&login_sig=" + pt_login_sig + "&u1=http%3A%2F%2Fxinyue.qq.com%2Fcomm-htdocs%2Flogin%2Flogincallback.htm&r=0.00668773893967356&pt_uistyle=40&pt_jstoken=3611214356";
            CookieContainer cookieNull  = new CookieContainer();
            HttpHelper      helper      = new HttpHelper()
            {
            };


            HttpItem h = new HttpItem()
            {
                URL = forCheckUrl, ResultType = ResultType.String
            };
            String receiveFromCheck = "";

            HttpResult result = helper.GetHtml(h);

            receiveFromCheck = result.Html;

            ptv = HttpCookieHelper.GetCookieValue("ptvfsession", result.Cookie);

            //将验证码信息的三部分存入数组
            int    checkCodePosition = receiveFromCheck.IndexOf("(") + 1;
            String checkCode         = receiveFromCheck.Substring(checkCodePosition, receiveFromCheck.LastIndexOf(")") - checkCodePosition);

            String[] checkNum = checkCode.Replace("'", "").Split(',');  //验证码数组


            if ("1".Equals(checkNum[0])) //判断是否需要图片验证码
            {
                hasimage = 1;
                String forImageUrl   = "http://captcha.qq.com/getimage?aid=21000111&uin=" + QQ + "&cap_cd=" + checkNum[1];
                Stream receiveStream = new MemoryStream(helper.GetHtml(new HttpItem {
                    URL = forImageUrl, ResultType = ResultType.Byte
                }).ResultByte);
                //将获取的图片验证码存入电脑
                //System.Drawing.Image.FromStream(receiveStream).Save(@"d:/code.jpg");
                Image img = Image.FromStream(receiveStream);
                pictureBox1.Image = img; //将读取到的图片验证码输出到picture_box面板上
            }
            else //若不需图片验证码,验证码就等于checkNum[1]
            {
                hasimage          = 0;
                Vericode_box.Text = checkNum[1];
            }
        }
Exemple #3
0
        /// <summary>
        /// 获取皮肤名称
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static string GetThemeName(HttpRequestBase request)
        {
            string cookieTheme = HttpCookieHelper.GetCookie("easyuitheme");

            if (string.IsNullOrEmpty(cookieTheme) && request["easyuitheme"].ObjToStr() != string.Empty)
            {
                cookieTheme = request["easyuitheme"].ObjToStr();
            }
            string themeName = string.IsNullOrWhiteSpace(cookieTheme) ? ConstDefine.DEFAULT_THEME : cookieTheme;

            return(themeName);
        }
Exemple #4
0
        private string PostSign(WebSiteModel model)
        {
            //获取cookie
            //model.Cookie BAIDUID
            //model.Result.Cookie  BDUSS
            string cookie1 = HttpCookieHelper.GetCookieValue("BAIDUID", model.Cookie);
            string cookie2 = HttpCookieHelper.GetCookieValue("BDUSS", model.Result.Cookie);
            string cookie  = string.Format("BAIDUID={0};BDUSS={1}", cookie1, cookie2);
            var    result  = http.GetHtml(new HttpItem()
            {
                URL    = model.SignRequestUrl,
                Cookie = cookie
            });

            return(result.Html);
        }
Exemple #5
0
        public LoginResultObject GetUserTokenII(string loginName, string password)
        {
            LoginResultObject result = null;

            HttpCookieHelper.ClearCurrentAuthCooike();
            var identity = new LoginIdentity(loginName, password, GetSSOConfigSettings.Informations["SystemCode"].Value);

            if (ValidateIdentity(identity))
            {
                using (var channel = ChannelFactory.Create <ILogin>(ServiceAddress))
                {
                    result = channel.Channel.Login(RemotingToken.Token, identity);
                }
            }
            return(result);
        }
Exemple #6
0
        public SignModel BeginSign(string userName, string userPwd)
        {
            SignModel    signModel = new SignModel();
            WebSiteModel model     = new WebSiteModel()
            {
                SiteDomin      = "http://www.baidu.com/",
                SiteName       = "百度",
                LoginUrl       = "https://passport.baidu.com/v2/api/?login",
                LoginName      = "*****@*****.**",
                LoginPwd       = "ycq0729,.",
                SignRequestUrl = "http://wenku.baidu.com/task/submit/signin",
            };

            SetCookieToken(model);
            string uname = PostLogin(model);

            if (uname != null)//登陆成功
            {
                signModel.Msg = "登陆成功";
                string cookie1 = HttpCookieHelper.GetCookieValue("BAIDUID", model.Cookie);
                string cookie2 = HttpCookieHelper.GetCookieValue("BDUSS", model.Result.Cookie);
                model.Cookie = string.Format("BAIDUID={0};BDUSS={1}", cookie1, cookie2);
                model.Result = PostSign(model);
                if (!model.Result.Html.Contains("errno\":\"109") && !model.Result.Html.Contains("errno\":\"0"))
                {
                    signModel.Msg = "签到成功";
                }
                else if (model.Result.Html.Contains("errno\":\"0") && model.Result.Html.Contains("error_no\":\"0"))
                {
                    signModel.Msg = "签到失败或已签到";
                }
                else
                {
                    signModel.Msg = "签到失败:" + model.Result.Html;
                }
            }
            else
            {
                signModel.Msg = "登陆失败";
            }
            signModel.Msg = "[" + userName + "]" + signModel.Msg;

            return(signModel);
        }
Exemple #7
0
        private bool IndexPageCheck(HttpResult result, HttpItem indexItem, out string mainCookie)
        {
            var count = 0;

            mainCookie = result.Cookie;
            var http = new HttpHelper();

            do
            {
                if (result.Cookie.Contains("nlbi") || result.Cookie.Contains("ASP.NET_SessionId"))
                {
                    return(true);
                }

                var ir_url = Get_Incapsula_Resource_URL(result.Html);
                var item2  = new HttpItem()
                {
                    URL    = loginParam.WebUrl + ir_url,
                    Cookie = mainCookie
                };
                var r = http.GetHtml(item2);
                if (!string.IsNullOrEmpty(r.Cookie))
                {
                    mainCookie = HttpCookieHelper.CombineCookie(mainCookie, r.Cookie);
                }
                indexItem.Cookie = mainCookie;
                result           = http.GetHtml(indexItem);
                mainCookie       = HttpCookieHelper.CombineCookie(mainCookie, result.Cookie);
                if (mainCookie.Contains("nlbi"))
                {
                    return(true);
                }
                count++;
                if (count > 3)
                {
                    logger.Error("Index page Robots check failed over 3 times!!!");
                }
            } while (count < 3);

            return(false);
        }
Exemple #8
0
 /// <summary>
 /// 将字符串Cookie转为CookieCollection
 /// </summary>
 /// <param name="strcookie">Cookie字符串</param>
 /// <returns>List-CookieItem</returns>
 public static CookieCollection StrCookieToCookieCollection(string strcookie)
 {
     return(HttpCookieHelper.StrCookieToCookieCollection(strcookie));
 }
Exemple #9
0
 /// <summary>
 /// 根据字符生成Cookie和精简串,将排除path,expires,domain以及重复项
 /// </summary>
 /// <param name="strcookie">Cookie字符串</param>
 /// <returns>精简串</returns>
 public static string GetSmallCookie(string strcookie)
 {
     return(HttpCookieHelper.GetSmallCookie(strcookie));
 }
Exemple #10
0
        public bool AutoLogin()
        {
            try
            {
                Available = false;
                Console.WriteLine("Start login...");

                //  test跳过登录
                //if (beginDataID > 0)
                //{
                //    _nextTime = "";//清空
                //    available = true;
                //    Pause = false;
                //    ErrorTimes = 0;
                //    LoginResult = new LoginResult() { LoginSuccess = true };
                //    return true;
                //}

                HttpHelper http = new HttpHelper();
                //访问首页
                HttpItem   item;
                HttpResult result;
                string     mainCookie = "";// "LangKey=en";

                ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                item = new HttpItem()
                {
                    URL               = loginParam.WebUrl + "/Default.aspx?IsSSL=1",
                    UserAgent         = userAgent,
                    Accept            = accept,
                    Cookie            = mainCookie,
                    Allowautoredirect = true,
                    KeepAlive         = true
                };
                item.Header.Add("Accept-Language", "en-US;q=0.5,en;q=0.3");
                item.Header.Add("Accept-Encoding", acceptEncoding);
                item.Header.Add("Upgrade-Insecure-Requests", "1");
                result = http.GetHtml(item);
                string tmpCookie;
                if (!IndexPageCheck(result, item, out tmpCookie))
                {
                    Console.WriteLine("MessageBox|Index page Robots check failed over 3 times!!!");
                    return(false);
                }
                mainCookie = HttpCookieHelper.CombineCookie(mainCookie, tmpCookie);

                //  首页访问成功
                if (result.StatusCode == HttpStatusCode.OK)
                {
                    //  检查IBC是否维护
                    if (result.Html.Contains("window.location.href='index.aspx"))
                    {
                        Console.WriteLine("maxbet website is under maintenance!!!");
                        logger.Debug("MessageBox|maxbet website is under maintenance!!!");
                        return(false);
                    }

                    //  请求用DeviceID作为cookie请求JS
                    var item1 = new HttpItem()
                    {
                        URL       = "https://sc.detecas.com/di/activator.ashx",
                        UserAgent = userAgent,
                        Accept    = "*/*",
                        Referer   = loginParam.WebUrl + "/Default.aspx?IsSSL=1",
                        Host      = "sc.detecas.com",
                        KeepAlive = true,
                        //  只根据浏览器信息生成的,固定不变
                    };
                    item1.Header.Add("Accept-Language", "zh-CN,zh;q=0.8");
                    var deviceRes = http.GetHtml(item1);

                    //  模拟JS生成相关参数进行下一次请求获取CacheDeviceID
                    var cof = JsonConvert.DeserializeObject <Dictionary <string, string> >(RegGetStr(deviceRes.Html, "Config=", ";"));
                    var c   = "{\"na\":\"N/A\",\"deviceCode\":\"7af746974dc2482cd562d21549e4b6b659b1bc12;8c67f4af3a2362fedc24b0f3997eb900\",\"appVersion\":\"5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36\",\"timeZone\":\"-480\",\"userAgent\":\"Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36\",\"screen\":{\"width\":1920,\"height\":1080,\"colorDepth\":24},\"deviceId\":\"" + cof["defaultDeviceId"] + "\",\"href\":\"" + loginParam.WebUrl + "/Default.aspx\",\"capturedDate\":\"" + cof["capturedDate"] + "\"}";
                    var _di = Convert.ToBase64String(Encoding.UTF8.GetBytes(c));

                    //首页访问成功
                    HtmlDocument htmlDoc = new HtmlDocument();
                    htmlDoc.LoadHtml(result.Html);
                    //获取验证码
                    HtmlNode node = htmlDoc.GetElementbyId("txtCode");
                    string   code = "";
                    if (node != null)
                    {
                        code = node.Attributes["value"].Value;
                    }
                    item.URL    = loginParam.WebUrl + "/getBeforeLoginCode.ashx?_=" + ToUnixTimeSpan(DateTime.Now);
                    item.Cookie = mainCookie;
                    var rs = http.GetHtml(item);
                    code = rs.Html;

                    // 获取tk
                    HtmlNode node1 = htmlDoc.GetElementbyId("__tk");
                    string   tk    = "";
                    if (node1 != null)
                    {
                        tk = node1.Attributes["value"].Value;
                    }

                    //ibc对会员密码加密
                    string CFSKey      = CFS.Encrypt(loginParam.Password);
                    string EnCryptData = CFSKey + code;
                    string hidKey      = ML.Security.MD5.Encrypt(EnCryptData);
                    //IBC有一个参数__di又两个加密JS制作 暂时无用所以没加
                    string _data = "txtID=" + loginParam.Username + "&txtPW2=" + loginParam.Password + "&txtPW=" + hidKey +
                                   "&txtCode=" + code +
                                   "&hidKey=&hidServerKey=maxbet.com&hidLowerCasePW=&IEVerison=0&IsSSL=1&PF=Default&__tk=" + tk + "&__di=" + _di;// + "&detecas-analysis=" + dataAnaly;

                    item = new HttpItem()
                    {
                        URL               = loginParam.WebUrl + "/ProcessLogin.aspx",
                        Method            = "POST",
                        ContentType       = "application/x-www-form-urlencoded",
                        Cookie            = mainCookie,//_cookieDic.ParseCookieDictionary(),
                        Postdata          = _data,
                        UserAgent         = userAgent,
                        Accept            = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
                        Referer           = loginParam.WebUrl + "/Default.aspx?IsSSL=1",
                        KeepAlive         = true,
                        Expect100Continue = false,
                        Host              = "www.maxbet.com",
                    };
                    item.Header.Add("Accept-Language", "zh-CN,zh;q=0.8");
                    item.Header.Add("Cache-Control", "max-age=0");
                    item.Header.Add("Upgrade-Insecure-Requests", "1");
                    item.KeepAlive = true;
                    result         = http.GetHtml(item);
                    mainCookie     = HttpCookieHelper.CombineCookie(mainCookie, result.Cookie);

                    //  登录页面访问成功将跳转到子域名验证页面
                    if (result.StatusCode == HttpStatusCode.OK)
                    {
                        #region 新的登录流程

                        if (result.Html.Contains("GetLoginVerifyInfo.aspx"))
                        {
                            var url = RegGetStr(result.Html, "location='.", "'");
                            item = new HttpItem()
                            {
                                URL       = loginParam.WebUrl + url,
                                Cookie    = mainCookie,
                                UserAgent = userAgent,
                                Accept    = accept,
                                Referer   = loginParam.WebUrl + "/ProcessLogin.aspx",
                                KeepAlive = true,
                            };
                            item.Header.Add("Accept-Language", "en-US;q=0.5,en;q=0.3");
                            item.Header.Add("Accept-Encoding", acceptEncoding);
                            item.Header.Add("Upgrade-Insecure-Requests", "1");
                            var r = http.GetHtml(item);
                            localUrl = RegGetStr(r.Html, "href=\"", ".com") + ".com";
                            if (!r.RedirectUrl.Contains("ValidateToken"))
                            {
                                logger.Error("Failed ValidateToken! " + "\n Html = " + r.Html);
                                return(false);
                            }

                            mainCookie  = HttpCookieHelper.RemoveCookieByKey("ASP.NET_SessionId", mainCookie);
                            mainCookie  = HttpCookieHelper.RemoveCookieByFuzzyKey("sto-fx", mainCookie);
                            item.URL    = r.RedirectUrl;
                            item.Cookie = mainCookie;
                            r           = http.GetHtml(item);

                            if (r.Html.Contains("ChangeAccountPassword"))
                            {
                                Console.WriteLine("MessageBox|Need to change the account password on the IBC website.");
                                Thread.Sleep(2 * 60 * 1000);
                                return(false);
                            }

                            if (!r.Html.Contains("/sports"))
                            {
                                logger.Error("Failed ValidateToken! " + "\n Html = " + r.Html);
                                return(false);
                            }

                            mainCookie  = HttpCookieHelper.CombineCookie(mainCookie, r.Cookie);
                            item.URL    = localUrl + "/sports";
                            item.Cookie = mainCookie;
                            result      = http.GetHtml(item);

                            if (result.StatusCode != HttpStatusCode.OK)
                            {
                                logger.Error("Failed sports! " + "\n Html = " + r.Html);
                                return(false);
                            }
                            //mainCookie = HttpCookieHelper.CombineCookie(mainCookie, r.Cookie);
                            //mainCookie = HttpCookieHelper.RemoveCookieByKey("_culture", mainCookie);
                            //item.URL = localUrl + "/SwitchPlatform/SwitchToOtherSite/";
                            //item.Cookie = mainCookie;
                            //item.Referer = localUrl + "/sports";
                            //result = http.GetHtml(item);
                        }
                        #endregion

                        #region 点击Agree
                        //  点击Agree
                        if (result.Html.Contains("rulesalert.aspx"))
                        {
                            item.URL     = loginParam.WebUrl + "/rulesalert.aspx";
                            item.Method  = "GET";
                            item.Referer = loginParam.WebUrl + "/ProcessLogin.aspx";
                            var res = http.GetHtml(item);

                            item.URL     = loginParam.WebUrl + "/rulesContent.aspx";
                            item.Method  = "GET";
                            item.Referer = loginParam.WebUrl + "/rulesalert.aspx";
                            res          = http.GetHtml(item);

                            item.URL         = loginParam.WebUrl + "/rulesalert.aspx";
                            item.Method      = "POST";
                            item.Postdata    = "Accept=YES";
                            item.Referer     = item.URL;
                            item.ContentType = "application/x-www-form-urlencoded";
                            res = http.GetHtml(item);
                        }
                        #endregion

                        if (result.StatusCode == HttpStatusCode.OK)
                        {
                            if (!ValidateFailed(result.Html))
                            {
                                return(false);
                            }

                            if (!GetNecessaryParam(result.Html, mainCookie + result.Cookie))
                            {
                                logger.Error("Cannot get necessaryParam , html = " + result.Html);
                                return(false);
                            }
                            mainCookie += result.Cookie;

                            //  访问另一个子域名获取cookie
                            item.URL     = "https://agnj3.maxbet.com/socket.io/?gid=" + GetGid() + "&token=" + SocketInitDto.Token + "&id=" + SocketInitDto.Id + "&rid=" + SocketInitDto.Rid + "&EIO=3&transport=polling";
                            item.Accept  = "*/*";
                            item.Host    = "agnj3.maxbet.com";
                            item.Referer = item.Referer + "/sports";
                            var anotherRes = http.GetHtml(item);
                            mainCookie = HttpCookieHelper.CombineCookie(mainCookie, anotherRes.Cookie);
                            mainCookie = HttpCookieHelper.RemoveCookieByKey("io", mainCookie);

                            Console.WriteLine("Login Success.");
                            logger.Info("Login Success!");
                            Available   = true;
                            Status      = TakerStatus.Started;
                            checkCookie = mainCookie;
                            checkUrl    = localUrl;
                            loginCheckTimer.Start();
                            return(true);
                        }
                    }
                }
                Console.WriteLine("Request web page failed,check network connection or network envirenment");
                return(false);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Login failed," + ex.Message);
                logger.Error(ex.ToString());
                return(false);
            }
        }
Exemple #11
0
 /// <summary>
 /// 自动合并两个Cookie的值返回更新后结果
 /// </summary>
 /// <param name="OldCookie">Cookie1</param>
 /// <param name="NewCookie">Cookie2</param>
 /// <returns>返回更新后的Cookie</returns>
 public static string GetMergeCookie(string OldCookie, string NewCookie)
 {
     return(HttpCookieHelper.MergerCookies(OldCookie, NewCookie));
 }
        public bool SimulateLogin()
        {
            return(true);

            IPProxy ipProxy = null;

            if (Settings.IPProxyList == null || Settings.IPProxyList.Where(c => c.Unavaiable == false).Count() <= 0)
            {
                Environment.Exit(0);
            }

            HttpHelper http = new HttpHelper();

            //尝试登陆
            while (true)
            {
                try
                {
                    ipProxy = Settings.GetIPProxy();
                    if (ipProxy == null || string.IsNullOrEmpty(ipProxy.IP))
                    {
                        Settings.SimulateCookies = string.Empty;
                        //return true;
                    }
                    HttpItem item = new HttpItem()
                    {
                        URL         = "http://luckymn.cn/QuestionAnswer", //URL     必需项
                        Encoding    = null,                               //编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                        Method      = "GET",                              //URL     可选项 默认为Get
                        ContentType = "text/html",                        //返回类型    可选项有默认值
                        KeepAlive   = true,
                        Timeout     = 2000
                    };

                    if (ipProxy != null)
                    {
                        item.ProxyIp = ipProxy.IP;
                    }
                    Console.WriteLine(string.Format("尝试登陆{0}", Settings.curIPProxy != null ? Settings.curIPProxy.IP : string.Empty));
                    HttpResult result = http.GetHtml(item);
                    if (result.StatusCode == HttpStatusCode.OK)
                    {
                        string cookie = string.Empty;
                        foreach (CookieItem s in HttpCookieHelper.GetCookieList(result.Cookie))
                        {
                            //if (s.Key.Contains("24a79_"))
                            {
                                cookie += HttpCookieHelper.CookieFormat(s.Key, s.Value);
                            }
                        }
                        Console.WriteLine("{0}访问成功", item.ProxyIp);
                        return(true);
                    }
                    return(false);
                }
                catch (WebException ex)
                {
                    IPInvalidProcess(ipProxy);
                }
                catch (Exception ex)
                {
                    IPInvalidProcess(ipProxy);
                }
            }
        }
Exemple #13
0
        /// <summary>
        /// 模拟登陆,ip代理可能需要用到
        /// </summary>
        /// <returns></returns>
        public bool SimulateLogin()
        {
            if (isSpecialUrlMode)
            {
                return(true);
            }
            //之前似乎否已经登陆过了
            if (!string.IsNullOrEmpty(Settings.LoginAccount))
            {
                DBChangeQueue.Instance.EnQueue(new StorageData()
                {
                    Document = new BsonDocument().Add(DataTableName + "status", "1"), Name = DataTableNameAccount, Query = Query.EQ("userName", Settings.LoginAccount), Type = StorageType.Update
                });
                StartDBChangeProcess();
            }
            var accountBson = AccountQueue.Instance.DeQueue();

            if (accountBson == null)
            {
                Console.WriteLine("账号已用完");
                Environment.Exit(0);
                return(false);
            }

            IPProxy ipProxy = null;

            HttpHelper http = new HttpHelper();

            //尝试登陆
            while (true)
            {
                try
                {
                    ipProxy = Settings.GetIPProxy();
                    if (ipProxy == null || string.IsNullOrEmpty(ipProxy.IP))
                    {
                        Settings.SimulateCookies = string.Empty;
                        //return true;
                    }

                    HttpItem item = new HttpItem()
                    {
                        URL      = "https://passport.fang.com/login.api",                                           //URL     必需项
                        Encoding = null,                                                                            //编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                                                                                                                    //Encoding = Encoding.Default,
                        Method = "post",                                                                            //URL     可选项 默认为Get
                                                                                                                    //Timeout = 100000,//连接超时时间     可选项默认为100000
                                                                                                                    //ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000
                                                                                                                    //IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写
                                                                                                                    //Cookie = "",//字符串Cookie     可选项
                        UserAgent         = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko", //用户的浏览器类型,版本,操作系统     可选项有默认值
                        Accept            = "text/html, application/xhtml+xml, */*",                                //    可选项有默认值
                        ContentType       = "application/x-www-form-urlencoded",                                    //返回类型    可选项有默认值
                        Referer           = "https://passport.fang.com/",                                           //来源URL     可选项
                        Allowautoredirect = true,
                    };

                    if (accountBson != null)
                    {
                        item.Postdata = accountBson.Text("postData");
                    }

                    if (ipProxy != null)
                    {
                        item.ProxyIp = ipProxy.IP;
                    }
                    if (Settings.CurWebProxy != null)
                    {
                        item.WebProxy = Settings.CurWebProxy;
                    }
                    Console.WriteLine(string.Format("尝试登陆{0}", Settings.curIPProxy != null ? Settings.curIPProxy.IP : string.Empty));
                    HttpResult result = http.GetHtml(item);
                    if (!result.Html.Contains("Success"))
                    {
                        return(false);
                    }
                    string cookie = string.Empty;
                    foreach (CookieItem s in HttpCookieHelper.GetCookieList(result.Cookie))
                    {
                        //if (s.Key.Contains("24a79_"))
                        {
                            cookie += HttpCookieHelper.CookieFormat(s.Key, s.Value);
                        }
                    }
                    if (accountBson != null)
                    {
                        var account = accountBson.Text("userName");
                        if (result.Html.IndexOf("Success") > 0)
                        {
                            Settings.SimulateCookies = cookie;//设置cookie值
                            Settings.LoginAccount    = account;
                            Console.WriteLine(string.Format("{0}模拟登陆成功", account));
                            return(true);
                        }
                        DBChangeQueue.Instance.EnQueue(new StorageData()
                        {
                            Document = new BsonDocument().Add("status", "1"), Name = DataTableNameAccount, Query = Query.EQ("userName", account), Type = StorageType.Update
                        });
                        StartDBChangeProcess();
                    }
                    else
                    {
                        Settings.SimulateCookies = cookie;//设置cookie值
                        Console.WriteLine("登陆失败");
                        return(false);
                    }
                    return(false);
                }
                catch (WebException ex)
                {
                    IPInvalidProcess(ipProxy);
                }
                catch (Exception ex)
                {
                    IPInvalidProcess(ipProxy);
                }
            }
        }
Exemple #14
0
 public static CookieCollection GetMergeCookie(CookieCollection OldCookie, CookieCollection NewCookie)
 {
     return(HttpCookieHelper.MergerCookies(OldCookie, NewCookie));
 }
Exemple #15
0
 /// <summary>
 /// 将CookieCollection转为字符串Cookie
 /// </summary>
 /// <param name="cookie">Cookie字符串</param>
 /// <returns>strcookie</returns>
 public static string CookieCollectionToStrCookie(CookieCollection cookie)
 {
     return(HttpCookieHelper.CookieCollectionToStrCookie(cookie));
 }
Exemple #16
0
        /// <summary>
        /// 模拟登陆,ip代理可能需要用到
        /// </summary>
        /// <returns></returns>
        public bool SimulateLogin()
        {
            return(true);

            IPProxy ipProxy = null;

            HttpHelper http = new HttpHelper();

            //尝试登陆
            while (true)
            {
                try
                {
                    ipProxy = Settings.GetIPProxy();
                    if (ipProxy == null || string.IsNullOrEmpty(ipProxy.IP))
                    {
                        Settings.SimulateCookies = string.Empty;
                        //return true;
                    }
                    HttpItem item = new HttpItem()
                    {
                        URL      = "https://passport.fang.com/login.api",                                           //URL     必需项
                        Encoding = null,                                                                            //编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                                                                                                                    //Encoding = Encoding.Default,
                        Method = "post",                                                                            //URL     可选项 默认为Get
                                                                                                                    //Timeout = 100000,//连接超时时间     可选项默认为100000
                                                                                                                    //ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000
                                                                                                                    //IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写
                                                                                                                    //Cookie = "",//字符串Cookie     可选项
                        UserAgent         = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko", //用户的浏览器类型,版本,操作系统     可选项有默认值
                        Accept            = "text/html, application/xhtml+xml, */*",                                //    可选项有默认值
                        ContentType       = "application/x-www-form-urlencoded",                                    //返回类型    可选项有默认值
                        Referer           = "https://passport.fang.com/",                                           //来源URL     可选项
                        Postdata          = "Uid=luckymn&Pwd=1c523e9b2109407d0857676dfc20af997c14791f495ec8676979628bfef0762ce2679e2f4770d536526bcf00639ec803539f02c54387fbd4a3f159ec5a6185cd46cb139b5c2696c269bce5b7f9c00fb3a9bc58e815773c227b54d4570da0cbee50b47b29c363d398791d3065c0343494aebaa925313e705fd514898e56c2df29&Service=soufun-passport-web&IP=&VCode=&AutoLogin=1",
                        Allowautoredirect = true,
                    };

                    if (ipProxy != null)
                    {
                        item.ProxyIp = ipProxy.IP;
                    }
                    Console.WriteLine(string.Format("尝试登陆{0}", Settings.curIPProxy != null ? Settings.curIPProxy.IP : string.Empty));
                    HttpResult result = http.GetHtml(item);
                    string     cookie = string.Empty;
                    foreach (CookieItem s in HttpCookieHelper.GetCookieList(result.Cookie))
                    {
                        //if (s.Key.Contains("24a79_"))
                        {
                            cookie += HttpCookieHelper.CookieFormat(s.Key, s.Value);
                        }
                    }
                    if (result.Html.IndexOf("luckymn") > 0)
                    {
                        Settings.SimulateCookies = cookie;//设置cookie值
                        Console.WriteLine("zluckymn模拟登陆成功");
                        return(true);
                    }
                    return(false);
                }
                catch (WebException ex)
                {
                    IPInvalidProcess(ipProxy);
                }
                catch (Exception ex)
                {
                    IPInvalidProcess(ipProxy);
                }
            }
        }
Exemple #17
0
 /// <summary>
 /// 自动合并两个Cookie的值返回更新后结果
 /// </summary>
 /// <param name="cookie1">Cookie1</param>
 /// <param name="cookie2">Cookie2</param>
 /// <returns>返回更新后的Cookie</returns>
 public static string GetMergeCookie(string cookie1, string cookie2)
 {
     return(HttpCookieHelper.GetMergeCookie(cookie1, cookie2));
 }