Esempio n. 1
0
        public LoginResult DoLogin(string UserName, string Password, string UserAgent = "")
        {
            Stopwatch stopwatch = new Stopwatch();

            cookies = new CookieContainer();

            try
            {
                stopwatch.Start();
                HttpHelper.GetHttpContent("https://passport.baidu.com/passApi/html/_blank.html", cookies: cookies, cookiesDomain: "passport.baidu.com");

                //1. Get the token.
                string token_url      = string.Format("https://passport.baidu.com/v2/api/?getapi&tpl=mn&apiver=v3&tt={0}&class=login&gid={1}&logintype=dialogLogin&callback=bd__cbs__{2}", TimeHelper.ConvertDateTimeInt(DateTime.Now), Guid.NewGuid().ToString().ToUpper(), build_callback());
                string prepareContent = HttpHelper.GetHttpContent(token_url, null, cookies, referer: "https://www.baidu.com/", encode: Encoding.GetEncoding("GB2312"), cookiesDomain: "passport.baidu.com");
                //string prepareJson = prepareContent.Split('(')[1].Split(')')[0];
                dynamic prepareJson = JsonConvert.DeserializeObject(prepareContent.Split('(')[1].Split(')')[0]);
                string  token       = prepareJson.data.token;

                //2. Get public key
                string pubkey_url    = "https://passport.baidu.com/v2/getpublickey?token={0}&tpl=mn&apiver=v3&tt={1}&gid={2}&callback=bd__cbs__{3}";
                string pubkeyContent = HttpHelper.GetHttpContent(string.Format(pubkey_url, token, TimeHelper.ConvertDateTimeInt(DateTime.Now), Guid.NewGuid().ToString().ToUpper(), build_callback()), null, cookies, referer: "https://www.baidu.com/", encode: Encoding.GetEncoding("GB2312"), cookiesDomain: "passport.baidu.com");

                dynamic pubkeyJson = JsonConvert.DeserializeObject(pubkeyContent.Split('(')[1].Split(')')[0]);
                rsa_pub_baidu = pubkeyJson.pubkey;
                string KEY = pubkeyJson.key;

                stopwatch.Stop();
                //3. Build post data
                string login_data = "staticpage=https%3A%2F%2Fwww.baidu.com%2Fcache%2Fuser%2Fhtml%2Fv3Jump.html&charset=UTF-8&token={0}&tpl=mn&subpro=&apiver=v3&tt={1}&codestring=&safeflg=0&u=https%3A%2F%2Fwww.baidu.com%2F&isPhone=&detect=1&gid={2}&quick_user=0&logintype=dialogLogin&logLoginType=pc_loginDialog&idc=&loginmerge=true&splogin=rate&username={3}&password={4}&verifycode=&mem_pass=on&rsakey={5}&crypttype=12&ppui_logintime={6}&countrycode=&callback=parent.bd__pcbs__{7}";

                login_data = string.Format(login_data, token, TimeHelper.ConvertDateTimeInt(DateTime.Now), Guid.NewGuid().ToString().ToUpper(), HttpUtility.UrlEncode(UserName), HttpUtility.UrlEncode(get_pwa_rsa(Password)), HttpUtility.UrlEncode(KEY), stopwatch.ElapsedMilliseconds, build_callback());

                //4. Post the login data
                string login_url = "https://passport.baidu.com/v2/api/?login";
                HttpHelper.GetHttpContent(login_url, login_data, cookies, referer: "https://www.baidu.com/", cookiesDomain: "passport.baidu.com");

                string home_url = "https://www.baidu.com";
                string result   = HttpHelper.GetHttpContent(home_url, cookies: cookies, cookiesDomain: "passport.baidu.com");

                //5. Verifty the login result
                if (string.IsNullOrWhiteSpace(result) || result.Contains("账号存在异常") || !result.Contains("bds.comm.user=\""))
                {
                    return(new LoginResult()
                    {
                        Result = ResultType.AccounntLimit, Msg = "Fail, Msg: Login fail! Maybe you account is disable or captcha is needed."
                    });
                }
            }
            catch (Exception e)
            {
                return(new LoginResult()
                {
                    Result = ResultType.ServiceError, Msg = "Error, Msg: " + e.ToString()
                });
            }

            LoginResult loginResult = new LoginResult()
            {
                Result = ResultType.Success, Msg = "Success", Cookies = HttpHelper.GetAllCookies(cookies)
            };

            return(loginResult);
        }
