Beispiel #1
0
        /// <summary>
        /// 验证码识别
        /// </summary>
        /// <param name="url"></param>
        /// <param name="cookie"></param>
        /// <param name="codeType"></param>
        /// <param name="code"></param>
        /// <param name="codeId"></param>
        /// <returns></returns>
        public static bool GetCodeByByte_UU(string url, ref CookieContainer cookie, int codeType, ref string code, ref int codeId)
        {
            try
            {
                #region 获取验证码

                Image image = ByteHelper.byteArrayToImage(PostAndGet.HttpGetByte(url, "", ref cookie));

                #endregion

                #region 保存图片
                //判断保存图片的文件夹是否存在,若不存在则创建
                //string filepath = System.Windows.Forms.Application.StartupPath + @"\37";

                //if (!Directory.Exists(filepath))
                //{
                //    Directory.CreateDirectory(filepath);
                //}

                //Bitmap bmp1 = new Bitmap(image);
                //MemoryStream bmpStream1 = new MemoryStream();
                //bmp1.Save(bmpStream1, System.Drawing.Imaging.ImageFormat.Jpeg);
                //string BmpPath = filepath + "\\" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
                //FileStream fs = new FileStream(BmpPath, FileMode.Create);
                //bmpStream1.WriteTo(fs);
                //bmpStream1.Close();
                //fs.Close();
                //bmpStream1.Dispose();
                //fs.Dispose();
                #endregion

                #region 把图片转换为字节流
                //判断保存图片的文件夹是否存在,若不存在则创建

                Bitmap       bmp       = new Bitmap(image);
                MemoryStream bmpStream = new MemoryStream();

                MemoryStream ms = new MemoryStream();
                bmp.Save(ms, ImageFormat.Jpeg);
                byte[] buffer = new byte[ms.Length];
                ms.Position = 0;
                ms.Read(buffer, 0, buffer.Length);
                ms.Flush();

                #endregion

                #region 调用优优云打码
                StringBuilder strResult = new StringBuilder(50);
                codeId = Wrapper.uu_recognizeByCodeTypeAndBytes(buffer, buffer.Length, codeType, strResult);
                code   = CheckResult(strResult.ToString(), Convert.ToInt32(strSoftID), codeId, strCheckKey);

                #endregion

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }