APNS与谷歌应用引擎和PHP SSL错误


APNS with Google App Engine and PHP SSL error

我试图从PHP应用引擎后端发送iOS推送通知,但我收到以下错误。我不确定证书是否有问题,我这样做的方式,或者特定于应用程序引擎的东西。这是我第一次向iOS发送推送通知。

下面是我的代码:
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
{
  //Handle Error
}
$body['aps'] = array(
  'alert' => $data["message"],
  'sound' => 'default',
);
$body["postID"] = $data["postID"];
$body["groupID"] = $data["groupID"];
$body["type"] = $data["type"];
$payload = json_encode($body);
foreach ($registrationIds as $registrationID)
{
  $deviceToken = $registrationID;
  $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
  $result = fwrite($fp, $msg, strlen($msg));
}
fclose($fp);

下面是我得到的错误:

PHP Warning:  stream_socket_client(): SSL operation failed with code 1. OpenSSL 
Error messages: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake 
failure in fakefile.php

我不知道原因是什么。提前感谢

更新:这不再是我得到的错误。现在我得到这个:

PHP Warning:  stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error)

可能是您的端口2195和2196从服务器端关闭,阻止推送通知。

在stream_context_set_option中,您没有包含ck的完整路径。Pem文件。在给出完整的路径后,没有错误。

下面的代码可能有助于解决你的问题。

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '/Users/Development/Dev/ck.pem');

以下代码用于检查端口是否启用推送通知。

<?php
chkServer('gateway.sandbox.push.apple.com', 2195);
//chkServer('gateway.push.apple.com',2195); 
function chkServer($host, $port)
{
    $hostip = @gethostbyname($host);
    if ($hostip == $host) {
        echo "Server is down or does not exist";
    } else {
        if (!$x = @fsockopen($hostip, $port, $errno, $errstr, 5)) {
            echo "Port $port is closed.";
        } else {
            echo "Port $port is open.";
            if ($x) {
                @fclose($x);
            }
        }
    }
}
?>

快乐编码。