我得到一個定製的學校CMS(PHP/Mysql/html/CSS/JS)。該CMS的其中一項功能是向學校移動應用程序發送學校信息。例如,教師可以爲他的學生添加新聞,並且CMS將Android和iOS推送通知發送給他的學生。多次發送ios推送通知不起作用
的問題是當系統發送多個iOS的通知,該通知不接收。 (單個iOS通知沒有問題)。
函數的源代碼:
function send_notification_ios($mesaj, $uye, $link = NULL,$cert = 'combined',$passphrase="passphrase123") {
$success = 0;
$failure = 0;
$error;
$errorString;
$keyPath = dirname(__FILE__) . '/' .$cert.'.pem';
$keyPassword = $passphrase;
$context = stream_context_create();
if (!stream_context_set_option($context, 'ssl', 'local_cert', $keyPath)){
return json_encode(array('success' => 0, 'failure' => 1, 'reason'=>'stream_context local_cert'));
}
if(!stream_context_set_option($context, 'ssl', 'passphrase', $keyPassword)){
return json_encode(array('success' => 0, 'failure' => 1, 'reason'=>'stream_context passphrase'));
}
$socket = stream_socket_client('ssl://gateway.push.apple.com:2195', $error, $errorString, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $context);
if (!$socket) {
return json_encode(array('success' => 0, 'failure' => 1, 'reason'=>'soket: '.$error.' '.$errorString.' '.$keyPath.' '.$keyPassword));
}
$body['aps'] = array(
'alert' => array(
'action-loc-key' => "Open",
'body' => $mesaj
),
'sound' => 'default',
'badge' => 0
);
foreach ($uye as $item) {
$body['aps']['badge'] = (isset($item['badge'])) ? $item['badge'] : 0;
$body['url'] = (isset($item['url'])) ? $item['url'] : '';
$encodedData = json_encode($body);
$binaryString = chr(0).pack('n', 32).pack('H*', $item['apikey']).pack('n', strlen($encodedData)).$encodedData;
$result = fwrite($socket, $binaryString, strlen($binaryString));
if (!$result) {
$failure++;
} else {
$success++;
}
}
fclose($socket);
return json_encode(array('success' => $success, 'failure' => $failure, 'reason'=>'fwrite', 'certname'=>$cert));
}
任何幫助將不勝感激。
在多個設備上發送推送通知您需要傳遞需要接收推送通知的所有設備令牌。 –