Exemple #1
0
        /// <summary>
        /// 对于出现验证码,识别验证码,输入验证码解封
        /// </summary>
        /// <returns></returns>
        public bool UnLock(bool isOCR)
        {
            logger.Debug("vcode appear, use UnLock()");
            string codeurl = "http://weixin.sogou.com/antispider/util/seccode.php?tc=" + DateTime.Now.Ticks;
            //codeurl = 'http://weixin.sogou.com/antispider/util/seccode.php?tc=' + str(time.time())[0:10]
            HttpHelper          netHelper = new HttpHelper();
            WebHeaderCollection headers   = new WebHeaderCollection();
            var content = netHelper.Get(headers, codeurl);

            //异步显示验证码
            ShowImageHandle showImageHandle = new ShowImageHandle(DisplayImageFromBase64);

            showImageHandle.BeginInvoke(content, null, null);

            if (isOCR)
            {
            }
            else
            {
            }



            Console.WriteLine("请输入验证码:");
            string verifyCode = Console.ReadLine();
            string postURL    = "http://weixin.sogou.com/antispider/thank.php";
            string postData   = string.Format("{'c': {0}, 'r': {1}, 'v': 5 }", verifyCode, this._vcode_url);
            Random r          = new Random();
            int    index      = r.Next(WechatSogouBasic._agent.Count - 1);

            headers.Add("User-Agent", WechatSogouBasic._agent[index]);
            headers.Add("Referer", "http://weixin.sogou.com/antispider/?from=%2" + this._vcode_url.Replace("http://", ""));
            headers.Add("Host", "weixin.sogou.com");
            string  remsg     = netHelper.PostJson(postURL, headers, postData);
            JObject jo        = JObject.Parse(remsg);//把json字符串转化为json对象
            int     satuscode = (int)jo.GetValue("code");

            if (satuscode < 0)
            {
                logger.Error("cannot unblock because " + jo.GetValue("msg"));
                var vcodeException = new WechatSogouVcodeException();
                vcodeException.MoreInfo = "cannot jiefeng because " + jo.GetValue("msg");
                throw vcodeException;
            }
            else
            {
                //this._cache.set(Config.CacheDir, "", 500);
                Console.WriteLine("ocr");
                return(true);
            }
        }
Exemple #2
0
        /// <summary>
        /// 页面出现验证码,输入才能继续,此验证依赖cookie, 获取验证码的requset有个cookie,每次不同,需要在post验证码的时候带上
        /// </summary>
        /// <returns></returns>
        public bool VerifyCodeForContinute(string url, bool isUseOCR)
        {
            bool isSuccess = false;

            logger.Debug("vcode appear, use VerifyCodeForContinute()");
            DateTime            Epoch           = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            var                 timeStamp17     = (DateTime.UtcNow - Epoch).TotalMilliseconds.ToString("R"); //get timestamp with 17 bit
            string              codeurl         = "https://mp.weixin.qq.com/mp/verifycode?cert=" + timeStamp17;
            WebHeaderCollection headers         = new WebHeaderCollection();
            var                 content         = this.Get(headers, codeurl, "UTF-8", true);
            ShowImageHandle     showImageHandle = new ShowImageHandle(DisplayImageFromBase64);

            showImageHandle.BeginInvoke(content, null, null);
            Console.WriteLine("请输入验证码:");
            string verifyCode = Console.ReadLine();
            string postURL    = "https://mp.weixin.qq.com/mp/verifycode";

            timeStamp17 = (DateTime.UtcNow - Epoch).TotalMilliseconds.ToString("R");        //get timestamp with 17 bit
            string postData = string.Format("cert={0}&input={1}", timeStamp17, verifyCode); // "{" + string.Format(@"'cert':'{0}','input':'{1}'", timeStamp17, verifyCode) + "}";

            headers.Add("Host", "mp.weixin.qq.com");
            headers.Add("Referer", url);
            string remsg = this.Post(postURL, headers, postData, true);

            try
            {
                JObject jo         = JObject.Parse(remsg);//把json字符串转化为json对象
                int     statusCode = (int)jo.GetValue("ret");

                if (statusCode == 0)
                {
                    isSuccess = true;
                }
                else
                {
                    logger.Error("cannot unblock because " + jo.GetValue("msg"));
                    var vcodeException = new WechatSogouVcodeException();
                    vcodeException.MoreInfo = "cannot jiefeng because " + jo.GetValue("msg");
                    throw vcodeException;
                }
            }catch (Exception e)
            {
                logger.Error(e);
            }


            return(isSuccess);
        }