谷歌 reCaptcha - [“缺少输入响应”,“缺少输入秘密”]

2024-03-08

我从 Google API 对 ReCaptcha\RequestMethod\Post.php 进行了一些更改

class Post implements RequestMethod
{
    /**
    * URL to which requests are POSTed.
    * @const string
    */
    const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';

    /**
    * Submit the POST request with the specified parameters.
    *
    * @param RequestParameters $params Request parameters
    * @return string Body of the reCAPTCHA response
    */
    public function submit(RequestParameters $params)
    {
        /**
        * PHP 5.6.0 changed the way you specify the peer name for SSL context options.
        * Using "CN_name" will still work, but it will raise deprecated errors.
        */

        $cafile = dirname(__DIR__) . '/RequestMethod/ca-bundle.crt';
        $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name';
        $options = array(
            'ssl' => array(
                'header' => "Content-type: application/x-www-form-urlencoded\r\n",
                'method' => 'POST',
                'content' => $params->toQueryString(),
                // Force the peer to validate (not needed in 5.6.0+, but still works
                'cafile' => $cafile,
                'verify_peer' => true,
                'verify_peer_name' => true,
                // Force the peer validation to use www.google.com
                $peer_key => 'www.google.com',
            ),
        );
        $context = stream_context_create($options);
        return file_get_contents(self::SITE_VERIFY_URL, false, $context);
    }
}

我将以下行添加到数组中,并将其从 http 重命名为 ssl

'cafile' => $cafile 
'verify_peer_name' => true

现在我的以下问题的错误消失了。问题链接 https://stackoverflow.com/questions/33849880/recaptcha-file-get-contents-ssl-operation-failed

新错误是 ["missing-input-response","missing-input-secret"]

当我从提交方法调试 $params 时,响应和密钥都存在。

感谢您的帮助 :)


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

谷歌 reCaptcha - [“缺少输入响应”,“缺少输入秘密”] 的相关文章

随机推荐