-
-
Save samvermette/759564 to your computer and use it in GitHub Desktop.
<?php | |
$apnsHost = 'gateway.sandbox.push.apple.com'; | |
$apnsCert = 'apns-dev.pem'; | |
$apnsPort = 2195; | |
$streamContext = stream_context_create(); | |
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert); | |
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext); | |
$payload['aps'] = array('alert' => 'Oh hai!', 'badge' => 1, 'sound' => 'default'); | |
$output = json_encode($payload); | |
$token = pack('H*', str_replace(' ', '', $token)) | |
$apnsMessage = chr(0) . chr(0) . chr(32) . $token . chr(0) . chr(strlen($output)) . $output; | |
fwrite($apns, $apnsMessage); | |
socket_close($apns); | |
fclose($apns); |
@andreszs, i m getting "undefined error" can you help what is the issue ?
got some errors
Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) in /customers/d/b/3/server.com/httpd.www/app/apn-server.php on line 18 Warning: fwrite() expects parameter 1 to be resource, boolean given in /customers/d/b/3/server.com/httpd.www/app/apn-server.php on line 19 Warning: fclose() expects parameter 1 to be resource, boolean given in /customers/d/b/3/server.com/httpd.www/app/apn-server.php on line 20
Can anyone suggest what's wrong with this server.
If there is any restrictions from server then let me know what should I do.
i am getting fwrite(): send of 92 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. this error please help me.
I am getting same errors as you @bhavin-chauhan. Did you manage to get this issue fixed?
Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) in /home/mandin/public_html/vadmin2/send_broadcast_dev.php on line 17
Warning: pack(): Type H: illegal hex digit h in /home/mandin/public_html/vadmin2/send_broadcast_dev.php on line 34
Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/mandin/public_html/vadmin2/send_broadcast_dev.php on line 35
Warning: fclose() expects parameter 1 to be resource, boolean given in /home/mandin/public_html/vadmin2/send_broadcast_dev.php on line 42
Warning: Cannot modify header information - headers already sent by (output started at /home/mandin/public_html/vadmin2/send_broadcast_dev.php:42) in /home/mandin/public_html/vadmin2/common.php on line 977
Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/mandin/public_html/vadmin2/send_broadcast_dev.php on line 35
Warning: fclose() expects parameter 1 to be resource, boolean given in /home/mandin/public_html/vadmin2/send_broadcast_dev.php on line 42
Can anyone help please???
I am getting same errors as you @bhavin-chauhan. Did you manage to get this issue fixed?
Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) in /home/mandin/public_html/vadmin2/send_broadcast_dev.php on line 17
Warning: pack(): Type H: illegal hex digit h in /home/mandin/public_html/vadmin2/send_broadcast_dev.php on line 34Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/mandin/public_html/vadmin2/send_broadcast_dev.php on line 35
Warning: fclose() expects parameter 1 to be resource, boolean given in /home/mandin/public_html/vadmin2/send_broadcast_dev.php on line 42
Warning: Cannot modify header information - headers already sent by (output started at /home/mandin/public_html/vadmin2/send_broadcast_dev.php:42) in /home/mandin/public_html/vadmin2/common.php on line 977
Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/mandin/public_html/vadmin2/send_broadcast_dev.php on line 35
Warning: fclose() expects parameter 1 to be resource, boolean given in /home/mandin/public_html/vadmin2/send_broadcast_dev.php on line 42
Can anyone help please???
My Server not allow me to open APN Port number, So Finally I've Used Firebase service for that task. It's easy to use and both android, iOS token can easily work now. Let me know if you need any help from my side.
Thanks!
Bhavin
The previous code has serious flaws with the packaging of bytes, Try this instead:
http://www.kubilayerdogan.net/sample-apple-push-notification-php-script/
Or just update the existing sample with this code, which works just fine: