<?php/** * Main method to run the object * $message message content * $deviceToken This is the only token for the iphone (remember to remove the space) * $badge is the app icon in the upper right corner of the number * $sound message sound * $apnsCert Certificate path * $passphrase private key password (can not be written) */public Functi On Iospush ($message, $deviceToken, $badge =1, $sound = ' duck.wav ', $apnsCert, $passphrase) {$body [' aps '] = Array (' Alert ' =& Gt $message); if ($badge) $body [' APs '] [' badge '] = $badge; if ($sound) $body [' APs '] [' sound '] = $sound; $payload = Json_encode ($body); $ctx = Stream_context_create (); Stream_context_set_option ($ctx, ' SSL ', ' Local_cert ', $apnsCert); Stream_context_set_option ($ctx, ' SSL ', ' passphrase ', $passphrase); $fp = stream_socket_client (' ssl://gateway.sandbox.push.apple.com:2195 ', $err, $errstr, $, stream_client_connect, $ CTX); if (! $fp) {print_r (); Print "Failed to connect $err $errstr \ n"; Return } else {PRint $message; Print "Connection ok\n<br/>"; } $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); }?>