Laravel 5.1 GCM推送通知SSL错误

时间:2016-08-10 10:13:35

标签: php laravel-5 push-notification google-cloud-messaging ssl-certificate

我通过GCM客户端将laravel 5.1\Zend\Http\ PushNotification连接起来。 它运作良好。但突然间它停止了工作并产生了一些exceptions

我的代码就像......

$collection = PushNotification::app('appNameAndroid')->to ( $deviceToken ); 
$collection->adapter->setAdapterParameters(['sslverifypeer' => false]);
$collection->send ( $message );

我也试过以下代码,但没有一个正在运作......

$collection = PushNotification::app('appNameAndroid')->to ( $deviceToken ); 
$new_client = new \Zend\Http\Client(null, array(
                'adapter' => 'Zend\Http\Client\Adapter\Socket',
                'sslverifypeer' => false
));
$collection->adapter->setHttpClient($new_client); 
$collection->send ( $message );

----------------------------and-----------------------------------

$collection = PushNotification::app('appNameAndroid')->to ( $deviceToken ); 
        $collection->adapter->setAdapterParameters(array(
        'ssl'=>array(
                'verify_peer' => false,
                'verify_peer_name' => false)
));
$collection->send ( $message );

例外是......

exception 'ErrorException' with message 'stream_socket_enable_crypto(): SSL     operation failed with code 1. OpenSSL Error messages:
error:14077102:SSL routines:SSL23_GET_SERVER_HELLO:unsupported protocol' in C:\xampp\htdocs\activ8-webapp\api\vendor\zendframework\zend-http\src\Client\Adapter\Socket.php:281

Next exception 'Zend\Http\Client\Adapter\Exception\RuntimeException' with message 'Unable to enable crypto on TCP connection gcm-http.googleapis.com' in C:\xampp\htdocs\activ8-webapp\api\vendor\zendframework\zend-http\src\Client\Adapter\Socket.php:308

1 个答案:

答案 0 :(得分:1)

根据此thread,如果您的证书不匹配,则该错误将失败。修复您的SSL配置,因为它不是PHP的错误。如果要连接的服务器的SSL配置不正确,则会出现如下错误。尝试用一个好的证书替换无效,配置错误或自签名的证书。您可以通过SMTPOptions属性允许不安全的连接。在早期版本中,subclassing the SMTP class可以执行此操作,但不建议这样做。还可以尝试将app/config/email.phpsmtp更改为mail

在此link上找到示例代码段:

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

您还可以查看以下相关链接:

希望这有帮助!