Esempio n. 2
0
        /// <summary>
        /// Needn't provide username and password. You can put any string for those.
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public LoginResult DoLogin(string UserName, string Password)
        {
            LoginResult loginResult = new LoginResult();

            HttpHelper.GetHttpContent("https://wx.qq.com/?&lang=zh_CN", cookies: cookies);

            //request the image, and send this image url to email.
            string QRLogin = HttpHelper.GetHttpContent("https://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN&_=" + TimeHelper.ConvertDateTimeInt(DateTime.Now), cookies: cookies);

            string QRUid = "";
            string qrUrl = "";
            Match  m     = Regex.Match(QRLogin, "\"(?<QRUid>.*?)\";");

            if (m.Success && m.Groups["QRUid"].Success)
            {
                QRUid = m.Groups["QRUid"].Value;
                qrUrl = string.Format(QRUrlFmt, QRUid);
            }

            //send QR image to other process.
            string qrResult = PluginHelper.Operation(LoginSite.WeChat, qrUrl, null);

            if (!string.IsNullOrEmpty(qrResult))
            {
                string strFmt = "https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid={0}&tip=0&r={1}8&_={2}";

                int i = 0;
                do
                {
                    string result = HttpHelper.GetHttpContent(string.Format(strFmt, QRUid, "-595416181", TimeHelper.ConvertDateTimeInt(DateTime.Now)), cookies: cookies);

                    i++;

                    //If contains window.code=200, succ; If contains window.code=201, ready。
                    if (result.Contains("window.code=200;"))
                    {
                        Match m2 = Regex.Match(result, "redirect_uri=\"(?<redirect>.*?)\";");
                        if (m2.Success && m2.Groups["redirect"].Success)
                        {
                            string redirectContent = HttpHelper.GetHttpContent(m2.Groups["redirect"].Value + "&fun=new&version=v2&lang=zh_CN", cookies: cookies, referer: WxUrl);
                            Match  m3 = Regex.Match(redirectContent, "<skey>(?<skey>.*?)</skey><wxsid>(?<wxsid>.*?)</wxsid><wxuin>(?<wxuin>.*?)</wxuin><pass_ticket>(?<pass_ticket>.*?)</pass_ticket>");
                            if (m3.Success && m3.Groups["skey"].Success && m3.Groups["wxsid"].Success && m3.Groups["wxuin"].Success && m3.Groups["pass_ticket"].Success)
                            {
                                skey        = m3.Groups["skey"].Value;
                                wxsid       = m3.Groups["wxsid"].Value;
                                wxuin       = m3.Groups["wxuin"].Value;
                                pass_ticket = m3.Groups["pass_ticket"].Value;

                                //wxInit, Get the synckey.
                                string wxInitUrl  = string.Format("https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r={0}&lang=zh_CN&pass_ticket={1}", TimeHelper.ConvertDateTimeInt(DateTime.Now) / 1000, pass_ticket);
                                string wxInitPost = "{\"BaseRequest\":{\"Uin\":\"" + wxuin + "\",\"Sid\":\"" + wxsid + "\",\"Skey\":\"" + skey + "\",\"DeviceID\":\"" + BuildDeviceId() + "\"}}";
                                do
                                {
                                    string wxInitContent = HttpHelper.GetHttpContent(wxInitUrl, wxInitPost, cookies, referer: "https://wx.qq.com/?&lang=zh_CN");
                                    if (!string.IsNullOrEmpty(wxInitContent))
                                    {
                                        synckey = GetSyncKeyStr(wxInitContent);
                                        if (!string.IsNullOrEmpty(synckey))
                                        {
                                            break;
                                        }
                                    }
                                }while (true);


                                tickTimer.Interval = 2000;
                                tickTimer.Elapsed += new System.Timers.ElapsedEventHandler(SyncCheck);
                                tickTimer.Start();

                                loginResult.Result  = ResultType.Success;
                                loginResult.Msg     = "Success";
                                loginResult.Cookies = HttpHelper.GetAllCookies(cookies);
                                return(loginResult);
                            }
                        }
                    }
                }while (i <= 20);
            }

            loginResult.Result = ResultType.Timeout;
            loginResult.Msg    = "error, no body scan the QR code in limited time.";

            return(loginResult);
        }
        /// <summary>
        /// weibo login
        /// </summary>
        /// <param name="UserName">user name</param>
        /// <param name="Password">password</param>
        /// <returns>Login result</returns>
        public LoginResult DoLogin(string UserName, string Password, string UserAgent = "")
        {
            cookies = new CookieContainer();
            try
            {
                if (GetPreloginStatus(UserName))
                {
                    string login_url  = "https://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.15)&_=" + TimeHelper.ConvertDateTimeInt(DateTime.Now).ToString();
                    string login_data = "entry=account&gateway=1&from=&savestate=30&useticket=0&pagerefer=&vsnf=1&su=" + get_user(UserName)
                                        + "&service=sso&servertime=" + servertime + "&nonce=" + nonce + "&pwencode=rsa2&rsakv=" + rsakv + "&sp=" + get_pwa_rsa(Password)
                                        + "&sr=1440*900&encoding=UTF-8&cdult=3&domain=sina.com.cn&prelt=" + prelt + "&returntype=TEXT";

                    string  Content     = HttpHelper.GetHttpContent(login_url, login_data, cookies);
                    dynamic refreshJson = JsonConvert.DeserializeObject(Content.Substring(0, Content.LastIndexOf('}') + 1));
                    HttpHelper.GetHttpContent(refreshJson.crossDomainUrlList[0].ToString(), cookies: cookies, referer: login_url);

                    string home_url = "http://weibo.com/tnidea/";
                    string result   = HttpHelper.GetHttpContent(home_url, cookies: cookies);

                    if (string.IsNullOrWhiteSpace(result) || result.Contains("账号存在异常") || !result.Contains("$CONFIG['islogin']='******'"))
                    {
                        return(new LoginResult()
                        {
                            Result = ResultType.AccounntLimit, Msg = "Fail, Msg: Login fail! Maybe you account is disable or captcha is needed."
                        });
                    }
                }
                else
                {
                    return new LoginResult()
                           {
                               Result = ResultType.ServiceError, Msg = "Error, Msg: The method is out of date, please update!"
                           }
                };
            }
            catch (Exception e)
            {
                return(new LoginResult()
                {
                    Result = ResultType.ServiceError, Msg = "Error, Msg: " + e.ToString()
                });
            }

            LoginResult loginResult = new LoginResult()
            {
                Result = ResultType.Success, Msg = "Success", Cookies = HttpHelper.GetAllCookies(cookies)
            };

            return(loginResult);
        }