Php reCaptcha文件\u获取\u内容():SSL操作失败

Php reCaptcha文件\u获取\u内容():SSL操作失败,php,ssl,file-get-contents,recaptcha,Php,Ssl,File Get Contents,Recaptcha,我正在使用Google reCaptcha作为我的网页 在测试模式下,一切正常。没有SSL 在生产环境中测试网页时,出现以下错误: 警告:文件\u获取\u内容():SSL操作失败,代码为 1.OpenSSL错误消息:错误:14090086:SSL例程:SSL3\u获取\u服务器\u证书:证书验证在中失败 /vendor/google/recomptcha/src/recomptcha/RequestMethod/Post.php 在第68行警告:文件获取内容() 无法在中启用加密 /vendor

我正在使用Google reCaptcha作为我的网页

在测试模式下,一切正常。没有SSL

在生产环境中测试网页时,出现以下错误:

警告:文件\u获取\u内容():SSL操作失败,代码为 1.OpenSSL错误消息:错误:14090086:SSL例程:SSL3\u获取\u服务器\u证书:证书验证在中失败 /vendor/google/recomptcha/src/recomptcha/RequestMethod/Post.php 在第68行

警告:文件获取内容() 无法在中启用加密 /vendor/google/recomptcha/src/recomptcha/RequestMethod/Post.php 第68行

警告: 文件获取内容(): 无法打开流:中的操作失败 /vendor/google/recomptcha/src/recomptcha/RequestMethod/Post.php 第68行
[“无效json”]

我这样调用reCaptcha API:

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

如谷歌开发者页面所述

我正在hoststar.ch托管我的网页。TSL1.2正在运行


我希望有人能帮助我。

对于你最后的评论,我意识到你不能改变谷歌的
recaptchaapi
——我的意思只是在
example.com
上做一个
文件获取内容(它确实存在)作为一项测试,查看在某些Web主机禁用相关功能时,是否可以使用该方法检索任何内容

但是,对于Google reCatcha API,您可能需要为
文件获取内容
函数调用指定其他参数,特别是为SSL设置
上下文
选项

$secret = 'Your google secret';
$captcha = trim( $_POST['g-recaptcha-response'] );
$ip = $_SERVER['REMOTE_ADDR'];
$url = "https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$captcha}&remoteip={$ip}";

$options=array(
    'ssl'=>array(
        'cafile'            => '/path/to/cacert.pem',
        'verify_peer'       => true,
        'verify_peer_name'  => true,
    ),
);
$context = stream_context_create( $options );
$res=json_decode( file_get_contents( $url, FILE_TEXT, $context ) );
if( $res->success ){/* all good */}
else{ /* captcha failed */ }

如果您还没有副本,或者您可以从各自的链接下载。
cafile
的路径可以使用以下两种方法之一-将副本保存到主机并更正路径以适应您的环境。

文件获取内容更改为卷曲。这是密码

改变-

$verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
 $captcha_success=json_decode($verify);  /*store json response*/
根据本守则:

$ch = curl_init("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$verify = curl_exec($ch);

$captcha_success=json_decode($verify);  /*store json response*/

请注意,$secret是存储在服务器端的密钥,$response是从前端通过post发送的recaptcha响应。

您是否通过https调用google javascript文件?live主机是否允许使用
file\u get\u contents
获取URL?@RamRaider我不知道的第二个问题是,必须使用
file\u get\u contents('http://example.com/)
并查看测试页面上发生的情况-在实时站点上。如果您得到响应,那么主机允许fopen包装,否则您可能需要重新考虑…@RamRaider如果我执行http请求,它会工作,如果我执行https请求,它会不工作。。。我无法更改reCaptcha APICE将arrayname从http更改为ssl,并在本地添加证书使其正常工作,谢谢。。看看我的下一个问题,关于通过POST请求传递参数。。。