Google Recaptcha V3-通过URL加载验证码时的小部件ID [英] Google Recaptcha V3 - Widget Id when loading captcha through URL

查看:317
本文介绍了Google Recaptcha V3-通过URL加载验证码时的小部件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的网站上实现Recaptcha V3,如果我的请求失败,我找不到重置令牌的正确方法.

I am implementing the Recaptcha V3 on my site, and I could not find a proper way to reset the token if my request has failed.

根据文档,要加载验证码,我需要在页面上包含以下脚本:

Following the documentation, to load the recaptcha I need to include the following script on my page:

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

我还将验证码令牌绑定到一个字段,以便当客户选择发送电子邮件时在后端进行验证:

Also I am binding the captcha token to a field, to validate on my back end when the customer choose to send an e-mail:

    grecaptcha.ready(function() {
        grecaptcha.execute('MY_KEY', {
            action : 'homepage'
        }).then(function(token) {
            $("#recaptcha").val(token);
        });
    });

所以我主要有两个步骤:

So I have mainly two steps:

  1. 验证验证码
  2. 发送电子邮件

如果在第二步过程中发生了一些错误,我将无法找到一种方法来重置页面上的当前验证码,因为如果我再试一次,该验证码已经过验证.

If some error occur during the second step, I was unable to find a way to reset the current captcha on the page, since it was already validated if I try again it is no longer valid.

我已经尝试过grecaptcha.reset(),但是没有widgetId时,会出现以下消息:Uncaught Error: No reCAPTCHA clients exist.

I have tried the grecaptcha.reset(), but without the widgetId the following message appears: Uncaught Error: No reCAPTCHA clients exist.

通过脚本渲染时如何获取小部件ID?

How can I get the widget id when rendering through the script?

推荐答案

据我从Recaptcha V3的了解,您必须再次调用execute. 尝试这样做

As I understand from Recaptcha V3 you have to call execute again try to do it like this

let createNewToken = () => {
        grecaptcha.ready(function() {                   
            grecaptcha.execute('code', {action: 'homepage'}).then(function(token) {
                 console.log(token);
            });
         });        
}

这篇关于Google Recaptcha V3-通过URL加载验证码时的小部件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