1


まず、ご清聴ありがとうございました。ここでのシナリオは、何千ものデバイスに同じ PUSH 通知を送信する必要があるということです。このトピックに関する Apple のドキュメントを読んでいると、複数の通知をバッチ処理する必要があることがわかりました。理論は明らかですが、実装には疑問があります。

たとえば、私は通常、次の PHP Web サービスを使用して 1 つの通知を送信します。

$deviceToken = 'f9082e0e26fe72f4c9ef04bff33b8274186b51abeecb86e4a4e7ac773081****';
$passphrase = '********';
$message = "Hi, world";
$badge = 2;

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// Open a connection to the APNS server
$fp = stream_socket_client('ssl://gateway.sandbox.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'=>$badge);
$body['mis_parametros'] = array('hora' => date("F j, Y, g:i a"));

// 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 'Message not delivered' . PHP_EOL;
else
    echo 'Message successfully delivered' . PHP_EOL. ' to device token: '. $deviceToken;

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

それらをバッチで送信する方法がわかりません。私は電話する必要があります:

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

次に、deviceToken を変更して再度呼び出します

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

そして最後に、すべての通知の後、APNs 呼び出しへの接続を閉じます ??

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

皆さんの答えを待っています。このコードが、通常の PUSH 通知を送信するためにサーバー側を実装している人々にも役立つことを願っています。前もって感謝します!!

4

0 に答える 0