gpt4 book ai didi

php - APNS错误警告: stream_socket_client() error

转载 作者:行者123 更新时间:2023-12-03 12:06:33 27 4
gpt4 key购买 nike

我正在努力工作,并且在服务器上启用了openssl,但问题仍然存在。如果运行它的书会不会有任何区别。如果已完成,请回应。

我的代码:

<?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



如果有任何想法请发表。

谢谢

最佳答案

我有同样的问题。对我来说,解决方案是再次生成证书。我用以下命令做到了:

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是您在Apple开发人员页面的APNS证书部分中拥有的证书。

希望这对您有所帮助,无论如何,我确定这是证书问题。

关于php - APNS错误警告: stream_socket_client() error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6265189/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com