apple-push-notifications - 通知推送 ios : Connection reset by peer

标签 apple-push-notifications peer connection-reset

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

Warning: stream_socket_client(): SSL: Connection reset by peer in /home/empresa/public_html/simplepush/push.php on line 30

Warning: stream_socket_client(): Failed to enable crypto in /home/empresa /public_html/push/push.php on line 30

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /home/empresa /public_html/push/push.php on line 30 Failed to connect: 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);

会发生什么?谢谢。

最佳答案

我不能确定一个特定的原因

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

  • 不要并行进行很多连接。要么重复使用相同的
    连接或发送 Push 后关闭连接
    通知。实际上,服务器对最大数量有限制
    并行连接,这可能会给您带来麻烦,一旦您
    达到阈值。苹果还建议保持连接打开,除非
    你知道它会闲置。

    在多个通知中保持与 APNs 的连接;不要反复打开和关闭连接。 APNs 将快速连接和断开连接视为拒绝服务攻击。您应该保持连接打开,除非您知道它会在很长一段时间内处于空闲状态——例如,如果您每天只向用户发送一次通知,那么每天使用一个新连接是可以的。
  • 不要将开发者资料 token 发送到 LIVE APNS。保持
    分发和开发应用程序 token 分开。它可能导致
    错误,如果您尝试将沙箱 token 发送到 LIVE APNS,反之亦然。

  • 来源 - APNS - notifications push ios: Connection reset by peer PHP

    关于apple-push-notifications - 通知推送 ios : Connection reset by peer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31706286/

    相关文章:

    bittorrent - BitTorrent 同行(Deluge)在说什么?

    jakarta-mail - javax.mail.MessagingException : Connection reset while trying to access gmail using java mail API

    tomcat - 对端 : socket write error - cfcontent on Coldfusion 10 重置连接

    iOS 证书 "Push Notification"选项显示为灰色

    ios - 当您的应用程序打开并位于前台时显示一个 iOS 通知横幅?

    ios - 如果用户拒绝推送通知提示的回调方法?

    android - Wi-FI Direct 教程 - PeerListListener 去了哪里?

    javascript - 如何使用 peerjs 连接到主机?

    java - Digital Ocean java服务器不断崩溃: java.net.SocketException:连接重置

    ios - Apple 开发者 APN 角色