我必須做的有節省分貝,我有使PHP許多設備發送推送通知(分配)代碼:推送通知,如果deviceToken是錯的不是發送給其他
// Put your alert message here:
$message = "send push";
// Put your private key's passphrase here:
$passphrase = 'phrase';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns.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'. "<br>" ;
ob_flush();
flush();
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
if (mysql_num_rows($results)!=0) {
while($row = mysql_fetch_array($results))
{
$deviceToken= $row['deviceToken'];
if(isset($deviceToken)&&(strcmp($deviceToken,"(null)")!=0)){
echo "<br>".$deviceToken."<br>";
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered';
else
echo 'Message successfully delivered' ;
ob_flush();
flush();
}
}
// Close the connection to the server
fclose($fp);
}
如果我有數據庫,只有deviceToken正確或值(空),消息發送,但如果我有一個deviceToken錯誤,我收到消息'消息已成功發送'已發送所有消息,但不工作。我犯了什麼錯誤?謝謝。