我的应用程序仍在开发中,我使用本教程使用PHP和SSL发送iOS推送通知。
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
它正在运行,但它最近被折旧,因为Apple最近决定放弃SSL,立即影响开发中的所有应用程序,生产中的应用程序将在10月29日之前更改其代码。
我想知道如何使用TLS而不是SSL来做同样的事情。
以下是我以前工作的php的样子:
$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);
我尝试添加Entrust证书,如Apple建议的那样:
$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);
但它仍然无法奏效。你有什么建议来解决它吗?
答案 0 :(得分:3)
$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
答案 1 :(得分:2)
<?php
$message = 'aa_' . rand(10000,99999);
$deviceToken = array(
'xxxxxx'
);
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'passphrase', '111111');
stream_context_set_option($ctx, "ssl", "local_cert", './apns.pem');
$fp = NULL;
$errno = NULL;
$errstr = NULL;
$fp = stream_socket_client("tls://gateway.sandbox.push.apple.com:2195", $errno, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if($fp === FALSE){
exit('error message');
}
$content = array("aps" => array("alert" => $message, "badge" => 4, "sound" => 'default', "code" => 200));
$data = json_encode($content);
foreach ($deviceToken as $token) {
$msg = chr(0) . pack("n", 32) . pack("H*", $token) . pack("n", strlen($data)) . $data;
fwrite($fp, $msg);
fflush($fp);
}
fclose($fp);
答案 2 :(得分:0)
以下是一些可以帮助您弄清楚的提示:
转到entrust.net/downloads/root_request.cfm并下载entrust_2048_ca.cer
添加以下代码: stream_context_set_option($ ctx,&#39; ssl&#39;,&#39; cafile&#39;,&#39; entrust_2048_ca.cer&#39;);
确定路径是否正确:&#39; ../ folder / file / ck.pem&#39;
切换并尝试沙盒和实时ssl链接。
切换dev和production pem并尝试两者。