<?PHP $deviceToken = "myDeviceToken"; $message = "Hello from server"; $badge = 1; $sound = "default"; // Construct the notification payload $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','my.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); ?>
从浏览器调用时我收到:
[13-Dec-2011 18:52:52] PHP 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 /home/srv/public_html/myTest.PHP on line 28[13-Dec-2011 18:52:52] PHP Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /home/srv/public_html/myTest.PHP on line 28
[13-Dec-2011 18:52:52] PHP Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandBox.push.apple.com:2195 (Unknown error) in /home/srv/public_html/myTest.PHP on line 28
知道发生了什么事吗?
>这可能是证书问题.尝试使用流选项allow_self_signed和verify_peer来检查它.>尝试使用explicitely sslv2://或sslv3://?>“/ dev / urandom”上的权限问题