Why I am getting Fatal error: Uncaught exception &

2019-08-12 17:16发布

问题:

I am doing project in laravel. I am using plivo api for sending sms. For that I followed all the steps mentioned at

https://www.plivo.com/docs/getting-started/send-a-single-sms/ .

but When I tried to run my php file then I am getting error message as

"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".

My php file looks like,

<?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>";

?>

I am not getting how to solve this problem. please help and many thanks in advance.

回答1:

Do not disable SSL

Instead, fix your PHP installation.

These directions worked for me on Windows.

This problem shows up when your CA root certificates are missing or out-of-date. Since at the moment ALL the Windows platform PHP installers DO NOT include the CA root certificates in the distribution, its much more common on Windows than on Linux.

Here is how you update the CA root certificates:

  1. Download an up-to-date copy of CA root certificates.
  2. Save the file "cacert.pem" to your computer. For example c:\xampp\php
  3. Add the location of the "cacert.pem" file from Step 2 to your php.ini file.
    Search for [curl] in your php.ini file and update or add the following line:
    curl.cainfo=c:\xampp\php\cacert.pem
  4. Restart your web server.

Curl now has a valid CA root certificate bundle and can verify the SSL certificates of remote servers.

If you are running any of the Google Cloud Platform PHP examples on a Windows computer you'll get the following cURL error : CURLE_SSL_CACERT (60) - Peer certificate cannot be authenticated with known CA certificates. That error should now be self-explanatory along with how to fix it.