gpt4 book ai didi

php - iOS 发送多个推送通知

转载 作者:行者123 更新时间:2023-11-28 21:57:03 26 4
gpt4 key购买 nike

我想用 php 脚本从数据库发送多个 PN。表中有 3 个设备 token ,但脚本只将其发送给第一个。

这里是脚本,有人有想法。

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'DEV.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp){
exit("Failed to connect: $err $errstr" . PHP_EOL);
}

$ausgabe.= 'Connected to APNS' . PHP_EOL . '<hr>';

$body['aps'] = array(
'alert' => $message,
'sound' => 'note.wav',
'badge' => 1
);

$payload = json_encode($body);

$selectSQL = 'SELECT * from app_pushnotification';
$result = mysql_query($selectSQL);
while($row = mysql_fetch_array($result)){
$i+=1;
$ausgabe.= $i.' - '. $row['device_token'].' ';
$deviceToken = $row['device_token'];

$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

$result = fwrite($fp, $msg, strlen($msg));

if (!$result){
$ausgabe.='Message to not delivered' . PHP_EOL . '<hr>';
} else {
$ausgabe.='Message to successfully delivered' . PHP_EOL . '<hr>';
}

}

$ausgabe.='close connection';
fclose($fp);

}
echo $ausgabe;

问候凯文

最佳答案

您的错误是您在循环中更改了$result 的值。因此脚本无法获取下一行数组。

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'DEV.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp){
exit("Failed to connect: $err $errstr" . PHP_EOL);
}

$ausgabe.= 'Connected to APNS' . PHP_EOL . '<hr>';

$body['aps'] = array(
'alert' => $message,
'sound' => 'note.wav',
'badge' => 1
);

$payload = json_encode($body);

$selectSQL = 'SELECT * from app_pushnotification';
$result = mysql_query($selectSQL);
while($row = mysql_fetch_array($result)){
$i+=1;
$ausgabe.= $i.' - '. $row['device_token'].' ';
$deviceToken = $row['device_token'];

$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

$write_result = fwrite($fp, $msg, strlen($msg));

if (!$write_result){
$ausgabe.='Message to not delivered' . PHP_EOL . '<hr>';
} else {
$ausgabe.='Message to successfully delivered' . PHP_EOL . '<hr>';
}

}

$ausgabe.='close connection';
fclose($fp);

}
echo $ausgabe;

请注意,第二个 $result = 现在是 $write_result =

关于php - iOS 发送多个推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26184601/

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