APNS连接失败。在mac上工作,不在服务器上。港口是开放的。

时间:2013-12-24 13:24:00

标签: php ios apple-push-notifications

我一直在尝试在我的服务器上发送推送通知但是我收到此错误

警告:stream_socket_client()[function.stream-socket-client]:无法连接到/ home / mialkan / public_html / pushPro中的ssl://gateway.push.apple.com:2195(连接超时)。第15行的PHP 连接失败:110连接超时

这是我的PHP。

<?php
   function sendNotificationiOS ($deviceToken,$message){


 // Put your private key's passphrase here:
  $passphrase = 'passcode';
  $ctx = stream_context_create();
  stream_context_set_option($ctx, 'ssl', 'local_cert', 'ckPro.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, 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);

}
 sendNotificationiOS('devicetoken','first pushNotification')
?>

我安装了Entrust Ca. pem文件在我的mac上正常工作。

0 个答案:

没有答案