sendApple.php 907 Bytes
<?php 
$message = 'Text to Send';
$badgeCount = 1;
$sound = 'default';
$payload['aps'] = array('alert'=> $message,'badge'=>$badgeCount,'sound'=>$sound);
$payload = json_encode($payload);
$deviceToken = 'cf7800bd 80cfc6bc ed7822b8 76dfc2b6 04a9fd8e 37a987b2 c4f2fd6d 00972736';
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = dirname(__FILE__).'/ck.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext,'ssl', 'local_cert', $apnsCert);
stream_context_set_option($streamContext, 'ssl', 'passphrase', 'yoho');
$apns = stream_socket_client('ssl://'.$apnsHost.':'.$apnsPort,$error,$errorString,
    60,STREAM_CLIENT_CONNECT,$streamContext);
$apnsMessage = chr(0).chr(0).chr(32).pack('H*',str_replace(' ','',$deviceToken))
    .chr(0).chr(strlen($payload)).$payload;
fwrite($apns, $apnsMessage);
fclose($apns);
echo $error.'\n';
echo $errorString;
?>