如何获得验证码客户端验证参数g-recaptcha-响应后,用户确认他不是一个机器人

how to get recaptcha client verification parameter g-recaptcha-response after user confirms he is not a robot?

本文关键字:验证 机器人 一个 确认 用户 客户端 何获得 参数 g-recaptcha- 响应      更新时间:2023-09-26

我正试图在一个表单中实现谷歌验证码。表单向服务器发出HTTP post请求,然后将for数据作为JSON对象发送到服务器。

我在表单提交按钮前添加了Google reCAPTCHA,并使用以下div标签:

     <div class="g-recaptcha" data-sitekey="{SITE_KEY}"></div>

我还在head标签中添加了所需的JavaScript文件:

 <script src='https://www.google.com/recaptcha/api.js'></script>

现在提交按钮向JavaScript函数发出请求,如下所示:因此我使用的是Angular JS

  $scope.issueVideoUploadRequest = function () {
    var requestVideoUploadParameters = {
        videoSource: $scope.videoSource,
        title: $scope.title,
        description: $scope.description,
        videoLanguage: $scope.language,
        tagsList: $scope.tagsList
    };
    $http({
        method: "POST",
        dataType: "json",
        data: requestVideoUploadParameters,
        url: 'http://localhost:8080/OampSeniorProjectV2/rs/content/requestUploadForm'
    }).success(function (response, status, headers) {
        $scope.alertMessageVideoRequest = response;
        alert(response);
    }).error(function (response, status, headers, config) {
        $scope.reloadPage();
    });
};

表单提交给REST服务。

问题是,在哪里找到g-recaptcha-response参数,所以我把它连同表单JSON对象一起发送回服务器?因为我需要这个响应值来执行服务器端用户验证。

我遵循这里发布的文档

grecaptcha.getResponse(widget_id);

这将为您提供验证码的响应。如果你使用的是Angular,在表单提交函数中使用这个。