C#使用第三方API识别图片验证码案例

现在的网站图片验证码简直是无处不在,但是有第三方接口的话,做这种图片验证码识别的小demo是非常简单的,只需要处理接口返回的数据即可,最终效果图如下(Winform):

具体代码:

 

转载留出处
        /// <summary>
        /// 第三方接口验证账号密码是否正确
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rklogin_btn_Click(object sender, EventArgs e)
        {
            string userName = rkname_text.Text;
            string passWord = rkpwd_text.Text;
            string responseStr = HttpPost("http://api.ruokuai.com/info.json", "username=" + userName + "&password=" + passWord + "") + "\r\n";
            JObject responseJson = (JObject)JsonConvert.DeserializeObject(responseStr);
            if (responseJson.Count == 4)
            {
                messages_text.Text += "登录成功!剩余若快点数:" + responseJson["Score"].ToString() + "\r\n";
            }
            else
            {
                messages_text.Text += "登录失败!" + responseJson["Error"].ToString() + "\r\n";
            }
        }
        /// <summary>
        /// 识别图片验证码并返回结果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void sbyzm_btn_Click(object sender, EventArgs e)
        {
            string userName = rkname_text.Text;
            string passWord = rkpwd_text.Text;
            string yzmUrl = tpyzmUrl_text.Text;
            messages_text.Text += "正在识别图片验证码,请稍等!\r\n";
            string responseStr = HttpPost("http://api.ruokuai.com/create.json", "username=" + userName + "&password=" + passWord + "&typeid=3000&timeout=60&softid=1&softkey=21asd5as1d56as1d521asd2asd165as1d52&imageurl=" + yzmUrl);
            JObject responseJson = (JObject)JsonConvert.DeserializeObject(responseStr);
            if (responseJson.Count == 2)
            {
                messages_text.Text += "识别结果:" + responseJson["Result"].ToString() + "\r\n";
                yzmretrun_text.Text = responseJson["Result"].ToString();
            }
            else
            {
                messages_text.Text += "识别失败!" + responseJson["Error"].ToString() + "\r\n";
            }
        }
转载留出处

代码中用到的HttpPost、HttpGet方法,请移步上一篇博客,该案例使用的是若快打码平台,上述为原创代码,转载请留出处,Thanks♪(・ω・)ノ!

THE END