Php APNS:无效令牌导致所有后续推送通知失败
我正在使用,但是如果我完全手动发送所有推送通知,而不使用库(如下面的脚本中所示),则会发生相同的情况。如果我的SQL数据库中有一个无效的令牌,并且我试图向该令牌发送推送,那么我将断开与Php APNS:无效令牌导致所有后续推送通知失败,php,ios,apple-push-notifications,apns-php,Php,Ios,Apple Push Notifications,Apns Php,我正在使用,但是如果我完全手动发送所有推送通知,而不使用库(如下面的脚本中所示),则会发生相同的情况。如果我的SQL数据库中有一个无效的令牌,并且我试图向该令牌发送推送,那么我将断开与ssl://gateway.push.apple.com:2195和所有后续令牌不接收推送。如何发现无效令牌并将其从数据库中删除,或者在遇到无效令牌后继续发送推送?下面的一个php脚本(虽然不是上面的库)也有相同的错误: // Put your device token here (without spaces):
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);
这个问题解决了。我所做的是按ID对令牌进行排序,当令牌无效时,我将其从SQL数据库中删除,并继续向ID高于无效令牌的令牌发送推送(因此按ID排序至关重要)