Created
November 28, 2015 16:02
-
-
Save anehkumar/166c465a57c4f864f777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Put your device token here (without spaces): | |
$deviceToken = '<DEVICE_TOKEN>'; | |
$apnsHost = 'gateway.sandbox.push.apple.com'; | |
$apnsCert = 'apns-dev-cert.pem'; | |
$apnsPort = 2195; | |
$apnsPass = '<PASSWORD>'; | |
$token = $deviceToken; | |
$payload['aps'] = array('alert' => 'Oh bilo!', 'badge' => 1, 'sound' => 'default'); | |
$output = json_encode($payload); | |
$token = pack('H*', str_replace(' ', '', $token)); | |
$apnsMessage = chr(0).chr(0).chr(32).$token.chr(0).chr(strlen($output)).$output; | |
$streamContext = stream_context_create(); | |
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert); | |
stream_context_set_option($streamContext, 'ssl', 'passphrase', $apnsPass); | |
$apns = stream_socket_client('ssl://'.$apnsHost.':'.$apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext); | |
fwrite($apns, $apnsMessage); | |
fclose($apns); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment