【问题标题】:Apple Push Notification Service苹果推送通知服务
【发布时间】:2010-12-01 16:09:27
【问题描述】:

我尝试使用本地 mac 机器运行,但出现以下错误

Warning: stream_socket_client() [function.stream-socket-client]: Unable to set private key file `/Applications/XAMPP/xamppfiles/htdocs/apns/apns-dev.pem’ in /Applications/XAMPP/xamppfiles/htdocs/apns/apns.php on line 9

Warning: stream_socket_client() [function.stream-socket-client]: failed to create an SSL handle in /Applications/XAMPP/xamppfiles/htdocs/apns/apns.php on line 9

Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /Applications/XAMPP/xamppfiles/htdocs/apns/apns.php on line 9

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Applications/XAMPP/xamppfiles/htdocs/apns/apns.php on line 9

Warning: socket_close() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/apns/apns.php on line 11

Warning: fclose() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/apns/apns.php on line 12

我获得了从其他机器生成的 PEM 证书,

所以我很困惑我现在要做什么。

请让我知道我需要做什么才能在 localhost 中运行它

【问题讨论】:

  • 我有同样的问题,我可以在我的本地 XAMPP 服务器上运行。但它没有在我的外部服务器中运行。
  • 嗨 Biranchi,请咨询您的托管服务提供商,将端口列入白名单,这将解决您的问题

标签: php macos openssl apple-push-notifications


【解决方案1】:

我认为您可能导出了证书,但没有导出苹果提供的 .cer 文件中的私钥。

markbates 的这些说明可能会有所帮助:

获得证书后 Apple 为您的应用程序,导出 您的密钥和苹果证书为 p12 文件。这是一个快速演练 关于如何做到这一点:

  1. 单击钥匙串访问中证书旁边的披露箭头 并选择证书和 钥匙。
  2. 右键单击并选择Export 2 items…
  3. 从下拉列表中选择 p12 格式并将其命名为 cert.p12

现在将 p12 文件转换为 pem 文件:

$ openssl pkcs12 -in cert.p12 -out apple_push_notification_production.pem -nodes -clcerts

【讨论】:

  • 嗨 jessecurry 非常感谢您的建议 它工作得很好,除了一个警告警告:socket_close():提供的资源不是有效的套接字资源。你能告诉我可能是什么问题吗?
  • 这听起来像是一个 php 错误。你用的是什么版本的php?你传递给 socket_close() 的是什么?
  • iam 使用 pHP 版本 5 $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext); socket_close($apns);
  • 我不是一个真正的 PHP 人,但我认为您在使用 stream_socket_client 创建时可能会使用 fclose()。我认为 socket_close() 与socket_create() 一起工作,不过不要太认真,我可能错了。
  • 谢谢!我使用了一种稍微不同的方法来分别转换证书和密钥,尽管在过去它有效,但在我需要续订时不再有效。这种方法效果很好,而且更容易。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-08
  • 2011-12-03
  • 2012-10-20
  • 2017-10-25
相关资源
最近更新 更多