2016-07-01 12 views
1

私は私の会社のためのリンゴのアプリケーションを開発しています、私は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/>"; 
    } 

答えて

2

ですが、私は私の問題を発見しました。

  1. 当社のサーバーがAPNSにPUSHメッセージを送信すると、リクエストごとに確認する必要があります。 チェックエラーの後、私はエラーメッセージ8、無効なトークン

  2. 開発用証明書を使用して、ユーザーレジスタは開発アプリケーションを使用している場合は、彼らは トークンデバイスを取得していますが、生産に変更されたとき、あなたは生産証明書を変更する必要がありますを取得しますあなたは、開発のアプリで取得するデバイストークンは、生産証明書で動作しませんので、登録ユーザーは、それが重要欠場する完全に私のミスだ

    ...

プッシュ通知を機能させるために、新たなデバイストークンを取得する必要があります物..

関連する問題