gpt4 book ai didi

php - 使用 PHP (iOS) 向多个 token 发送推送通知

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:18:11 25 4
gpt4 key购买 nike

我有一个包含所有设备 token 的数据库。我继续从数据库中获取 token ,但我的脚本不再工作(推送不发送)。

这是我的脚本:

<?PHP

$db_user = "xxx"; // Gebruiker voor MySQL
$db_pass = "xxx"; // Wachtwoord voor MySQL
$db_host = "localhost"; // Host voor MySQL; standaard localhost
$db_db = "xxx"; // Database

// Als je al ergens anders een database connectie hebt gemaakt,
// maak dan van de volgende twee regels commentaar (# of // ervoor zetten)
mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_db);

$query = mysql_query("SELECT * FROM iospush");

while ($row = mysql_fetch_array($query)) {
$deviceToken = $row["devicetoken"];
}

if($_POST['message']){

// $deviceToken = 'xxx';

$message = stripslashes($_POST['message']);

$payload = '{
"aps" :

{ "alert" : "'.$message.'",
"badge" : 1
}
}';


$ssl='xx.pem';

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $ssl);
stream_context_set_option($ctx, 'ssl', 'passphrase', 'xxx');
$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 "Notifications sent!";
}

$devArray = array();
$devArray[] = $deviceToken;

foreach($devArray as $deviceToken){
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack ("n",strlen($payload)) . $payload;
print "sending message :" . $payload . "n";

fwrite($fp, $msg);
}
fclose($fp);
}

?>
<form action="pushios.php" method="post">
<input type="text" name="message" maxlength="100">
<input type="submit" value="Send Notification">
</form>

请帮助我让它工作!

谢谢!

最佳答案

$deviceToken = ARRAY();
while ($row = mysql_fetch_array($query)) {
$deviceToken[] = $row["devicetoken"];
}

...

// or use ($devArray = $deviceToken;)

foreach($deviceToken as $token){
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $token)) . pack ("n",strlen($payload)) . $payload;

关于php - 使用 PHP (iOS) 向多个 token 发送推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15960051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com