我有以下代码发送推送通知,但它似乎没有到达每个人,任何想法,请?我看了这里和网上似乎代码是正确的所以我很困惑,特别是我总是得到'消息成功交付'
$ctx = stream_context_create();
//stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'local_cert', 'production.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$err = '' ;
$errstr = '';
//$fp = stream_socket_client( 'ssl://gateway.sandbox.push.apple.com:2195', $err,$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
$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' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'type' => $type,
'id' => $id
);
// Encode the payload as JSON
$payload = json_encode($body);
foreach ($devices as $deviceArray) {
$regId = $deviceArray['device_id'];
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $regId ) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
ob_flush();
flush();
}
// Close the connection to the server
fclose($fp);