首页 > 解决方案 > Google Invisible reCaptcha 未按预期工作

问题描述

我们在登陆页面“注册和登录”有两个表单,我们必须在两个表单上集成不可见的验证码。

下面是在 body 标签关闭上方加载的脚本:

<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>

注册和登录表单通过主页上的引导模式呈现。所以,我必须使用脚本中提到的单个回调来管理这两种表单。有时它工作,有时没有。!

当我执行以下脚本时,它开始显示挑战框,因为我已经附上了屏幕截图。setTimeout(function(){ grecaptcha.execute(login_captcha); },1200);

在此处输入图像描述

下面是我的 JS 代码:

function loadGoogleCaptcha(captcha_selector){
        var onloadCallback = function(captcha_selector) {
            if (captcha_selector=='login_captcha'){
                login_captcha = grecaptcha.render(captcha_selector, {'sitekey' : sitekey, 'callback' : captchaLoginCallback});
            } else if (captcha_selector=='signup_captcha'){
                signup_captcha = grecaptcha.render(captcha_selector, {'sitekey' : sitekey, 'callback' : captchaSignupCallback});
            }
        };
        onloadCallback(captcha_selector);
        if (captcha_selector=='login_captcha'){
            setTimeout(function(){ grecaptcha.execute(login_captcha); }, 1200);
        } else if (captcha_selector=='signup_captcha'){
            setTimeout(function(){ grecaptcha.execute(signup_captcha); }, 1200);
        }
    }
    function captchaLoginCallback(token){
        grecaptcha.execute(login_captcha);
        //var captcha_response = grecaptcha.getResponse(login_captcha);
        //console.log('Login: '+token+' === '+captcha_response);
    }
    function captchaSignupCallback(token){
        grecaptcha.execute(signup_captcha);
        //var captcha_response = grecaptcha.getResponse(signup_captcha);
        //console.log('Signup: '+token+' === '+captcha_response);
    }

我希望现在我的查询很清楚

我做错了什么。任何帮助,将不胜感激。

谢谢

标签: phpinvisible-recaptcha

解决方案


推荐阅读