1

Appleデバイス向けのプッシュ通知サービスを実装しています。phpスクリプトを使用すると、phpスクリプトがブラウザからヒットした場合にのみプッシュ通知が行われます。ブラウザでサーバーphpスクリプトにアクセスすると、通知がAppleデバイスにプッシュされます。私のphpスクリプトは...

// Apple デバイスで通知を送信するメソッドの終了

function sendNotificationToAppleDevice($token,$message)
    {
    /////////////////////////////////////////////For apple divice////////////////////////////////

$passphrase='1234';
// Create a stream to the server
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', 'sample.pem');
stream_context_set_option($streamContext, 'ssl', 'passphrase', $passphrase);

$apns = stream_socket_client( 'ssl://gateway.sandbox.push.apple.com:2195', $error,$errorString,60,STREAM_CLIENT_CONNECT, $streamContext);

// You can access the errors using the variables $error and $errorString


// Now we need to create JSON which can be sent to APNS
        $inc=0;                  
$load = array(
'aps' => array(
'alert' => $message,
'badge' =>$inc,
)
);
$inc++;
$payload = json_encode($load);
// The payload needs to be packed before it can be sent
$apnsMessage = chr(0) . chr(0) . chr(32);
$apnsMessage .= pack('H*', str_replace(' ', '', $token));
$apnsMessage .= chr(0) . chr(strlen($payload)) . $payload;

// Write the payload to the APNS

fwrite($apns, $apnsMessage);

echo "just wrote " . $payload;

// Close the connection

fclose($apns);
    }

このスクリプトは正常に実行され、このスクリプトがブラウザにヒットすると、通知が正常に送信されます。

スケジュール タスクの cron ジョブからこのスクリプトを実行すると、デバイスに通知が送信されません。それが引き起こした......

警告: stream_socket_client(): SSL 操作がコード 1 で失敗しました。OpenSSL エラー メッセージ: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure in sample.php

警告: stream_socket_client(): オンラインの sample.php で暗号化を有効にできませんでした

警告: stream_socket_client(): ssl://gateway.sandbox.push .apple.com:2195 に接続できません (不明なエラー) ラインの sample.php で

警告: fwrite() は、パラメーター 1 がリソースであると想定しており、オンラインの sample.php で指定されたブール値です。

警告: fclose() は、パラメーター 1 がリソースであると想定しており、オンラインの sample.php で指定されたブール値です。

この関数とエラーの問題は何ですか..誰か助けてください...

前もって感謝します。

4

1 に答える 1