开发者

APNS error Warning: stream_socket_client() error

开发者 https://www.devze.com 2023-03-11 04:24 出处:网络
I am working hard on it and openssl is enabled on my server but issue remains as it. Will it make any difference if run it MAc book. Please response if it is done there.

I am working hard on it and openssl is enabled on my server but issue remains as it. Will it make any difference if run it MAc book. Please response if it is done there.

My Code:

<?php
$deviceToken = 'my device key';  // not putting in for security

$payload['aps'] = array('alert' => 'This is the aler开发者_StackOverflowt text', 'badge' => 1, 'sound' => 'default');
$payload = json_encode($payload);

$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';

$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);

$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);

socket_close($apns);
fclose($apns);
?>

Error:

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 F:\xampp\htdocs\apns\apns.php on line 24

Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in F:\xampp\htdocs\apns\apns.php on line 24

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in F:\xampp\htdocs\apns\apns.php on line 24

Please post if any have an idea.

Thanks


I had the same problem. The solution for me was generate the certificate again. I did it with these commands:

openssl x509 -in testpush_aps_development.cer -inform der -out TestPushCert.pem
openssl pkcs12 -nocerts -out TestPushKey.pem -in TestPush.p12

After that:

cat TestPushKey.pem TestPushCert.pem > TestPushCK.pem

Remember that testpush_aps_development.cer in this case is the certificate that you have in your apple developer page in the section APNS Certificates.

Hope this help you, anyway I'm sure it's a problem with the certificates.


Check your certificates, they cause errors quite oftenly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号