我正在使用此php腳本,但它的生成輸出消息已成功發送但未發送通知。我已經檢查過設備ID和證書,他們是完美的,並且可以很好地處理另一個腳本。蘋果推送通知腳本不起作用
<?php
// Put your device token here (without spaces):
$deviceToken = 'fbf04bf4ace2f1e823016082da3a798cf3ab666ae99a395b65e364eb4c6d6d4a';
// Put your private key's passphrase here:
$passphrase = '123';
// Put your alert message here:
$message = 'A push notification has been sent!';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'key.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 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array('alert' => array('body' => $message, 'action-loc-key' => 'Look',), 'badge' => 2, 'sound' => 'oven.caf',);
// 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));
echo "<pre>Result : ";
print_r($result);
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
?>
任何人都可以幫助我擺脫這一點。 在此先感謝
請點擊此鏈接。可能這會幫助你找出問題所在。 http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 –
謝謝,但阿里Hafizji焦點蘋果設備端... 他不知道關於服務器端.. –
爲什麼不嘗試這個=== https://packagist.org/packages/sly/notification-pusher,它的確如我剛纔那樣工作。 – Tom