Recaptcha 验证问题

问题描述

我在使用注册页面来实施 Google 的 reCaptcha v2 时遇到问题。

                //DONGND:: check email exist to register
            if (Customer::customerExists($email,true,true)) {
                $errors[] = $this->l('This email is already used,please choose another one or sign in','leocustomer');
            } else {
                $hookResult = array_reduce(
                    Hook::exec('actionSubmitaccountBefore',array(),null,true),function ($carry,$item) {
                        return $carry && $item;
                    },true
                );

                $gurl = "https://www.google.com/recaptcha/api/siteverify";
                $secretKey = "CENSORED";

                $ch = curl_init();

                curl_setopt_array($ch,[
                    CURLOPT_URL => $gurl,CURLOPT_POST => true,CURLOPT_POSTFIELDS => [
                        'secret' => $secretKey,'response' => $gcaptcha,'remoteip' => $_SERVER['REMOTE_ADDR']
                    ],CURLOPT_RETURNTRANSFER => true
                ]);

                $output = curl_exec($ch);
                curl_close($ch);

                $googleResponSEObj = json_decode($output);

                if($googleResponSEObj->success !== true){
                    $this->context->controller->errors[] = $this->trans('Captcha verification Failed','Shop.Notifications.Error');
                }
                else {


                //DONGND:: add new account
                $customer = new Customer();
                $customer->firstname = $firstname;
                $customer->lastname = $lastname;
                $customer->email = $email;
                $customer->passwd = $this->get('hashing')->hash($pass,_COOKIE_KEY_);

这是注册背后的 .PHP 代码,至少是有趣的部分。我切断了修剪并检查数据是否有效/已使用。然后我有一个页面的 .tpl 文件来知道要使用什么 HTML。

            <div class="form-group row">
             <div class="col-md-9">
                <div class="g-recaptcha" data-sitekey="CENSORED" id="captcha-Box" data-theme="{$captchatheme}"></div>
             </div>
            <script src="https://www.google.com/recaptcha/api.js" async defer></script>
        </div>

验证码框出现,除了上面的 PHP 代码外,它破坏了注册过程,现在每当我尝试注册时,它都会返回“未定义”并刷新页面,就好像您完成了注册但它没有。即使我真的完成了验证码,我现在也不能用这个代码创建一个帐户。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)