为什么我会收到“致命错误:未捕获的异常'GuzzleHttp \ Exception \ RequestException',消息为'cURL错误60”?

5
我正在使用 Laravel 进行项目开发,需要使用 Plivo API 发送短信。我已经按照https://www.plivo.com/docs/getting-started/send-a-single-sms/ 上的步骤进行了操作。
但是当我尝试运行我的 PHP 文件时,出现以下错误信息:
“Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 60: SSL certificate problem: self signed certificate in certificate chain (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in G:\Xampp\htdocs\plivoTrial\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:187 Stack trace: #0 G:\Xampp\htdocs\plivoTrial\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(150): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array) #1 G:\Xampp\htdocs\plivoTrial\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(103): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #2 G:\Xampp\htdocs\plivoTrial\vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #3 G:\Xampp\htdocs\plivoTria in G:\Xampp\htdocs\plivoTrial\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 187”。
我的 PHP 文件如下:
<?php
require 'vendor/autoload.php';
use Plivo\RestAPI;

$auth_id = "xxxxxxxxxxxxx";
$auth_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$p = new RestAPI($auth_id, $auth_token);

// Set message parameters
$params = array(
'src' => 'xxxxxxxxxxx', 
'dst' => '91xxxxxxxxxx', 
'text' => 'Hi, I am Amarja :)', 
'url' => 'http://localhost/untitled/sentsms.php', 
'method' => 'POST' 
);
// Send message
$response = $p->send_message($params);

echo "Response : ";
print_r ($response['response']);

echo "<br> Api ID : {$response['response']['api_id']} <br>";

echo "Message UUID : {$response['response']['message_uuid'][0]} <br>";

?>

我不知道如何解决这个问题,请帮忙,非常感谢。


有什么难以理解的地方:证书链中的自签名证书(请参见http://curl.haxx.se/libcurl/c/libcurl-errors.html)? - Quentin
实际上,我之前做过同样的项目。这个新项目在旧项目所在的地方。那个旧项目运行得非常完美,所以我不知道问题出在哪里......我认为问题可能与composer有关。 - AmarjaPatil4
在您的核心文件中尝试使用 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - Chetan Ameta
我在Plivo的plivo.php文件中尝试了这个,但仍然显示相同的错误。 - AmarjaPatil4
在多个项目中使用身份验证ID和身份验证令牌是否可行? - AmarjaPatil4
1个回答

11

请勿禁用SSL

相反,修复您的PHP安装

这些指南在Windows上对我有效。

当您的CA根证书缺失或过期时,会出现这个问题。由于目前所有 Windows平台的PHP安装程序都未在分发中包含CA根证书,因此在Windows上比在Linux上更为常见。

以下是更新CA根证书的方法:

  1. 下载最新的CA根证书副本Download
  2. 将文件“cacert.pem”保存到您的计算机上。例如c:\xampp\php
  3. 将“步骤2”中“cacert.pem”文件的位置添加到您的php.ini文件中。
    php.ini文件中搜索[curl],并更新或添加以下行:
    curl.cainfo=c:\xampp\php\cacert.pem
  4. 重新启动您的Web服务器。

Curl现在拥有有效的CA根证书包,并且可以验证远程服务器的SSL证书。

如果您在Windows计算机上运行任何Google Cloud Platform PHP examples,您将收到以下cURL错误:CURLE_SSL_CACERT (60) - 对等证书无法使用已知CA证书进行身份验证。该错误现在应该是不言自明的,以及如何解决它。

1
有没有办法自动化这个过程?我发现了一个名为"certainty"的php扩展可以做到这一点,但是需要一个当前有效的cacert.pem文件来运行。如何保持这些文件的最新状态? - Richard Duerr

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接