php - stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) -
php - stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) -
i made php file sending notification apple iphone users. working other server not working in server. have made .pem file accurately , opened port number 2195,2196. still not working. please help me out rid of issue. here php code sending force notification:
<?php // set device token here (without spaces): $devicetoken = 'f672c26cbfb279e45c1b66d0ddb738d8043c785d5bb8dd20a72d52ae88d4a604'; // set private key's passphrase here: $passphrase = 'pushchat'; // set alert message here: $message = 'welcome in testing'; $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); // open connection 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 connect: $err $errstr" . php_eol); echo 'connected apns' . php_eol; // create payload body $body['aps'] = array( 'alert' => $message, 'sound' => 'default' ); // encode payload json $payload = json_encode($body); // build binary notification $msg = chr(0) . pack('n', 32) . pack('h*', $devicetoken) . pack('n', strlen($payload)) . $payload; // send server $result = fwrite($fp, $msg, strlen($msg)); if (!$result) echo 'message not delivered' . php_eol; else echo 'message delivered' . php_eol; // close connection server fclose($fp); ?>
i found article while having same issues , problem 2 issues , thought useful here. on ubuntu / php 5.5
test certificates!prompt\#: openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert ./push-crt.pem -key ./push-key.pem -capath ./entrust_root_certification_authority.pem
when found above test realized missing root authorization certificate on server, item 1. 1 time ran above , worked realized library using passed 1 file, more on in item two.
1. root certificateon server did not have right root certificate installed , hence not verify pem file. i'll next. 1 time found page [where entrust root ca pem file?][1] checked , has same problem. assume d/l home folder...
prompt\#: sudo cp ~/entrust_root_certification_authority.pem /usr/local/share/ca-certificates/entrust_root_certification_authority.crt prompt\#: sudo update-ca-certificates
you should see response indicated certificate installed or updated. now, getting somewhere. started different connection error straight related pem file. work with.
2. pem fileif using library mine passes 1 file , passed above test using both cert , key need combine key , cert. me, using sample names above of push-crt.pem
prompt\#: cat push-crt.pem > push.pem prompt\#: echo >> push.pem prompt\#: cat push-key.pem >> push.pem
then used combined key/certificate pair , started work.
phew. hope helps someone.
php ios iphone ssl
Comments
Post a Comment