【问题标题】:APNS not working anymore on PHPAPNS 不再适用于 PHP
【发布时间】:2014-07-25 23:42:21
【问题描述】:

几天前,APNS 服务运行良好。唯一改变的是我将服务器从 Ubuntu 12.10 升级到 13.04。升级后我的 apns 停止工作。我不知道为什么,但这是我在服务器上唯一更改的内容。

我还尝试使用从我的 mac 生成的证书远程登录 gateway.push.apple.com:2195 一切正常。

但是当我尝试将我的服务器与 php 代码一起使用时,我得到了这个响应:

连接失败:0

          <?php

  // Put your device token here (without spaces):
  $deviceToken = 'bd218fb8ce00xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

      // Put your private key's passphrase here:
    $passphrase = 'xxxxxxxxxxxxxxxxxxxx';

    // Put your alert message here:
      $message = 'My first push notification!';

    ////////////////////////////////////////////////////////////////////////////////

      $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns.pem');
     stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

  // Open a connection to the APNS server
  $fp = stream_socket_client(
      'ssl://gateway.push.apple.com:2195', $err,
        $errstr, 360, 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);

【问题讨论】:

  • 确保您的 pem 文件可以从您的路径访问

标签: php ios xcode ubuntu apple-push-notifications


【解决方案1】:

尝试将正确的证书路径放在 php 脚本中,即。

stream_context_set_option($ctx, 'ssl', 'local_cert',APPPATH.'../assets/apns.pem');

【讨论】:

    【解决方案2】:

    格式化并安装 Ubuntu 14.10 的新副本后,一切顺利。 APNS 再次按预期工作。

    一切都表明升级搞砸了 PHP 或任何配置文件。

    所以教训是不要从终端升级 Ubuntu。

    如果要升级,请先备份所有数据并从光盘或 USB 安装新版本的 Ubuntu。使用所有可能的更新重新安装 LAMP 并恢复所有文件和数据。

    之后一切正常。

    【讨论】:

      猜你喜欢
      • 2013-01-27
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      • 2014-05-08
      • 2017-09-26
      • 1970-01-01
      • 2014-05-17
      • 2019-10-23
      相关资源
      最近更新 更多