如何使用 TLS 和 PHP 发送 iOS 推送通知?

问题描述:

我的应用仍在开发中,我使用本教程使用 PHP 和 SSL 发送 iOS 推送通知.

My app is still in development and I used this tutorial to send iOS Push Notifications using PHP and SSL.

http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

它正在运行,但最近贬值了,因为 Apple 最近决定立即放弃 SSL,这会立即影响所有正在开发的应用,并且生产中的应用必须在 10 月 29 日之前更改其代码.

It was working but it was recently depreciated because Apple recently decided to drop SSL immediately affecting all apps in development and apps in production have until October 29th to change their code.

我想知道如何使用 TLS 而不是 SSL 来做同样的事情.

I would like to know how to do the same thing using TLS instead of SSL.

这是我过去工作的 php 的样子:

Here is what my php that used to work looks like:

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

我尝试按照 Apple 的建议添加 Entrust 证书:

I tried adding an Entrust certificate as Apple suggests:

$ctx = stream_context_create();
stream_context_set_option($ctx, 'tls', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'tls', 'passphrase', $passphrase);
stream_context_set_option($ctx, 'tls', 'cafile', 'entrust_2048_ca.cer');
$fp = stream_socket_client('tls://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

但是还是不行.你有什么建议来修复它吗?

But it still doesn't work. Do you have any suggestion to fix it?

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
$fp = stream_socket_client('tls://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

如果您在本地主机环境中工作,请不要忘记下载认证文件 entrust_2048_ca.cer

if you work in a localhost environment don't forget download the certification file entrust_2048_ca.cer