예제 #1
0
파일: Form1.cs 프로젝트: tracyhatemice/Sipo
        private void button1_Click(object sender, EventArgs e)
        {
            HttpHelper hh = new HttpHelper();

            hh.GetHtmlData(MainUrl, cookie);           //获取cookie
            hh.DowloadCheckImg(codeUrl, cookie, path); //下载验证码

            if (File.Exists(path + "yzm.jpg"))
            {
                Bitmap bmp = new Bitmap(path + "yzm.jpg");

                vfc = new VerifyCode(bmp);
                vfc.ClearPicBorder(3);                                 //去图形边框
                vfc.GrayByPixels();                                    //灰度处理
                vfc.ClearNoise(128, 1);                                //清除噪点
                vfc.GrayByPixels();                                    //灰度处理
                vfc.BitmapTo1Bpp(1);                                   //二值化
                vfc.GetPicValidByValue(128, 4);                        //得到有效空间
                Bitmap[] pics     = vfc.GetSplitPics(4, 1);            //分割
                int      verycode = Calculate(pics);                   //计算验证码的结果

                long   longTime  = ConvertDateTimeToInt(DateTime.Now); //当前时间戳
                string shenqingh = "2017302262484";
                string data      = "select-key:shenqingh=" + shenqingh + "&select-key:zhuanlimc=&select-key:shenqingrxm=&select-key:zhuanlilx=&select-key:shenqingr_from=&select-key:shenqingr_to=&verycode=" + verycode + "&inner-flag:open-type=window&inner-flag:flowno=" + longTime + "";

                string retString = hh.SendDataByGET(MainUrl, data, ref cookie);
                if (retString.Contains("申请信息"))
                {
                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(retString);
                    HtmlNode node  = doc.DocumentNode.SelectSingleNode(("//input[@id='sq_token']"));
                    string   token = node.GetAttributeValue("value", "");
                    longTime = ConvertDateTimeToInt(DateTime.Now);//当前时间戳
                    string backPage = LastUrl + "?" + data;

                    string lastData   = "select-key:shenqingh=" + shenqingh + "&select-key:backPage=" + backPage + "&token=" + token + "&inner-flag:open-type=window&inner-flag:flowno = " + longTime + "";
                    string qwe        = LastUrl + "?" + lastData;
                    string lastResult = hh.SendDataByGET(LastUrl, lastData, ref cookie);
                    if (lastResult.Contains("案件状态"))
                    {
                        HtmlAgilityPack.HtmlDocument lastDoc = new HtmlAgilityPack.HtmlDocument();
                        doc.LoadHtml(lastResult);
                        HtmlNode lastNode   = doc.DocumentNode.SelectSingleNode(("//span[@name='record_zlx:anjianywzt']/span"));
                        string   statusCase = lastNode.InnerHtml;
                        MessageBox.Show(statusCase);
                    }
                }
            }
            else
            {
                MessageBox.Show("验证码不存在根目录!");
            }
        }
예제 #2
0
        /// <summary>
        /// 执行任务
        /// </summary>
        public string DoTask(string shenqingh)
        {
            string state    = "请求超时!";
            int    verycode = 0;
            int    f        = 0;

            try
            {
                while (true)
                {
                    Bitmap     bmp = null;
                    HttpHelper hh  = new HttpHelper("183.30.204.174", 9999);
                    hh.GetHtmlData(MainUrl, cookie);           //获取cookie
                    hh.DowloadCheckImg(codeUrl, cookie, path); //下载验证码

                    if (File.Exists(path + "yzm.jpg"))
                    {
                        try
                        {
                            bmp = new Bitmap(path + "yzm.jpg");

                            vfc = new VerifyCode(bmp);
                            vfc.ClearPicBorder(3);                  //去图形边框
                            vfc.GrayByPixels();                     //灰度处理
                            vfc.ClearNoise(128, 1);                 //清除噪点
                            vfc.GrayByPixels();                     //灰度处理
                            vfc.BitmapTo1Bpp(1);                    //二值化
                            vfc.GetPicValidByValue(128, 4);         //得到有效空间
                            Bitmap[] pics = vfc.GetSplitPics(4, 1); //分割
                            verycode = Calculate(pics);             //计算验证码的结果
                        }
                        catch (Exception ex)
                        {
                            WriteLog("网络异常,验证码请求失败!");
                        }
                        finally
                        {
                            vfc.bmpobj.Dispose();
                            bmp.Dispose();
                        }
                        string data = "select-key:shenqingh=" + shenqingh + "&select-key:zhuanlimc=&select-key:shenqingrxm=&select-key:zhuanlilx=&select-key:shenqingr_from=&select-key:shenqingr_to=&verycode=" + verycode + "&inner-flag:open-type=window&inner-flag:flowno=" + ConvertDateTimeToInt() + "";

                        string retString = hh.SendDataByGET(queryurl, data, ref cookie);
                        if (retString.Contains("申请信息"))
                        {
                            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                            doc.LoadHtml(retString);
                            HtmlNode node     = doc.DocumentNode.SelectSingleNode(("//input[@id='sq_token']"));
                            string   token    = node.GetAttributeValue("value", "");
                            string   backPage = LastUrl + "?" + data;

                            string lastData   = "select-key:shenqingh=" + shenqingh + "&select-key:backPage=" + backPage + "&token=" + token + "&inner-flag:open-type=window&inner-flag:flowno = " + ConvertDateTimeToInt() + "";
                            string qwe        = LastUrl + "?" + lastData;
                            string lastResult = hh.SendDataByGET(LastUrl, lastData, ref cookie);
                            if (lastResult.Contains("案件状态"))
                            {
                                HtmlAgilityPack.HtmlDocument lastDoc = new HtmlAgilityPack.HtmlDocument();
                                doc.LoadHtml(lastResult);
                                HtmlNodeCollection spanNodes = doc.DocumentNode.SelectNodes("//span[@name='record_zlx:anjianywzt']/span[@class='nlkfqirnlfjerldfgzxcyiuro']");
                                int           length         = spanNodes.Count;
                                List <string> spanlist       = new List <string>();
                                foreach (var sn in spanNodes)
                                {
                                    spanlist.Add(sn.InnerHtml);
                                }
                                List <string> newList       = spanlist.Distinct().ToList();
                                string        confusedState = string.Empty;
                                foreach (var item in newList)
                                {
                                    confusedState += item.ToString();
                                }
                                state = StateMatching(confusedState);
                            }
                        }
                    }
                    else
                    {
                        WriteLog("验证码不存在根目录!");
                    }
                    if (state == "请求超时!" && f < 5)
                    {
                        WriteLog("专利号[" + shenqingh + "] 请求失败,6秒后重新请求.");
                        Thread.Sleep(1000 * 6);
                        f++;
                        continue;
                    }
                    else
                    {
                        return(state);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog("网络异常,请求失败!");
            }
            return(state);
        }