Example #1
0
        public static string GetCouponInfo(string resulthtml, string itemurl, CookieContainer alimamacc, ref string tbkshortlink)
        {
            string pv_id = "";

            HttpHelper1.GetStringInTwoKeyword(resulthtml, ref pv_id, "pvid\":\"", "\",\"", 0);
            string itemid = "";

            HttpHelper1.GetStringInTwoKeyword(resulthtml, ref itemid, "auctionId\":", ",\"", 0);
            CookieCollection ccl            = alimamacc.GetCookies(new Uri("http://alimama.com"));
            string           tbtoken        = ccl["_tb_token_"].Value;
            DEWeiboAccount   deweiboaccount = WeiboHandler.GetOneAccount();

            //高佣搜索,先查看是否有高佣商品链接
            string url    = "http://pub.alimama.com/common/code/getAuctionCode.json?auctionid=" + itemid + "&adzoneid=" + deweiboaccount.Adzoneid + "&siteid=" + deweiboaccount.Siteid + "&scenes=3&channel=tk_qqhd&t=" + HttpHelper1.GetTicks() + "&_tb_token_=" + tbtoken + "&pvid=" + pv_id;
            string result = HttpHelper1.SendDataByGET(url, ref alimamacc);

            if (result.Contains("参数错误"))
            {
                url    = "http://pub.alimama.com/common/code/getAuctionCode.json?auctionid=" + itemid + "&adzoneid=" + deweiboaccount.Adzoneid + "&siteid=" + deweiboaccount.Siteid + "&scenes=1&t=" + HttpHelper1.GetTicks() + "&_tb_token_=" + tbtoken + "&pvid=" + pv_id + "&yxjh=-1";
                result = HttpHelper1.SendDataByGET(url, ref alimamacc);
            }
            //正常搜索

            string shorturl = "";

            HttpHelper1.GetStringInTwoKeyword(result, ref shorturl, "couponShortLinkUrl\":\"", "\",\"qrCodeUrl", 0);
            HttpHelper1.GetStringInTwoKeyword(result, ref tbkshortlink, "shortLinkUrl\":\"", "\"", 0);

            return(shorturl);
        }
Example #2
0
        public static string Comment(string mid, string ouid, string commentstr, string refer, CookieContainer weibocc, WebProxy proxy)
        {
            string commenturl = "http://weibo.com/aj/v6/comment/add?ajwvr=6&__rnd=" + HttpHelper1.GetTicks();

            commentstr = System.Web.HttpUtility.UrlEncode(commentstr.Trim());
            commentstr = commentstr.Trim().Replace("+", "%20");

            string commentpoststr = "act=post&mid=" + mid + "&uid=" + ouid + "&forward=0&isroot=0&content=" + commentstr + "&location=&module=scommlist&group_source=&pdetail=&_t=0";
            string commentresult  = HttpHelper1.SendDataByPost(commenturl, commentpoststr, refer, ref weibocc, proxy);

            if (commentresult.Contains("{\"code\":\"100001\""))
            {
                //Thread.Sleep(10 * 60 * 1000);//如果第一次评论就提示发布相同内容,则将线程停顿10分钟
                return(commentresult);//如果第一次评论就报错,一般认为是mid为空,直接返回不处理
            }

            if (commentresult.Contains("{\"code\":\"100027\""))
            {
                //需要输入验证码
                string retcode = "";
                string vcode   = "";

                while (retcode == "")
                {
                    while (vcode == "" || vcode == "IERROR" || vcode == "ERROR")
                    {
                        vcode = HttpHelper1.AutoGetVcode(weibocc);
                    }
                    retcode = WeiboHandler.GetVcodeRetcode(vcode, refer, weibocc);
                    if (retcode == "")
                    {
                        vcode = "";
                    }
                }//拿到验证码,并验证通过,通不过死循环

                commentpoststr = commentpoststr + "&retcode=" + retcode;
                commentresult  = HttpHelper1.SendDataByPost(commenturl, commentpoststr, refer, ref weibocc, proxy);//再次发送评论
            }
            return(commentresult);
        }
Example #3
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);
            }
        }
Example #4
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());
        }
Example #5
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);
            }
        }