iOS 推送通知在使用 crontab 调度程序时不起作用

2022-08-30 20:26:44

我已为我的应用实现了示例推送通知服务。

现在我在沙盒环境中进行测试。

当我手动调用PHP脚本以通过APN推送通知时,我收到通知。

当我使用 crontab 编写调度程序来自动传递通知时,我没有得到通知。我收到的邮件错误是:

PHP Warning:  stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure in /Users/aspire/Desktop/SimplePush/simplepush.php on line 21
PHP Warning:  stream_socket_client(): Failed to enable crypto in /Users/aspire/Desktop/SimplePush/simplepush.php on line 21
PHP Warning:  stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Users/aspire/Desktop/SimplePush/simplepush.php on line 21
Failed to connect: 0 

有人可以解释一下问题可能是什么吗?


答案 1

此问题已修复。真正的问题在于我使用的PHP脚本。

在stream_context_set_option的早些时候,我没有包括ck.pem文件的完整路径。给出完整路径后,没有错误。以下是我现在正在使用的代码。

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '/Users/Development/Dev/ck.pem');

其他一些遇到过这个问题的人和他们的讨论是

苹果论坛问题 1

苹果论坛问题 2


答案 2

试试这个代码

    $apnsCert = $_SERVER['DOCUMENT_ROOT'].'/..../..../ck.pem';
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert',$apnsCert);
    stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195',$err,$errstr,60,STREAM_CLIENT_CONNECT,$ctx);

推荐