I have used this php code
$query = "SELECT * FROM iphone_register";
$result_iphone = mysql_query($query);
$fetres = mysql_num_rows($result_iphone);
while ($rows = mysql_fetch_object($result_iphone)) {
$deviceToken = $rows->device_id;
$passphrase = '******';
$message = 'New Push Notification!';
$badge = 1;
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$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);
}
$body['aps'] = array(
'alert' => 'new notification is arrived',
'body'=> $message,
'badge' => $badge,
'sound' => 'newMessage.wav'
);
$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 'Error, notification not sent' . PHP_EOL;
} else {
echo 'notification sent!' . PHP_EOL;
}
fclose($fp);
When I send push notification to device from server then I got following error.
I try to change the ck.pem
file for solution.
but it's not working. So I don't think so it has problem with ck.pem(Certificate)
file.
Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) in /home/sunstate/public_html/sunstate_api/gcm_message.php on line 55 Failed to connect: 111 Connection refused