php iphone推送通知没有达到每个人

时间:2014-05-21 18:41:26

标签: php ios iphone push-notification apple-push-notifications

我有以下代码发送推送通知,但它似乎没有到达每个人,任何想法,请?我看了这里和网上似乎代码是正确的所以我很困惑,特别是我总是得到'消息成功交付'

$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);

0 个答案:

没有答案
相关问题