I use this code to push:
push("xxxx", 3);
function push($deviceToken, $badge) {
$message = "C'è il vento ideale!!";
$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);
}
But this is the error:
Warning: stream_socket_client() [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages: error:14094414:SSL routines:SSL3_READ_BYTES:sslv3 alert certificate revoked in /xxxx/notify.php on line 75
Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /xxxx/notify.php on line 75
Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2196 (Unknown error) in /xxxxx/notify.php on line 75 Failed to connect 0
The message is explicit : certificate revoked
.
Your certificate is not valid, the certificate is expired or you have clicked on 'revoke' the certificate in the Apple portal.
You may generate a new certificate for this appId, and install it on your server.
精彩评论