php - 使用PHP发送iOS推送通知时出错

标签 php ios apple-push-notifications

尝试使用PHP发送连接APNS的“推送通知”时出现以下错误:

Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 

Warning: stream_socket_client(): Failed to enable crypto

Warning: stream_socket_client(): unable to connect to ssl://gateway.push.apple.com:2195 (Unknown error) 

这是我的代码:
$payload = '{"aps":{"alert":"' . $message . '","sound":"default"}}';

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'Certificate.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');

$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195',      $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);

$msg = chr(0) . pack('n', 32) . pack('H*', $item) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
 fclose($fp);

最佳答案

Root certificate并添加以下行可解决此问题

`stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');`

关于php - 使用PHP发送iOS推送通知时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40573118/

相关文章:

php - 为什么 PHPUnit 会为明显相同的字符串提供 assertEquals 失败?

ios - UICollectionView自定义动画

ios - 实际情况如何... 5.6 应用程序不能使用推送通知发送广告、促销或任何类型的直接营销?

ios - 苹果主数据管理器 : DeviceInformation command

php - 如何使用 DOMDocument 替换节点的文本

php - 我该如何让我的 friend 的 friend 使用 mysql 和 PHP

php - echo json_encode($return_data, JSON_NUMERIC_CHECK);数字中的字符 'e' 不起作用

ios - UIViewController 之间的自定义转换

ios - setZoomScale 不适用于 UIWebView

ios - Parse 中发送的推送为 0