Google ReCaptcha答案 [英] Google ReCaptcha Answer
本文介绍了Google ReCaptcha答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有用于从谷歌创建recaptcha图像的代码:
I have that code for creating a recaptcha image from google:
public Image CreateRecaptcha(string key, ref string challenge)
{
try
{
WebClient client = new WebClient();
string response = client.DownloadString(string.Format("http://api.recaptcha.net/challenge?k={0}", key));
Match match = Regex.Match(response, "challenge : '(.+?)'");
if (match.Captures.Count == 0)
{
challenge = null;
return null;
}
challenge = match.Groups[1].Value;
if (File.Exists("captcha.jpg")) File.Delete("captcha.jpg");
client.DownloadFile(string.Format("http://www.google.com/recaptcha/api/image?c={0}", challenge),
"captcha.jpg");
Thread.Sleep(150);
return Image.FromFile("captcha.jpg");
}
catch (Exception)
{
challenge = null;
return null;
}
}
工作正常,我得到图像。
我唯一需要的是获取字符串图像的答案(出现在其上的文字)。
有人可以帮助我从这种方法中得到答案吗?
b $ b我认为这与'挑战'有关和'关键',但我无法找到该怎么做。
It is working fine and I get the image.
The only thing I need is to get the string with the answer for the image (the text that appears on it).
Can someone help me getting the answer from that method?
I believe it's related to the 'challenge' and 'key' but I just couldn't find what to do with it.
推荐答案
虽然
以下适用于ASP.NET,您仍然可以从中学习。
Although the following is for ASP.NET you can still learn from it.
using Newtonsoft.Json;
public class ReCaptchaClass
{
public static string Validate(string EncodedResponse)
{
var client = new System.Net.WebClient();
string PrivateKey = "6LcH-v8SerfgAPlLLffghrITSL9xM7XLrz8aeory";
var GoogleReply = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", PrivateKey, EncodedResponse));
var captchaResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<ReCaptchaClass>(GoogleReply);
return captchaResponse.Success;
}
[JsonProperty("success")]
public string Success
{
get { return m_Success; }
set { m_Success = value; }
}
private string m_Success;
[JsonProperty("error-codes")]
public List<string> ErrorCodes
{
get { return m_ErrorCodes; }
set { m_ErrorCodes = value; }
}
private List<string> m_ErrorCodes;
}
这篇关于Google ReCaptcha答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文