为什么Apple推送服务器认为我在指定TLS时使用的是SSLv3? (苹果推开关到tls)

时间:2015-01-06 21:12:04

标签: php ios apple-push-notifications

我提前道歉,但我问同样的问题:How to send iOS Push Notifications using TLS and PHP?因为问题仍未得到解决。这是我用来尝试发送推送通知的Ray Wenderlich教程php代码,根据SO帖子的建议修改:

<?php

// Put your device token here (without spaces):
$deviceToken = '325bcd9d15ab8b5f8ff6f4f3d5ab3a5254f1ce775d48828476f4aaff4c5c3d3f';

// Put your private key's passphrase here:
$passphrase = 'pushchat';

// Put your alert message here:
$message = 'My first push notification!';

////////////////////////////////////////////////////////////////////////////////

$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');

// Open a connection to the APNS server
$fp = stream_socket_client(
    'tls://gateway.sandbox.push.apple.com:2195', $err,
    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp)
    exit("Failed to connect: $err $errstr" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

// Create the payload body
$body['aps'] = array(
    'alert' => $message,
    'sound' => 'default'
    );

// Encode the payload as JSON
$payload = json_encode($body);

// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));

if (!$result)
    echo 'Message not delivered' . PHP_EOL;
else
    echo 'Message successfully delivered' . PHP_EOL;

// Close the connection to the server
fclose($fp);

我还下载了entrust_2048_ca.cer文件并确保它显示在我的钥匙串访问的系统选项卡上。当我运行这个php文件时,我仍然会收到以下错误,这是我在进行更改以反映tls使用之前得到的同一组错误:

error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure in /Users/aileenann/Desktop/SimplePush/simplepush.php on line 22

Warning: stream_socket_client(): Failed to enable crypto in /Users/aileenann/Desktop/SimplePush/simplepush.php on line 22

Warning: stream_socket_client(): unable to connect to tls://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Users/aileenann/Desktop/SimplePush/simplepush.php on line 22
Failed to connect: 0 

还有什么需要改变?当我在URL中指定tls时,为什么苹果服务器仍然认为我正在尝试使用SSL3?

感谢您提出任何建议。

0 个答案:

没有答案