norkunas / onesignal-php-api

OneSignal API for PHP
MIT License
233 stars 82 forks source link

Error while adding Notification #7

Closed vhanded closed 8 years ago

vhanded commented 8 years ago

Hi, I am new to PHP, and while using your library, I got this error:

Fatal error: Uncaught exception 'GuzzleHttp\Ring\Exception\RingException' with message 'cURL error 60: SSL certificate problem: unable to get local issuer certificate' in C:\wamp\www\project_name\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 51

This happened when I call $api->notifications->add().

What is possible go wrong?

norkunas commented 8 years ago

Hello @vhanded,

This is probably related to your webserver cURL configuration. In short you must provide a local list of certicificates which will be checked when you are making a request with SSL to secure from "man in the middle" attacks. You can read about cacert.pem file here http://serverfault.com/questions/241046/what-is-the-cacert-pem-and-for-what-to-use-that.

I recommend you to download the cacert.pem file from http://curl.haxx.se/ca/cacert.pem and place it in your server and configure the path to that file and then the exception should disappear.

But if you can't modify PHP configuration then there is another option. Since this package uses Guzzle, you can create a Guzzle client before OneSignal and pass to constructor as a second parameter.

use GuzzleHttp\Client;

$guzzle = new Client([
    'defaults' => [
        'headers' => [
            'Accept' => 'application/json',
        ],
        'cert' => '/path/to/cacert.pem',
    ],
]));

$oneSignal = new \OneSignal\OneSignal(.., $guzzle);

Also about guzzle configuration you can read here: http://docs.guzzlephp.org/en/5.3/clients.html?highlight=cert#verify