1
我试图发送推送通知,但APNS发给我这个回复:资源ID#3,所以这意味着缺少主题,第二个苹果文档,对吗? 什么是“主题”?我究竟做错了什么? 我再次创建证书,但我认为这不是问题。我不知道什么是“话题”。下面我无法接收推送通知 - 我收到回应“资源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);
?>
服务器发送与sucess消息,但就像我之前说的...我收到APNS的响应:
资源ID#3。
它可能是什么?
EDITED我修复它。问题是网址...我改成了gateway.sandbox.push.apple.com。这是开发的URL!
我删除,但仍不能工作。显示$ fp不会影响任何内容。 APN收到我的请求并返回此消息。 – holydev0tion