无论是php还是 java版本的都提示不能连接服务器网关 有人遇到吗
<?php
$deviceToken = '';//token
$pass = ''; // Passphrase for the private key (ck.pem file)// Get the parameters from http get or from command line
$message = $_GET['message'] or $message = $argv[1] or $message = 'A test message from worldcup';
$badge = (int)$_GET['badge'] or $badge = (int)$argv[2];
$sound = $_GET['sound'] or $sound = $argv[3];// C*****truct the notification payload
$body = array();
$body['aps'] = array('alert' => $message);
if ($badge)
$body['aps']['badge'] = $badge;
if ($sound)
$body['aps']['sound'] = $sound;/* End of Configurable Items */
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev.pem');
// assume the private key passphase was removed.
stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);// connect to apns
$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 $errstr\n";
return;
}
else {
print "Connection OK\n<br/>";
}// send message
$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);
?>
提示错误如下:Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 ) in D:\Program Files\VertrigoServ\www\apns.php on line 23Fatal error: Maximum execution time of 30 seconds exceeded in D:\Program Files\VertrigoServ\www\apns.php on line 23换了 javapns推送同样报出不能连接
代码如下:public static void main(String[] args) throws Exception {
try {
  String deviceToken = "";//我的token   PayLoad payLoad = new PayLoad();
  payLoad.addAlert("我的push测试");
  payLoad.addBadge(4);
  payLoad.addSound("default");

  PushNotificationManager pushManager = PushNotificationManager.getInstance();
  pushManager.addDevice("iPad", deviceToken);

  //Connect to APNs
  String host= "gateway.sandbox.push.apple.com";
  int port = 2195;
 // String certificatePath= "/Users/jcjc/Desktop/push_p.p12";
  String certificatePath = "d:\\Cert.p12";
  String certificatePassword= "123qaz";
  pushManager.initializeConnection(host,port, certificatePath,certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);

  //Send Push
  Device client = pushManager.getDevice("iPad");
  pushManager.sendNotification(client, payLoad);
  pushManager.stopConnection();   pushManager.removeDevice("iPad");
 }
 catch (Exception e) {
  e.printStackTrace();
 } }
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
java.net.ConnectException: Connection timed out: connect