My app is still in development and I used this tutorial to send iOS Push Notifications using PHP and SSL.
http://www.raywenderlich.com/32960/apple-push-notification-serv
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
$fp = stream_socket_client('tls://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if you work in a localhost environment don't forget download the certification file entrust_2048_ca.cer
Here are a few tips that should can help you figure out:
Go to entrust.net/downloads/root_request.cfm and download entrust_2048_ca.cer
Add following code: stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
Make sure if path is right: '../folder/file/ck.pem' ?
Switch and try both the sandbox and live ssl links.
Switch dev and production pem and try both.
<?php
$message = 'aa_' . rand(10000,99999);
$deviceToken = array(
'xxxxxx'
);
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'passphrase', '111111');
stream_context_set_option($ctx, "ssl", "local_cert", './apns.pem');
$fp = NULL;
$errno = NULL;
$errstr = NULL;
$fp = stream_socket_client("tls://gateway.sandbox.push.apple.com:2195", $errno, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if($fp === FALSE){
exit('error message');
}
$content = array("aps" => array("alert" => $message, "badge" => 4, "sound" => 'default', "code" => 200));
$data = json_encode($content);
foreach ($deviceToken as $token) {
$msg = chr(0) . pack("n", 32) . pack("H*", $token) . pack("n", strlen($data)) . $data;
fwrite($fp, $msg);
fflush($fp);
}
fclose($fp);