发送IOS推送时出错

时间:2015-12-18 07:09:50

标签: ios push-notification apple-push-notifications

错误:

  

警告:stream_socket_client():无法启用加密   第28行/home/####/public_html/####/testpushnotification.php

     

警告:stream_socket_client():无法连接   ssl://gateway.push.apple.com:2195(未知错误)in   第28行的/home/####/public_html/####/testpushnotification.php失败   连接:0

这是我的代码:

$apnsPort = 2195;
$badgecount = 1;

  $streamContext = stream_context_create();
  stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
  $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
   if (!$apns)
   {

  exit("Failed to connect: $error $errorString" . PHP_EOL);
} else
{
    $payload['aps'] = array('alert' => $message,'badge' => $count, 'sound' => 'default');
    $output = json_encode($payload);

   $token = pack('H*', str_replace(' ', '', $deviceToken));

   $apnsMessage = chr(0) . chr(0) . chr(32) . $token . chr(0) . chr(strlen($output)) . $output;
   fwrite($apns, $apnsMessage);

1 个答案:

答案 0 :(得分:0)

您可以参考this教程了解推送通知。检查证书,有一个参考PHP代码文件,您可以检查或使用该文件来检查推送通知。