http://blog.csdn.net/motian06/article/details/8199247 refer to this blog in exchange for their own device number and password phrase to report such a mistake I was locally tested local Apache opened the OpenSSL
Warning:stream_socket_client () [function.stream-socket-client]: Unable to set local cert chain file ' E:\AppServ\www\ Ceshi/apns-dev.pem '; Check that your Cafile/capath settings include details of the your certificate and its issuer in E:\AppServ\www\ceshi\2.php on Line 25
Warning:stream_socket_client () [Function.stream-socket-client]: Failed to create a SSL handle in E:\AppServ\www\ceshi\ 2.php on line 25
Warning:stream_socket_client () [function.stream-socket-client]: Failed to enable Crypto in E:\AppServ\www\ceshi\2.php On line 25
Warning:stream_socket_client () [function.stream-socket-client]: Unable to connect to ssl:// gateway.sandbox.push.apple.com:2195 (Unknown error) in E:\AppServ\www\ceshi\2.php on line 25
Failed to connect 0
Reply to discussion (solution)
It may be that the path of the APNS-DEV.PEM is wrong, the recommendation and the push file sibling, and, last month, the link of Apple changed to TLS, does not support SSL link
Stream_socket_client (' tls://gateway.push.apple.com:2195 ', $err, $errstr, stream_client_connect| Stream_client_persistent, $ctx);
???? The possibility of the big.
It may be that the path of the APNS-DEV.PEM is wrong, the recommendation and the push file sibling, and, last month, the link of Apple changed to TLS, does not support SSL link
Stream_socket_client (' tls://gateway.push.apple.com:2195 ', $err, $errstr, stream_client_connect| Stream_client_persistent, $ctx);
The. PEM certificate file and the PHP push file are in the same directory, would you like to change this to TLS?
Stream_context_set_option ($ctx, ' SSL ', ' Local_cert ', ' Ck.pem '); Stream_context_set_option ($ctx, ' SSL ', ' passphrase ', $pass);
This is not necessary, just changed the link way
The mobile registration app returns the only Devicetoken$devicetoken = ' xxxxxxxxx ';//ck.pem customs password $pass = ' xxx '; Message content $message = ' A test message! '; /badge I don't know what it is. $badge = 4;//sound I don't know what it is (perhaps the cue tone when I push the message to the phone) $sound = ' default ';//construction of the notification payload (that is, some information contained in the notification) $body = array (); body[' aps ' = Array (' alert ' = = $message);//convert array data to JSON data $payload = Json_encode ($body); Echo strlen ($payload), "\ r \ n ";//The following writing is the death of the wording, generally do not need to modify,//The only thing to modify is: ssl://gateway.sandbox.push.apple.com:2195 This is the sandbox test address, ssl:// GATEWAY.PUSH.APPLE.COM:2195 official release Address $ctx = Stream_context_create (); $pem = DirName (__file__). ' /'.' Apns-dev.pem '; stream_context_set_option ($ctx, ' TLS ', ' Local_cert ', $PEM); Stream_context_set_option ($ctx, ' TLS ', ' passphrase ', $pass); $fp = Stream_socket_client (' tls:// gateway.push.apple.com:2195 ', $err, $errstr, stream_client_connect| Stream_client_persistent, $ctx), if (! $fp) {print "Failed to connect $err $errstr \ n"; return;} else {print "Connection ok\n
";} Send message$msg = chr (0). Pack ("n", 32). Pack (' h* ', Str_replace (', ', $deviceToken)). Pack ("n", strlen ($payload)). $payload;p rint "Sending message:". $payload. "\ n"; Fwrite ($fp, $msg); fclose ($FP);
After the change to TLS or error
This is not necessary, just changed the link way
Thank you for your help. I'll make an error when I change it. php files and. Pem files are also in the same directory
My Code
The mobile registration app returns the only Devicetoken$devicetoken = ' xxxxx ';//ck.pem customs password $pass = ' xxx '; Message content $message = ' A test message! '; /badge I don't know what it is. $badge = 4;//sound I don't know what it is (perhaps the cue tone when I push the message to the phone) $sound = ' default ';//construction of the notification payload (that is, some information contained in the notification) $body = array (); body[' aps ' = Array (' alert ' = = $message);//convert array data to JSON data $payload = Json_encode ($body); Echo strlen ($payload), "\ r \ n ";//The following writing is the death of the wording, generally do not need to modify,//The only thing to modify is: ssl://gateway.sandbox.push.apple.com:2195 This is the sandbox test address, ssl:// GATEWAY.PUSH.APPLE.COM:2195 official release Address $ctx = Stream_context_create (); $pem = DirName (__file__). ' /'.' Apns-dev.pem '; stream_context_set_option ($ctx, ' SSL ', ' Local_cert ', $PEM); Stream_context_set_option ($ctx, ' SSL ', ' passphrase ', $pass); $fp = Stream_socket_client (' tls:// gateway.push.apple.com:2195 ', $err, $errstr, stream_client_connect| Stream_client_persistent, $ctx), if (! $fp) {print "Failed to connect $err $errstr \ n"; return;} else {print "Connection ok\n
";} Send message$msg = chr (0). Pack ("n", 32). Pack (' h* ', Str_replace (', ', $deviceToken)). Pack ("n", strlen ($payload)). $payload;p rint "Sending message:". $payload. "\ n"; Fwrite ($fp, $msg); fclose ($FP);
The error of the report
Warning:stream_socket_client () [function.stream-socket-client]: Unable to set private key file ' D:\clientweb\demo\ Apns-dev.pem ' in D:\clientweb\demo\y.php on line 25
Warning:stream_socket_client () [Function.stream-socket-client]: Failed to create a SSL handle in D:\clientweb\demo\ y.php on line 25
Warning:stream_socket_client () [function.stream-socket-client]: Failed to enable Crypto in D:\clientweb\demo\y.php on Line 25
Warning:stream_socket_client () [function.stream-socket-client]: Unable to connect to tls://gateway.push.apple.com : 2195 (Unknown error) in D:\clientweb\demo\y.php on line 25
Failed to connect 0
Can you give me a second look?
View Phpinfo () OpenSSL is also a display-enabled
$pem = DirName (__file__). ' /'.' Apns-dev.pem ';
Change to absolute path, such as D:/wamp/www/push/ck.pem try
$pem = DirName (__file__). ' /'.' Apns-dev.pem ';
Change to absolute path, such as D:/wamp/www/push/ck.pem try
You'll get an error if you change to an absolute path.
Warning:stream_socket_client () [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages:error:14094410:ssl routines:SSL3_READ_BYTES:sslv3 alert handshake failure in D:\clientweb\demo\ y.php on line 25
Warning:stream_socket_client () [function.stream-socket-client]: Failed to enable Crypto in D:\clientweb\demo\y.php on Line 25
Warning:stream_socket_client () [function.stream-socket-client]: Unable to connect to tls://gateway.push.apple.com : 2195 (Unknown error) in D:\clientweb\demo\y.php on line 25
Failed to connect 0
Http://zhidao.baidu.com/link?url=OVktep-jhluby3rXTZURF-QcCl4bMY5DWXgdQXhUaTMV08zbvNyRqswL4J0JO46e3iYYMQdUGPw160YQ4ALdUK
I'll check for you if I don't bother.
Http://zhidao.baidu.com/link?url=OVktep-jhluby3rXTZURF-QcCl4bMY5DWXgdQXhUaTMV08zbvNyRqswL4J0JO46e3iYYMQdUGPw160YQ4ALdUK
I'll check for you if I don't bother.
I checked the information, the wood has looked, should not not even on the Apple server reason
with your code, changed after testing, can send, change: Ck.pem and file sibling, link sandbox, their tokens and pass, others have not changed
The mobile registration app returns the only devicetoken$devicetoken = ' xxx ';//hides its own TOKEN//CK.PEM customs Code $pass = ' 123456 '; Message content $message = ' A test message! '; /badge I don't know what it is. $badge = 4;//sound I don't know what it is (perhaps the cue tone when I push the message to the phone) $sound = ' default ';//construction of the notification payload (that is, some information contained in the notification) $body = array (); body[' aps ' = Array (' alert ' = = $message);//convert array data to JSON data $payload = Json_encode ($body); Echo strlen ($payload), "\ r \ n ";//The following writing is the death of the wording, generally do not need to modify,//The only thing to modify is: ssl://gateway.sandbox.push.apple.com:2195 This is the sandbox test address, ssl:// GATEWAY.PUSH.APPLE.COM:2195 official release Address $ctx = Stream_context_create (); $pem = DirName (__file__). ' /'.' Ck.pem '; stream_context_set_option ($ctx, ' SSL ', ' Local_cert ', $PEM); Stream_context_set_option ($ctx, ' SSL ', ' passphrase ', $pass); $fp = Stream_socket_client (' tls:// gateway.sandbox.push.apple.com:2195 ', $err, $errstr, stream_client_connect| Stream_client_persistent, $ctx), if (! $fp) {print "Failed to connect $err $errstr \ n"; return;} else {print "Connection ok\n
";} Send message$msg = chr (0). Pack ("n", 32). Pack (' h* ', Str_replace (', ', $deviceToken)). Pack ("n", strlen ($payload)). $payload;p rint "Sending message:". $payload. "\ n"; Fwrite ($fp, $msg); fclose ($fp);/*35 Connection OK Sending message: {"APS": {"alert": "A Test Message!"}} */
I'm suggesting that your handshake failed, maybe your apns-dev.pem is wrong.
JAM00, thank you for your kind help, I'll try again.