1

我正在使用 Google reCaptcha v3。我正在尝试在我的 aspx 页面上实现它。当我第一次加载我的页面时,我可以获得一个令牌。但是,当我单击一个按钮来处理我的页面时,它会返回“没有 reCaptcha 客户端退出”。我确实对此进行了谷歌搜索,但没有任何东西可以解决我的问题。如何验证人或机器人交互?

这是我在我的 aspx 页面上的内容:

<div id="RegistrationForm">
  <input type="text" id="FirstName" runat="server" value="" valtype="required" maxlength="150" />
  <input type="text" id="LastName" runat="server" value="" valtype="required" maxlength="150" />
  <input runat="server" id="Email" type="text" value="" valtype="required;regex:email" maxlength="350"/>
  <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"/> <br />
  <div class="g-recaptcha" data-sitekey="SiteKey" data-callback="submit"></div>
  <input id="btnProcessOrder" type="button" name="ProcessOrder" onclick="confirmed = false;capt();" value="Save" />
</div>

这是我试过的

<script src="https://www.google.com/recaptcha/api.js?render=SiteKey"></script>
<script type="text/javascript">
    //so when i load the page it gets my token and i can assign the value to g-recaptcha-response
   grecaptcha.ready(function() {
       grecaptcha.execute('SiteKey', { action: 'homepage' }).then(function (token) {
           console.log(token);
           document.getElementById('g-recaptcha-response').value = token;

  });
});


 Then when i try to verify the response as follows i get the error or it just does nothing:
function capt() {
var response = grecaptcha.getResponse();
$.ajax({
   type: "POST",
   url: 'https://www.google.com/recaptcha/api/siteverify', 
   data: {"secret" : "SecretKey", "response" : response, "remoteip":"localhost"},
   contentType: 'application/x-www-form-urlencoded',
   success: function(data) { console.log(data); }
});// i call this function on my button
}
</script>

我发现的大部分代码都是用于 php 的,我不能使用它。我怎样才能让它正常工作?非常感谢您的回复

4

2 回答 2

1

根据以上评论:

您创建一个渲染函数如下

grecaptcha.render('example3', {
    'sitekey' : 'your_site_key',
    'callback' : verifyCallback,
});

然后要从验证码中获取响应,您需要创建一个变量来存储数据,如下所示:

var verifyCallBack = function(response) { 
    console.log(response); 
};
于 2019-06-20T19:52:25.103 回答
0

这里我们已经有一个相同类型的问题: 如何在 ASP.NET 中实现 reCaptcha V3 请检查这些答案。

您也可以查看此演示项目以供参考。https://github.com/NIHAR-SARKAR/GoogleRecaptchav3-example-In-asp.net

于 2019-07-12T20:38:17.887 回答