/// <summary>
        /// 识别验证码
        /// </summary>
        void HandleCaptcha(Carapplyarr carinfo)
        {
            LogWrapper.LogInfo("正在获取验证码...");
            State = RunState.WaitingNet;
            api.GetCaptcha((result, ex) => {
                if (result != null && result is Image)
                {
                    try {
                        LogWrapper.LogInfo("获取验证码成功,正在识别中...");
                        var img         = result as Image;
                        MemoryStream ms = new MemoryStream();
                        img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                        var bytes = ms.GetBuffer();
                        ms.Close();

                        string str           = NetRecognizePic.CJY_RecognizeBytes(bytes, bytes.Length, mConfig.CJYUsername, Utils.MD5String(mConfig.CJYPassword), "96001", "1104", "0", "0", "");
                        JObject recognizeRet = JObject.Parse(str);

                        string err_no  = recognizeRet["err_no"].ToString();
                        string err_str = recognizeRet["err_str"].ToString();
                        if (err_no == "0")
                        {
                            string pic_id  = recognizeRet["pic_id"].ToString();
                            string pic_str = recognizeRet["pic_str"].ToString();
                            img.Save("./code_" + pic_str + "_" + pic_id + ".jpeg");
                            img.Dispose();
                            LogWrapper.LogInfo("验证码识别成功:" + pic_str);
                            HandleSubmitpaper(carinfo, pic_str, pic_id);
                        }
                        else
                        {
                            LogWrapper.LogInfo("验证码识别失败:" + err_str);
                        }
                    } catch (Exception e) {
                        LogWrapper.LogInfo("识别验证码时,发生异常:" + e.ToString());
                    }

                    State = RunState.Waiting;
                }
                else
                {
                    LogWrapper.LogInfo("获取验证码失败:" + ex != null ? ex.Message : "验证码图片无效.");
                    State = RunState.Captcha;
                }
            });
        }
Beispiel #2
0
    private static string BaseInvoiceValideCodeOrc(WebClient wc, string url)
    {
        Stream       stream = null;
        MemoryStream ms     = null;

        byte[] bytes       = null;
        int    bytesConter = 0;

        try
        {
            stream = wc.OpenRead(url);
            ms     = new MemoryStream();
            bytes  = new byte[4096];
            int actual = stream.Read(bytes, 0, bytes.Length);
            if (actual > 0)
            {
                ms.Write(bytes, 0, actual);
                bytesConter += actual;
            }
            ms.Position = 0;
        }
        catch (Exception e)
        {
        }
        finally
        {
            ms.Close();
            stream.Close();
        }
        string user       = "******";
        string psw        = NetRecognizePic.MD5String("y123456");
        string lpSoftId   = "96001";
        string lpCodeType = "1902";

        string str    = NetRecognizePic.CJY_RecognizeBytes(bytes, bytesConter, user, psw, lpSoftId, lpCodeType, "0", "0", "");
        string strerr = GetTextByKey(str, "err_str");

        if (strerr != "OK")
        {
            return(strerr);
        }
        else
        {
            return(GetTextByKey(str, "pic_str"));
        }
    }
Beispiel #3
0
    private string JxHandWritingValideCodeOrc(string randomT, WebClient wc)
    {
        string       url    = "http://117.40.128.134:7002/fpcx//Validate?t=" + randomT;
        Stream       stream = null;
        MemoryStream ms     = null;

        byte[] bytes       = null;
        int    bytesConter = 0;

        try
        {
            //var wc = new WebClient { Encoding = Encoding.UTF8 };
            //wc.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
            stream = wc.OpenRead(url);
            ms     = new MemoryStream();
            bytes  = new byte[4096];
            int actual = stream.Read(bytes, 0, bytes.Length);
            if (actual > 0)
            {
                ms.Write(bytes, 0, actual);
                bytesConter += actual;
            }
            ms.Position = 0;
        }
        catch (Exception e)
        {
            throw e;
        }
        //try
        //{
        //    WebRequest req = WebRequest.Create(url);
        //    stream = req.GetResponse().GetResponseStream();
        //    ms = new MemoryStream();
        //    //using (var ms = new MemoryStream())
        //    //{
        //    //    await stream..CopyToAsync(ms);
        //    //    //...
        //    //}
        //    bytes = new byte[4096];
        //    int actual = stream.Read(bytes, 0, bytes.Length);
        //    if (actual > 0)
        //    {
        //        ms.Write(bytes, 0, actual);
        //        bytesConter += actual;
        //    }
        //    ms.Position = 0;
        //    //stream.Read(bytes, 0, (int)stream.Length);
        //}
        finally
        {
            ms.Close();
            stream.Close();
        }
        string user       = "******";
        string psw        = NetRecognizePic.MD5String("y123456");
        string lpSoftId   = "96001";
        string lpCodeType = "1004";

        string str    = NetRecognizePic.CJY_RecognizeBytes(bytes, bytesConter, user, psw, lpSoftId, lpCodeType, "0", "0", "");
        string strerr = GetTextByKey(str, "err_str");

        if (strerr != "OK")
        {
            //this.richTextBox1.Text += "[" + DateTime.Now.ToString("HH:mm:ss") + "]" + strerr + "\r\n";
            //MessageBox.Show(strerr);
            return(strerr);
        }
        else
        {
            return(GetTextByKey(str, "pic_str"));
        }
        //string strpic_id = GetTextByKey(str, "pic_id");
        //this.txtPicID.Text = strpic_id;

        //string strpic_str = GetTextByKey(str, "pic_str");
        //this.txtshibie.Text = strpic_str;


        //this.richTextBox1.Text += "[" + DateTime.Now.ToString("HH:mm:ss") + "]识别结果:" + strpic_str + "\r\n";
    }