3

我正在尝试发送推送通知,但 APNS 向我发送了以下响应:资源 id #3,所以这意味着缺少主题,第二个苹果文档,对吗?什么是“话题”?我究竟做错了什么?我再次创建证书,但我认为这不是问题。我不知道什么是“主题”。

下面是我的服务器 php:

<?php

$deviceToken = $_POST["deviceToken"];


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

// 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);

// Open a connection to the APNS server
$fp = stream_socket_client(
        'ssl://gateway.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 $fp;
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;
    echo $fp;
}   
else
{
    echo 'Message successfully delivered' . PHP_EOL;
    echo $fp;
}
    

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


?>

服务器成功发送消息,但就像我之前说的......我收到了APNS的响应:

资源 ID #3。

会是什么?

已编辑

我修复它。问题是网址......我改为 gateway.sandbox.push.apple.com。那是开发的URL!

4

1 回答 1

1

您收到资源错误,因为您回显了资源。

你做:

echo $fp;

在这种情况下 $fp 是一个资源,而不是一个字符串

于 2013-01-07T14:00:28.670 回答