gpt4 book ai didi

php - IOS中的推送通知-握手失败

转载 作者:行者123 更新时间:2023-12-01 22:19:42 26 4
gpt4 key购买 nike

每当我尝试发出推送通知时,都会引发多个错误,
我已经研究得很好,但没有解决方案。

1.stream_socket_client():SSL操作失败,代码为1。OpenSSL错误消息:
错误:14094410:SSL例程:SSL3_READ_BYTES:sslv3警报握手失败

--

2.严重程度:警告
消息:stream_socket_client():无法启用加密

--

3.严重程度:警告
消息:stream_socket_client():无法连接到ssl://gateway.sandbox.push.apple.com:2195(未知错误)

--

4.连接失败:0

下面是我的代码:

// Sends Push notification for iOS users
public function iOS($data, $devicetoken)
{
$deviceToken = $devicetoken;
$passphrase= "";
$ctx = stream_context_create();
// ck.pem is your certificate file
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the 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 to connect: $err $errstr" . PHP_EOL);
// Create the payload body
$body['aps'] = array(
'alert' => array(
'title' => $data['mtitle'],
'body' => $data['mdesc'],
),
'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
// Close the connection to the server
fclose($fp);
if (!$result)
return 'Message not delivered' . PHP_EOL;
else
return 'Message successfully delivered' . PHP_EOL;
}

谁能帮我解决问题?

最佳答案

添加以下行

stream_context_set_option( $ctx , 'ssl', 'verify_peer', false); 

如果您在生成pem文件时设置了密码,则必须在下一行中提及它
  $passphrase= "";

如果尚未设置,则由于pem文件而导致此错误。

关于php - IOS中的推送通知-握手失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46238383/

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