Exemple #1
0
        public static string GetVcode(Image img)
        {
            string m_softKey  = "365bd32d7ca2b5f07bc8328520542d9c";
            string m_userName = "******";
            string m_password = "******";
            //打码平台自动获取验证码
            string randomname = Guid.NewGuid().ToString();

            if (!Directory.Exists("pincode"))
            {
                Directory.CreateDirectory("pincode");
            }
            string imgPath = "pincode/" + randomname + "login.png";

            if (img == null)
            {
                return("");
            }
            img.Save(imgPath);
            FileInfo   fi = new FileInfo(imgPath);
            FileStream fs = new FileStream(imgPath, FileMode.Open);

            byte[] ba   = new byte[fi.Length];
            int    nRet = fs.Read(ba, 0, (int)fi.Length);

            if (nRet == 0)
            {
                return("");
            }

            //请求答题
            StringBuilder VCodeText = new StringBuilder(100);
            int           ret       = Dama2.D2Buf(
                m_softKey,  //softawre key (software id)
                m_userName, //user name
                m_password, //password
                ba,         //图片数据,图片数据不可大于4M
                (uint)nRet, //图片数据长度
                60,         //超时时间,单位为秒,更换为实际需要的超时时间
                200,        //验证码类型ID,参见 http://wiki.dama2.com/index.php?n=ApiDoc.GetSoftIDandKEY
                VCodeText); //成功时返回验证码文本(答案)

            if (ret > 0)
            {
                uint ulVCodeID = (uint)ret;
                return(VCodeText.ToString());;
            }
            File.Delete(imgPath);
            return(VCodeText.ToString());
        }
Exemple #2
0
        public static CookieContainer Login(string username, string password, WebProxy proxy)
        {
            var             preData = WeiboHandler.PreLogin(username);
            CookieContainer weibocc = new CookieContainer();

            if (preData != null)
            {
                string code = "";
                var    img  = WeiboHandler.GetLoginCodePic(preData.pcid);
                while (code == "" || code == "IERROR" || code == "ERROR" || code == null)
                {
                    code = Dama2.GetVcode(img);
                }
                //string code = null;
                //var img = WeiboHandler.GetLoginCodePic(preData.pcid);
                var loginData = WeiboHandler.Login(preData, username, password, code, proxy);
                if (loginData == null)
                {
                    return(null);
                }
                weibocc = WeiboHandler.InitWeiboCookie(username, loginData.cookies);
                bool isLogin = WeiboHandler.TestLogin(weibocc, proxy);
                if (isLogin)
                {
                    //登录成功保存Cookie
                    File.AppendAllText("weibocookie/" + username + ".txt", loginData.cookies);
                    return(weibocc);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        public static string AutoGetVcode(CookieContainer weibocc)
        {
            string m_softKey  = "365bd32d7ca2b5f07bc8328520542d9c";
            string m_userName = "******";
            string m_password = "******";
            //打码平台自动获取验证码
            string     imgPath = WeiboHandler.GetVcodePic(weibocc);
            FileInfo   fi      = new FileInfo(imgPath);
            FileStream fs      = new FileStream(imgPath, FileMode.Open);

            byte[] ba   = new byte[fi.Length];
            int    nRet = fs.Read(ba, 0, (int)fi.Length);

            if (nRet == 0)
            {
                return("");
            }

            //请求答题
            StringBuilder VCodeText = new StringBuilder(100);
            int           ret       = Dama2.D2Buf(
                m_softKey,  //softawre key (software id)
                m_userName, //user name
                m_password, //password
                ba,         //图片数据,图片数据不可大于4M
                (uint)nRet, //图片数据长度
                60,         //超时时间,单位为秒,更换为实际需要的超时时间
                200,        //验证码类型ID,参见 http://wiki.dama2.com/index.php?n=ApiDoc.GetSoftIDandKEY
                VCodeText); //成功时返回验证码文本(答案)

            if (ret > 0)
            {
                uint ulVCodeID = (uint)ret;
                return(VCodeText.ToString());;
            }
            return(VCodeText.ToString());
        }
Exemple #4
0
        /// <summary>
        /// 微博登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static CookieContainer Login(string username, string password)
        {
            var             preData = WeiboHandler.PreLogin(username);
            CookieContainer weibocc = new CookieContainer();

            if (preData != null)
            {
                string code = "";
                var    img  = WeiboHandler.GetLoginCodePic(preData.pcid);
                while (code == "" || code == "IERROR" || code == "ERROR")
                {
                    code = Dama2.GetVcode(img);
                }
                //string code = null;
                //var img = WeiboHandler.GetLoginCodePic(preData.pcid);
                var loginData = WeiboHandler.Login(preData, username, password, code);
                weibocc = WeiboHandler.InitWeiboCookie(username, loginData.cookies);
                string testloginresult = "";
                bool   isLogin         = WeiboHandler.TestLogin(weibocc, ref testloginresult);

                if (isLogin)
                {
                    CookieCollection ccl    = weibocc.GetCookies(new Uri("http://weibo.com"));
                    CookieCollection newccl = ccl;
                    for (int i = 0; i < newccl.Count; i++)
                    {
                        newccl[i].Domain = "sina.com.cn";
                    }
                    CookieContainer newcc = new CookieContainer();
                    weibocc.Add(new Uri("http://sina.com.cn"), newccl);


                    string ssourl1    = "http://login.sina.com.cn/sso/login.php?url=http%3A%2F%2Fm.weibo.cn%2F&_rand=" + HttpHelper1.GetTicks() + ".3493&gateway=1&service=sinawap&entry=sinawap&useticket=1&returntype=META&sudaref=&_client_version=0.6.23";
                    string ssoresult1 = HttpHelper1.SendDataByGET(ssourl1, ref weibocc);
                    string ssourl2    = "";
                    HttpHelper1.GetStringInTwoKeyword(ssoresult1, ref ssourl2, "arrURL\":[\"", "\"]", 0);
                    ssourl2 = ssourl2.Replace(@"\/", "/");
                    ssourl2 = ssourl2 + "&callback=sinaSSOController.doCrossDomainCallBack&scriptId=ssoscript0&client=ssologin.js(v1.4.19)&_=" + HttpHelper1.GetTicks();
                    string ssoresult2 = HttpHelper1.SendDataByGET(ssourl2, ref weibocc);

                    ccl    = weibocc.GetCookies(new Uri("http://sina.com.cn"));
                    newccl = ccl;
                    for (int i = 0; i < newccl.Count; i++)
                    {
                        newccl[i].Domain = "weibo.cn";
                    }
                    newcc = new CookieContainer();
                    weibocc.Add(new Uri("http://weibo.cn"), newccl);

                    //登录成功保存Cookie
                    File.AppendAllText("weibocookie/" + username + ".txt", loginData.cookies);
                    return(weibocc);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }