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