// Push Notification code for IPHONE in PHP
$deviceToken = $users_rows['gcm_regid'];
$passphrase = 'pass1234';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'DrinksterDevelopment.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 120, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
$body['aps'] = array(
// 'alert' => $_GET["message"].'#'.$_GET["type"].'#'.$_GET["deal_id"],
'alert' => $_GET["message"],
'sound' => 'default'
);
$body['other'] = $_GET["type"].'#'.$_GET["deal_id"];
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result_iphone = fwrite($fp, $msg, strlen($msg));
if (!$result_iphone)
$msg_iphone = 'Message not delivered' . PHP_EOL;
else
$msg_iphone = 'Message successfully delivered' . PHP_EOL;
mail('jackbrown00001@gmail.com', 'IOSPushMsgStatus', $msg_iphone);
fclose($fp);
} //if($users_rows['Platform'] == 'Web' OR $users_rows['Platform'] == 'Android')