我们将为我们的站点应用Recaptcha V3。但是Kentico仅支持V2。
那么有什么文件或指南吗?
还是我们应该继续使用V2?
谢谢, 杜克·休恩
答案 0 :(得分:0)
我通过构建自定义代码来呈现V3验证码来解决了这个问题。
然后,我将在保存表单之前检查reCaptcha代码。
答案 1 :(得分:0)
步骤如下:
您可以通过 Ajax 使用它或直接提交。
public static GooogleRecaptchaResponse ValidateGgRecaptchaToken(string responseToken, Action InvalidHandler) {
if (string.IsNullOrEmpty(responseToken)) {
EventLogProvider.LogInformation("ValidateGgRecaptchaToken", "Invalid", "Recaptcha was empty");
InvalidHandler?.Invoke();
return null;
}
string secretKey = SettingsKeyInfoProvider.GetValue(WebUtils.CaptchaSecretKeyName);
var request = (HttpWebRequest) WebRequest.Create("https://www.google.com/recaptcha/api/siteverify");
var postData = "response=" + responseToken;
postData += "&secret=" + secretKey;
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using(var stream = request.GetRequestStream()) {
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse) request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
var res = JsonConvert.DeserializeObject < GooogleRecaptchaResponse > (responseString);
if (res == null || !res.success || res.score < 0.5) {
EventLogProvider.LogInformation("ValidateGgRecaptchaToken", "Invalid", JsonConvert.SerializeObject(res));
InvalidHandler?.Invoke();
}
return res;
}