コード例 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            var img    = ImageIO.ReadFile("test1.jpg");
            var imgStr = ImageToString.ToBase64String(img, ImageFormat.Jpeg);

            imgStr = HttpUtility.UrlEncode(imgStr);
            var words = BaiduOcr.GetResult(imgStr);
        }
コード例 #2
0
 //开始
 private void btnStart_Click(object sender, EventArgs e)
 {
     btnSend.Enabled = false;
     ThreadPool.QueueUserWorkItem(new WaitCallback(
                                      (m) =>
     {
         for (int i = 0; i < retryTime; i++)
         {
             try
             {
                 Log($"正在进行第{i + 1}次尝试,共{retryTime}次");
                 var html         = booker.RequestIndexPage();
                 string timestamp = Utils.GetHtmlTimestamp(html);
                 Log($"获取首页成功,md5加密用时间戳为{timestamp}");
                 var imageBase64 = booker.RequestCaptchaImg();
                 var img         = Utils.Base64ToImage(imageBase64);
                 var ocr         = string.Empty;
                 try
                 {
                     ocr = BaiduOcr.GetOcrResult(imageBase64, booker.OCRConfig);
                 }
                 catch (Exception baiduException)
                 {
                     Log("百度api调用失败");
                 }
                 this.BeginInvoke(new Action(
                                      () =>
                 {
                     this.pbxImg.Image = img;
                     tbxCaptcha.Text   = ocr;
                 }
                                      ));
                 countDown();
                 var stocksStr = booker.RequestMaskStock();
                 Log(stocksStr);
                 List <StockInfo> stocks = booker.ConvertJsonToStock(stocksStr);
                 if (stocks == null)
                 {
                     return;
                 }
                 booker.UserInfo.Captcha = tbxCaptcha.Text;
                 var response            = booker.PostPurchaseInfo(stocks, timestamp);
                 Log(response);
             }
             catch (Exception ex)
             {
                 Log(ex.Message);
             }
         }
         this.BeginInvoke(new Action(
                              () =>
         {
             btnSend.Enabled = true;
         }
                              ));
     }
                                      ));
 }