2011-06-07 156 views
1

我正在努力工作,並在我的服務器上啓用openssl,但問題依然存在。如果運行MAc書,它會有什麼區別嗎?如果在那裏完成,請回復。APNS錯誤警告:stream_socket_client()錯誤

我的代碼:

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

$payload['aps'] = array('alert' => 'This is the alert 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); 
?> 

錯誤:

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

請後,如果有任何的想法。

謝謝

+1

問題仍然存在:( – Jarnail 2011-07-05 10:58:49

回答

0

檢查您的證書,他們經常會導致錯誤。

+0

我遇到了同樣的問題,證書應該是正確的(包含證書和私鑰)如果我刪除證書文件,我會得到一個不同的錯誤(無法設置私鑰)。所以這可能不是認證失敗,是嗎? – 2012-07-15 21:11:29

0

我有同樣的問題。我的解決方案是再次生成證書。我用這些命令這樣做是:

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

之後:

cat TestPushKey.pem TestPushCert.pem > TestPushCK.pem 

記住在這種情況下testpush_aps_development.cer是您在部分APNS證書的蘋果開發者頁面有該證書。

希望這對你有幫助,無論如何,我確定這是證書的問題。