无法在“ file_get_contents()”中加载cafile流?

Jef*_*Yan 2 php google-geocoding-api

我正在尝试从Google地理编码API获取JSON数据。但是,PHP警告显示有关“无法加载cafile流”的一些错误

这是我的代码:

$apiKey  = 'apikey';
$address = urlencode( '1600 Amphitheatre Pkwy, Mountain View, CA 94043' 
);
$url     = "https://maps.googleapis.com/maps/api/geocode/json?address= 
    {$address}key={apiKey}";
$resp    = json_decode( file_get_contents( $url ), true );
echo $url;

$lat    = $resp['results'][0]['geometry']['location']['lat'] ?? '';
$long   = $resp['results'][0]['geometry']['location']['lng'] ?? '';
Run Code Online (Sandbox Code Playgroud)

这是错误:

PHP Warning:  failed loading cafile stream: `C:\xampp\apache\bin\curl-ca- 
bundle.crt' in C:\Users\1\Desktop\test.php on line 7

Warning: failed loading cafile stream: `C:\xampp\apache\bin\curl-ca- 
bundle.crt' in C:\Users\1\Desktop\test.php on line 7
PHP Warning:  file_get_contents(): Failed to enable crypto in 
C:\Users\1\Desktop\test.php on line 7

Warning: file_get_contents(): Failed to enable crypto in 
C:\Users\1\Desktop\test.php on line 7
PHP Warning:  
file_get_contents(https://maps.googleapis.com/maps/api/geocode/json? 
address=1600+Amphitheatre+Pkwy%2C+Mountain+Vi
ew%2C+CA+94043key={apiKey}): failed to open stream: operation failed in 
C:\Users\1\Desktop\test.php on line 7

Warning: 
file_get_contents(https://maps.googleapis.com/maps/api/geocode/json? 
address=1600+Amphitheatre+Pkwy%2C+Mountain+View%2C
+CA+94043key={apiKey}): failed to open stream: operation failed in 
C:\Users\1\Desktop\test.php on line 7
https://maps.googleapis.com/maps/api/geocode/json? 
address=1600+Amphitheatre+Pkwy%2C+Mountain+View%2C+CA+94043key={apiKey}
Run Code Online (Sandbox Code Playgroud)

Moh*_*BLI 7

当您的php.ini文件的curl.cainfoopenssl.cafile配置属性未针对任何有效的证书,这些证书将使您无法与ssl创建连接时,将发生此错误。

例如,使用CURL调用外部服务器的请求时,就会发生这种情况。

您必须从此处的链接中下载casert.pem

并将认证文件放在路径中:

C:\ xampp \ apache \ bin \ cacert.pem

之后,在名为:curl.cainfoopenssl.cafile的配置项上检查php.ini 并进行此配置

例如:

curl.cainfo = "C:\xampp\apache\bin\cacert.pem"
openssl.cafile = "?C:\xampp\apache\bin\cacert.pem"
Run Code Online (Sandbox Code Playgroud)