私は私の会社のためのリンゴのアプリケーションを開発しています、私はPHPを使用して、サーバー側で働いているAPNS動作していない、SSL壊れたパイプ&悪いライトリトライ
、laravelフレームワークは、APNSにメッセージを送信します。
テスト用に、ハードコードデバイストークンを使用します。 私はそれを私がハードコードする一つのデバイス上で動作させる。
私はapns、機能で要求されたデバイストークンを送信する機能に前進しています。 この関数を呼び出すと、データベースからデバイストークンが取得され、apnsに送信されます。
私はエラー
fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
と
fwrite(): SSL: Broken pipe
を取得し、私は戻って最初のテストのコードを変更するが、それは前のように動作しません。
誰かが私が間違っていたアイデアを持っているのですか、私のリクエストで間違いを犯しましたか?
ノートのためにこれはいくつかの研究の後、私のコード
$apnsServer = 'ssl://gateway.sandbox.push.apple.com:2195';
$privateKeyPassword = 'my_private_key';
$id = $request->input('id');
$message = "message_here";
$userSelected = User::select('device_token')->where('id', $id)->first();
$deviceToken = str_replace(' ', '', $userSelected['device_token']);
$pushCertAndKeyPemFile = $_SERVER['DOCUMENT_ROOT'].'my_certificate.pem';
$stream = stream_context_create();
stream_context_set_option($stream, 'ssl', 'passphrase', $privateKeyPassword);
stream_context_set_option($stream, 'ssl', 'local_cert', $pushCertAndKeyPemFile);
$connectionTimeout = 30;
$connectionType = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
$connection = stream_socket_client($apnsServer, $errorNumber, $errorString, $connectionTimeout, $connectionType, $stream);
if (!$connection){
echo "Failed to connect to the APNS server. Error = $errorString <br/>";
exit;
}else{
echo "Successfully connected to the APNS. Processing...</br>";
}
$messageBody['aps'] = array('alert' => $message, 'sound' => 'default', 'badge' => 1);
$payload = json_encode($messageBody);
$notification = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$wroteSuccessfully = fwrite($connection, $notification, strlen($notification));
if (!$wroteSuccessfully){
echo "Could not send the message<br/>";
} else {
echo "Successfully sent the message<br/>";
}