通知推送ios:通过对等方重置连接

Lui*_*var 5 apple-push-notifications peer connection-reset

我正在尝试为苹果设备做一个通知系统,但是当我尝试在服务器上运行它时,我遇到以下错误:

警告:stream_socket_client():SSL:第30行/home/empresa/public_html/simplepush/push.php中的同行重置连接

警告:stream_socket_client():无法在第30行的/ home/empresa /public_html/push/push.php中启用加密

警告:stream_socket_client():无法连接到第30行的/ home/empresa /public_html/push/push.php中的ssl://gateway.sandbox.push.apple.com:2195(未知错误)无法连接:0

我的代码是这样的:

  <?php
ini_set('display_errors','On'); 
error_reporting(E_ALL);
$deviceToken= 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';      
$passphrase = ' ';
$message = 'my first notification';
////////////////////////////////////////////////////////////////////////////////
$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'
    );

// 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;
// Close the connection to the server
fclose($fp);
Run Code Online (Sandbox Code Playgroud)

可能会发生什么?谢谢.

小智 1

我无法确定特定原因

\n\n

但请确保您没有做以下任何错误的事情:

\n\n
    \n
  • 不要并行建立多个连接。重用相同\n连接或在发送推送\n通知后关闭连接。实际上,服务器对最大并行连接数有限制,一旦达到阈值,\n这可能会给您带来麻烦。Apple还建议保持连接打开,除非\n您知道它会空闲。

    \n\n

    在多个通知中保持与 APN 的连接保持打开状态;不要\xe2\x80\x99t 重复打开和关闭连接。APN 将快速连接和断开连接视为拒绝服务攻击。您应该保持连接处于打开状态,除非您知道它会在很长一段时间内处于空闲状态\xe2\x80\x94,例如,如果您每天只向用户发送一次通知,则每天使用一个新连接是可以的。

  • \n
  • 不要将开发者配置文件令牌发送到 LIVE APNS。将分发和开发应用程序令牌分开。如果您尝试将沙箱令牌发送到 LIVE APNS,\n可能会导致错误,反之亦然。

  • \n
\n\n

源 - APNS - 通知推送 ios:连接被对等 PHP 重置

\n