【发布时间】:2013-04-06 11:09:50
【问题描述】:
我的应用程序有一个推送通知令牌列表(大约 10k),我不跟踪活动/已删除令牌的状态。当一个新用户被添加到系统中时,它会被添加它的推送令牌
(一个设备可以持有一个推送通知令牌,以防令牌被更改 - 在我的应用程序生命周期的最后 6 个月内没有发生 - 它使用新令牌进行修改)
为了向单个用户发送推送通知,我正在使用以下 php 脚本
<?php
// connecting to sql
sql_connect();
// get user token from sql
$token = sql_gettoken();
// Put your device token here (without spaces):
$deviceToken = $token;
// Put your private key's passphrase here:
$passphrase = 'my_passphrase';
// Put your alert message here:
if ($_GET["message"]) $message = $_GET["message"];
else $message = 'This is a default message in case no message is defined';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'production_cerfiticate.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'
);
// 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;
// Close the connection to the server
fclose($fp);
?>
我相信如果我保持 $fp(与 APNS 服务器的连接)打开,我可以在两者之间发送多个推送通知(我不确定?)。但是我已经读过,如果一个令牌是离线/删除的应用程序,那么连接会被苹果端关闭,这意味着推送通知周期将失败。
将这个单一的推送通知脚本转换为广播通知的任何提示?我不鼓励测试这个,因为第一个测试将是现场直播,我只有一个镜头。
编辑:我错过了最重要的部分,如果我只是在循环中为所有设备令牌调用此 php 脚本,这意味着它将尝试为已删除的应用程序和活动调用此脚本,Apple 会阻止/停用/禁止我的证书或我发送推送通知的能力吗?
- 对于其他寻求广播的人来说,Apple 似乎对推送通知没有任何限制。
干杯
【问题讨论】:
-
+1 对于您的编辑,我建议您查看Feedback Service,如果您得到有效的反馈,即用户尚未卸载应用程序,您可以在网上查看 PHP 示例代码,您可以发送推送通知。
-
@Jennis 感谢反馈服务,我会调查的。使用它,我可以检查并发送推送通知(如果可用),并且我可以使用此脚本,但这意味着与 APNS 的 1 次连接、1 次检查、1 次推送(如果可用)和 1 次连接关闭时间所有令牌。它会在几分钟内发生,这就像对 APNS 服务器的 40k 操作。会被视为垃圾邮件吗?
-
不应该是这样,并且没有可用的记录限制,或者我现在可以搜索Check This,保持连接打开,直到发送所有推送通知。
-
好的,所以每日推送没有限制,我会执行您建议的脚本,并让您知道它是否正常工作
标签: php iphone ios push-notification apple-push-notifications