我有一個問題,當我使用推送通知,它適用於我使用開發,但是當我想使用它的真實,它不會工作。蘋果推送通知 - PHP
該ck是爲生產而製造的。
當我使用它,結果是:Message successfully delivered
但是我的手機沒有收到消息
<?php
pushNotification('wow2','DeviceToken');
function pushNotification($theMessage, $theDeviceToken)
{
// Put your device token here (without spaces):
$deviceToken = $theDeviceToken;
// Put your private key's passphrase here:
$passphrase = 'Code';
// Put your alert message here:
$message = $theMessage;
////////////////////////////////////////////////////////////////////////////////
$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);
exit("" . PHP_EOL);
//echo 'Connected to APNS\n' . 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;
fclose($fp);
}
?>
任何人都可以看看有什麼不對嗎? :)
你需要一些參考使用這個http://stackoverflow.com/questions/22717275/apns-push-notifications-not-working-on-production,http://stackoverflow.com/問題/ 17896979/APNS推送的通知 - 是 - 不工作,與生產證書 –