我有带有设备令牌和 php 脚本的数据库,它可以向 ios 设备发送通知,但我需要帮助如何向我的数据库中的所有设备令牌发送相同的消息?这是我的 php 代码:
<?
$con0 = mysql_connect("server","usr","pass");
mysql_select_db("table", $con0);
//$fetch = mysql_query("SELECT * FROM token ORDER BY token");
$result = mysql_query("SELECT * FROM toke ORDER BY token");
while($row = mysql_fetch_array($result)){
$token=$row['token'];
}
mysql_close();
if($_POST['message']){
$message = stripslashes($_POST['message']);
$payload = '{
"aps" :
{ "alert" : "'.$message.'",
"badge" : 1,
"sound" : "bingbong.aiff"
}
}';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', 'iphonista');
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if(!$fp){
print "Failed to connect $err $errstrn";
return;
} else {
print "Notifikace byla odeslána! <br><br><br>";
}
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $token)) . pack ("n",strlen($payload)) . $payload;
fwrite($fp, $msg);
fclose($fp);
}
?>
你能帮助我吗?谢谢