Beispiel #1
0
        public static Image GetVcImage(string vcUrl, ref string code, ref CookieContainer vcCookie, string token = "")
        {
            //Image vcImage = null;
            Image vcImage      = null;
            bool  continueFlag = true;

            do
            {
                try
                {
                    HttpClient client = new HttpClient(vcCookie);
                    if (StaticValues.Proxy != "")
                    {
                        client.Proxy = new WebProxy(StaticValues.Proxy);
                    }
                    Stream stream = client.GetImageStream(vcUrl);
                    if (stream != null)
                    {
                        vcImage = Image.FromStream(stream);
                        code    = ImageRealize.GetCode0(vcImage);
                        bool ocrFlag = CheckVc(vcCookie, code, token);
                        code         = ocrFlag ? code : "";
                        continueFlag = !ocrFlag && StaticValues.UserOcr;
                        //else
                        //{
                        //    break;
                        //}
                        //gif验证码
                        //FrameDimension fd = new FrameDimension(gif.FrameDimensionsList[0]);
                        //int count = gif.GetFrameCount(fd);
                        ////if (count == 6)
                        ////{
                        ////    gif.SelectActiveFrame(fd, 4);
                        ////    MemoryStream ms = new MemoryStream();
                        ////    gif.Save(ms, ImageFormat.Bmp);
                        ////    Image img1 = Image.FromStream(ms);
                        ////    picCommon.Image = img1;
                        ////}
                        //if (count == 1)
                        //{
                        //     code = ImageRealize.GetCode0(gif);
                        //     if (CheckVc(vcCookie, code, token))
                        //     {
                        //         break;
                        //     }
                        //}
                        //code = ImageRealize.GetCode(vcImage);
                        //if (CheckVc(vcCookie, code, token))
                        //{
                        //    break;
                        //}
                    }
                }
                catch
                {
                    break;
                }
            }while (continueFlag);
            return(vcImage);
        }
Beispiel #2
0
        /// <summary>
        /// 获取验证码,并且识别
        /// </summary>
        /// <param name="yzmUrl"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        private static string GetVcImage0(byte[] ret, Image img)
        {
            string        code        = string.Empty;
            StringBuilder codeBuilder = new StringBuilder(8, 8);

            codeBuilder.Length = 0;
            if (ret.Length > 0)
            {
                if (CodeAPI.GetCodeFromBuffer(1, ret, ret.Length, codeBuilder))
                {
                    code = codeBuilder.ToString().ToUpper();
                }
                if (code.Length == 4)
                {
                    code = code.Replace("V", "N").Replace("B", "8");
                }
                else
                {
                    code = ImageRealize.GetCode1(img);
                }
            }
            return(code);
        }
Beispiel #3
0
        /// <summary>
        /// 获取验证码,并且识别
        /// </summary>
        /// <param name="vcUrl"></param>
        /// <param name="code"></param>
        /// <param name="vcCookie"></param>
        /// <returns></returns>
        private static string GetVcImage1(Image vcImage)
        {
            string code = ImageRealize.GetCode0(vcImage);

            return(code);
        }
Beispiel #4
0
        public static Image GetVcImage(string vcUrl, ref string code, ref CookieContainer vcCookie, string token = "")
        {
            //Image vcImage = null;
            Image vcImage      = null;
            bool  continueFlag = true;

            do
            {
                try
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    HttpClient client = new HttpClient(vcCookie);
                    if (StaticValues.Proxy != "")
                    {
                        client.Proxy = new WebProxy(StaticValues.Proxy);
                    }
                    Stream stream = client.GetImageStream(vcUrl);
                    sw.Stop();
                    if (stream != null)
                    {
                        vcImage = Image.FromStream(stream);
                        if (sw.ElapsedMilliseconds > 2000)
                        {
                            //continueFlag = false;
                        }
                        else
                        {
                            if (vcImage.Width == 78)
                            {
                                code = ImageRealize.GetCode0(vcImage);
                            }
                            else
                            {
                                code = ImageRealize.GetCode1(vcImage);
                            }
                            if (CheckVc(vcCookie, code, token))
                            {
                                break;
                            }
                            else
                            {
                                code = "";
                            }
                        }
                        //else
                        //{
                        //    break;
                        //}
                        //gif验证码
                        //FrameDimension fd = new FrameDimension(gif.FrameDimensionsList[0]);
                        //int count = gif.GetFrameCount(fd);
                        ////if (count == 6)
                        ////{
                        ////    gif.SelectActiveFrame(fd, 4);
                        ////    MemoryStream ms = new MemoryStream();
                        ////    gif.Save(ms, ImageFormat.Bmp);
                        ////    Image img1 = Image.FromStream(ms);
                        ////    picCommon.Image = img1;
                        ////}
                        //if (count == 1)
                        //{
                        //     code = ImageRealize.GetCode0(gif);
                        //     if (CheckVc(vcCookie, code, token))
                        //     {
                        //         break;
                        //     }
                        //}
                        //code = ImageRealize.GetCode(vcImage);
                        //if (CheckVc(vcCookie, code, token))
                        //{
                        //    break;
                        //}
                    }
                }
                catch
                {
                    break;
                }
            }while (continueFlag);
            return(vcImage);
        }