Created
January 4, 2012 20:00
-
-
Save spangenberg/1561759 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
// Production | |
// APNs Push testen auf Token | |
$deviceToken = "XXX"; | |
// Payload erstellen und JSON codieren | |
$payload['aps'] = array('alert' => 'Hello World!', 'badge' => 1, 'sound' => 'default'); | |
$payload = json_encode($payload); | |
$apnsHost = 'gateway.push.apple.com'; | |
$apnsPort = 2195; | |
$apnsCert = 'aps_production_bundle.pem'; | |
// Stream erstellen | |
$streamContext = stream_context_create(); | |
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert); | |
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext); | |
if ($apns) | |
{ | |
// Nachricht erstellen und senden | |
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload; | |
fwrite($apns, $apnsMessage); | |
// Verbindung schliessen | |
fclose($apns); | |
} | |
else | |
{ | |
echo "Fehler!"; | |
var_dump($error); | |
var_dump($errorString); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment