![](/img/trans.png)
[英]unable to receive all ios notifications in device using php apns push
[英]APNS: Invalid token causes all subsequent push notifications to fail
我正在使用Sly PHP推送通知庫 ,但是無論我是否完全手動發送所有推送通知而沒有該庫,都會發生同樣的事情(如下面的腳本中所示)。 如果我的SQL數據庫中存在無效的令牌,並且我嘗試向該令牌發送推送,則我與ssl://gateway.push.apple.com:2195
斷開連接,並且所有后續令牌均未收到該推送。 如何發現無效令牌並將其從數據庫中刪除,或者在遇到無效令牌后如何繼續發送推送? 我下面的一個php腳本(盡管不是上面的庫)遭受了相同的錯誤:
// Put your device token here (without spaces):
$iosTokens = array(xxxx, xxxx, xxxx);
// Put your private key's passphrase here:
$passphrase = '';
$message = "Message";
$url = "URL";
if (!$message || !$url)
exit('Example Usage: $php newspush.php \'Breaking News!\' \'https://raywenderlich.com\'' . "\n");
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '../../../PEMs/siouxFallsStampede.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' => $message,
'sound' => 'default',
'link_url' => $url,
);
// Encode the payload as JSON
$payload = json_encode($body);
foreach($iosTokens as $devicetoken) {
// 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));
var_dump($result);
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
}
// Close the connection to the server
fclose($fp);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.