尝试使用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/