Server : Apache System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64 User : tradze ( 1001) PHP Version : 8.1.34 Disable Function : NONE Directory : /home/tradze/public_html/public/ |
<?php
//echo $_SERVER['DOCUMENT_ROOT'];die;
// Put your device token here (without spaces):
$deviceToken = '500f744444833172d1ce5d192d5e6934c48175d92f0ca445d6e84575871831f3';
// Put your private key's passphrase here:
$passphrase = 'download';
// Put your alert message here:
//$message = $argv[1];
$message = 'test push message by MSP';
//$url = $argv[2];
$url = 'abc';
if (!$message || !$url)
exit('Example Usage: $php newspush.php \'Breaking News!\' \'https://raywenderlich.com\'' . "\n");
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '/home/appszenlondon/public_html/newdev/public/pushcert_zenlondon.pem');
stream_context_set_option($ctx, 'ssl', '', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'link_url' => $url,
'category' => "NEWS_CATEGORY",
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered "'.$message . PHP_EOL;
// Close the connection to the server
fclose($fp);