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

标签 php ios push-notification apple-push-notifications

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

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/

相关文章:

android - 通知图标显示不正确

ios - 在应用程序中收到通知时,PFInstallation 不是最新的

php - Google OAuth JWT 签名验证

php - php 中的消息未打印在浏览器上?

php - OpenAI GPT-3 API 错误 : "You didn' t provide an API key. 您需要使用 Bearer auth 在授权 header 中提供您的 API key ”

php - 如何以编程方式启动 OAuth session ?

ios - 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout

ios - Xamarin 表格 : Have I Covered the bases on iOS Push Notifications?

iphone - iOS:相机 View 可以(应该)是默认 View (可以以模式方式启动其他屏幕)吗?

ios - 用于 Xcode 托管配置文件设置的 Azure Pipelines 配置 - 可能吗?记录在案?