-
-
Save uno-de-piera/ee6868b84bdaa62a1137a761c15254ab 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 | |
$development = false; | |
$passphrase = ''; //key del .pem | |
//utilizamos el certificado | |
$ctx = stream_context_create(); | |
stream_context_set_option($ctx, 'ssl', 'local_cert', public_path() . '/apns-dev-cert.pem'); //path del .pem | |
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); | |
// Abrimos una conexión con el servidor APNS | |
$host = $development ? 'ssl://gateway.sandbox.push.apple.com:2195' : 'ssl://gateway.push.apple.com:2195'; //distribution or development?? | |
$fp = stream_socket_client( | |
$host, $err, | |
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); | |
//si no hemos podido conectar | |
if (!$fp) | |
exit("" . PHP_EOL); | |
// Creamos los datos de la notificacion | |
$body['aps'] = array( | |
'alert' => $notification->message, | |
'sound' => 'default', | |
'title' => $notification->title | |
); | |
// creamos el payload | |
$payload = json_encode($body); | |
//recorremos todos los tokens y enviamos la notificacion a cada uno de ellos | |
foreach ($iosTokens as $ios_token) { | |
// Build the binary notification | |
$msg = chr(0) . pack('n', 32) . pack('H*', $ios_token) . pack('n', strlen($payload)) . $payload; | |
// envíamos a APNS | |
$result = fwrite($fp, $msg, strlen($msg)); | |
if (!$result) | |
$success = false; | |
} | |
fclose($fp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment