如何在生产中发送推送通知?

时间:2013-10-03 19:19:53

标签: php ios notifications apple-push-notifications

我已将应用程序提交到App Store。我使用我的设备生成了一个令牌,并使用以下PHP-Scritp发送它:

$deviceToken = 'b6e03b75f73bb9133c34434a09390e29g12696e8f32b3d29d1dd97a7e0a9adbd';

// Put your private key's passphrase here:
$passphrase = 'Passwort';

// Put your alert message here:
$message = $titel;

////////////////////////////////////////////////////////////////////////////////

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'Zertifikate.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' . PHP_EOL;

// Create the payload body
$body['aps'] = array(
    'alert' => $message,
    'sound' => 'default',
    'badge' => '+1'
    );

// Encode the payload as JSON
$payload = json_encode($body);

// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));

if (!$result)
    echo 'Nachricht wurde nicht zugestellt' . PHP_EOL;
else
    echo 'PUSHH!!' . PHP_EOL;

// Close the connection to the server
fclose($fp);

它说它连接到APNS,结果是积极的。 我不知道该怎么做。我只是在开发中使用相同的代码生成,但我将数据发送到gateway.push.apple.com-Server。

0 个答案:

没有答案