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

Error sending iOS push notifications using PHP

尝试使用 PHP 发送 'Push Notifications' 连接 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');`

请服务器管理员为传出连接打开端口 21952196。它会解决你的问题。