0

我按照苹果指南在我的上网本上设置了证书。然后,当我尝试执行推送通知时,我收到此错误:

Warning: stream_socket_client() [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure in xxxx.php on line 92

Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in xxxx.php on line 92

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in xxxx.php on line 92

Failed to connect 0 

这是我的 php 函数:

function push($deviceToken,$badge,$message) {

  $sound = "default";

  // Construct the notification payload
  $body = array();
  $body['aps'] = array("alert" => $message);

  if ($badge)
        $body['aps']['badge'] = $badge;
  if ($sound)
        $body['aps']['sound'] = $sound;

  $ctx = stream_context_create();
  stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev.pem');
  $fp = stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);

  if (!$fp) {
        print "Failed to connect $err $errstrn";
        return;
  } else {
        print "Connection OK\n";
  }

  $payload = json_encode($body);
  $msg = chr(0) . pack('n',32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack('n',strlen($payload)) . $payload;
  print "sending message :" . $payload . "\n";
  fwrite($fp, $msg);
  fclose($fp);

}

我尝试测试苹果网关,但这是我的输出:

$ telnet gateway.sandbox.push.apple.com:2195
Trying 212.48.8.140...
telnet: connect to address 212.48.8.140: Operation timed out
telnet: Unable to connect to remote host

有什么办法解决吗?

编辑:我不确定是否应该在远程服务器上设置证书

已解决: 我的错误是 apns-dev.pem 的路径

4

1 回答 1

0

要么是您的某些东西阻止了它,要么是 Apple 的网关已关闭,要么您需要在访问之前向 Apple 注册您的 IP 地址。请检查这三个:-)

于 2011-11-28T10:45:00.850 回答