google reCaptcha - [“missing-input-response”,“missing-input-secret”]

时间:2015-11-22 15:15:04

标签: php ssl recaptcha

我对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

现在我的后续问题的错误消失了。 link to question

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

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

感谢您的帮助:)

0 个答案:

没有答案