I have developed a script using stream_socket_client()
and it works on my localhost but when I try to use it online (with Fatcow.com web hosting) it won't work. I receive the following error:
Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) in .../send-notification.php on line 18 Failed to connect 111 Connection refused
This is line 18:
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
I know that the password for the .pem file is correct. The question becomes if I can't use this port what do I do? Is there any free service that I can use? I know that port 80 is open.
I've heard that using the curl()
function will work but have been unsuccessful so far.
I would really appreciate getting pointed in the right direction.
Android. Port 443 (HTTPS only)
Use the location push type for notifications that request a user's location. If you set this push type, the apns-topic header field must use your app's bundle ID with . location-query appended to the end. For more information, see Creating a Location Push Service Extension.
You can fix an iPhone that's not getting notifications by restarting it or making sure notifications are turned on. You should also make sure your iPhone is connected to the internet so apps can receive notifications. If all else fails, you should try resetting the iPhone — just make sure to back it up first.
Check required ports and hostsTCP port 443 or 2197 to send notifications to APNs.
In order to send the notifications to the device need to enable 2195 port in the firewall. For security reasons some organizations disabling these ports in the firewall. 2196 port is used for feedback services and this port also should open in the firewall. Without opening these ports messages cannot deliver to APNS.
I believe the following is what you are looking for
$url = 'https://gateway.sandbox.push.apple.com:2195';
$cert = 'AppCert.pem';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSLCERT, $cert);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "passphrase");
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"device_tokens": ["458e5939b2xxxxxxxxxxx3"], "aps": {"alert": "test message one!"}}');
$curl_scraped_page = curl_exec($ch);
more information can be found here: Apple push notification with cURL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With