php script to send iOS Notifications using api.push.apple.com/3/...
Budget: €8 – €30 EUR
hi, i found a php script that is not working anymore, it was used to send notifications to single devices using gateway.push.apple.com but this system seems to be down..
I have the certificate updated and ready in .pem and .p8 format and the old function looks like this:
function sendNotificationToPushService($certificate, $passphrase, $body, $deviceToken){
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $certificate);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('tls://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if ($fp){
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo '<br>Message not delivered' . PHP_EOL;
else
echo '<br>Message successfully delivered' . PHP_EOL;
echo $result;
fclose($fp);
} else {
echo 'Message was not sent';
}
}
so I need this function in new version to call it with certificate filename, password, deviceToken and the json-body
also I need a clear result if message was sendet or not
I have the certificate updated and ready in .pem and .p8 format and the old function looks like this:
function sendNotificationToPushService($certificate, $passphrase, $body, $deviceToken){
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $certificate);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('tls://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if ($fp){
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo '<br>Message not delivered' . PHP_EOL;
else
echo '<br>Message successfully delivered' . PHP_EOL;
echo $result;
fclose($fp);
} else {
echo 'Message was not sent';
}
}
so I need this function in new version to call it with certificate filename, password, deviceToken and the json-body
also I need a clear result if message was sendet or not