recaptcha v3 - 网站所有者错误:密钥类型无效

Hel*_*rld 7 html javascript recaptcha

我在我的网站上的 Google Recaptcha V3 中收到以下错误。

网站所有者错误:密钥类型无效

在此输入图像描述

我使用以下方法来验证验证码:

  1. 添加脚本
<script src="https://www.google.com/recaptcha/api.js?render=API_KEY"></script>
Run Code Online (Sandbox Code Playgroud)
  1. 提交时验证:
$('.submit-e-way-bill-registration').on('submit', function (e) {
    e.preventDefault();
    var self = this;
    if ($(self)[0].checkValidity()) {
        grecaptcha.ready(function () {
            grecaptcha.execute('API_KEY', {
                action: 'homepage'
            }).then(function (token) {
                console.log(token);

                console.log('google captcha initiated');
                $('[name=captcha_token]').val(token);

                var data = $(self).serialize();
                $('.save-button-ewb').prop('disabled', true);
                $.post('/api/submit-e-way-bill-registration.php', data, function (result) {
                    $('.save-button-ewb').prop('disabled', false);
                    console.log('status');
                    if (result.status == 'success') {
                        $('.success-message').show();
                        $('.submit-e-way-bill-registration').hide();
                    } else {
                        $('.error-message').show();
                        $('.submit-e-way-bill-registration').hide();
                    }
                });
            });
        });

    }
});
Run Code Online (Sandbox Code Playgroud)

以前(大约 3-4 个月前)曾经这样工作过。现在,当我检查时,出现上述错误。

谁能告诉我代码有什么问题吗???

Car*_*oso 5

几天前我就遇到过这样的错误。我通过生成正确的 ReCaptcha 站点的客户端密钥解决了这个问题。在我看来,您的脚本需要 google ReCaptcha v2,但您正在使用 v3。请检查此屏幕截图。这解决了我的问题。 在此输入图像描述

如果您在 React 中使用 Node 模块,请从此文档获取更多详细信息。