【问题标题】:Error sending iOS push notifications using PHP使用 PHP 发送 iOS 推送通知时出错
【发布时间】:2016-11-13 11:06:16
【问题描述】:

我在尝试使用 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);

【问题讨论】:

  • 向我们提供您的 php 代码:P
  • 是的,请分享您的代码。
  • 听起来您缺少 (1) TLS 1.0 及更高版本,(2) 服务器名称指示,以及 (3) 可能是 Entrust.net 证书颁发机构 (2048) 根.另见“verify error:num=20” when connecting to gateway.sandbox.push.apple.com
  • @jww 谢谢。缺少 Entrust.net 证书颁发机构 (2048) 是问题所在。在下载 Entrust 根证书stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer'); 后添加了这一行。通知现在工作正常

标签: php ios apple-push-notifications


【解决方案1】:

Root certificate 并添加以下行修复了问题

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 谢谢Kenil ..即使端口是开放的,没有entrust_2048_ca.cer,它会遇到错误:14090086
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多