推送通知加密错误

ses*_*360 13 php push-notification laravel

我在PHP Laravel应用程序中使用Push Notifs.我创建了一个pem文件并对其进行了测试.在我的开发机器上使用它时,它正确地推送到移动设备.当我现在将整个项目推送到我的生产服务器,并启动pushnotif调用时,我收到错误:Failed to enable crypto

在生产服务器上是否需要创建特殊的pem文件?我不是在谈论"生产证书"我仍然想使用沙箱进行测试

<?php

namespace App\Helpers;
use Carbon\Carbon;
use Illuminate\Support\Facades\Config;

class PushNotificationHelper {
    public function pushToResponder($deviceToken) {
        // Set device token of mobile device and the passphrase for certification
        $pushToken = $deviceToken;
        $passphrase = Config::get('MFConfig.PushNotificationTest.passPhrase');
        $APNS = Config::get('MFConfig.PushNotificationTest.APNS');

        // Open new context for streaming and set certificate as well as passphrase
        $ctx = stream_context_create();
        stream_context_set_option($ctx, 'ssl', 'local_cert', '../App/Certificates/ck.pem');
        stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
        stream_context_set_option($ctx, 'ssl', 'cafile', '../App/Certificates/entrust_2048_ca.cer');

        // Open connection to APNS
        $fp = stream_socket_client($APNS, $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

        // If no connection could be made then fail with error, otherwise connect
        if (!$fp) {
            exit("Failed to connect: $err, $errstr" . PHP_EOL);
        }

        echo 'Connected to APNS' . PHP_EOL;

        // Create the payload body
        $body['aps'] = array(
            'alert' => "MEDIFAKTOR Einsatz",
            'sound' => 'default'
        );

        // Encode the payload as JSON
        $payload = json_encode($body);

        // Build the binary notification
        $msg = chr(0) . pack('n', 32) . pack('H*', $pushToken) . pack('n', strlen($payload)) . $payload;

        // Send to server
        $result = fwrite($fp, $msg, strlen($msg));

        // If no result is available, the message was not delivered.
        if(!$result) {
            echo 'Message not delivered.' . PHP_EOL;
        } else {
            echo 'Message successfully delivered.' . PHP_EOL;
        }

        // Close connection
        fclose($fp);

    }
}
Run Code Online (Sandbox Code Playgroud)

我用以下方法测试了连接:

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert ck.pem -debug -showcerts -CAfile entrust_2048_ca.cer
Run Code Online (Sandbox Code Playgroud)

并且它返回状态0(ok)我认为这很好吗?但是当我调用我得到的函数时:failed loading cafile stream

Har*_*Geo 4

不确定这一点,但这可能是你在开发环境中的 php 设置。

尝试找到该cacert.pem文件。

如果您使用的是linux系统,可以尝试locate cacert.pem使用终端。

当您找到该位置时,找到该php.ini文件并找到这一行:

;openssl.cafile =

并将其更改为 openssl.cafile=来自locate的路径cacert.pem command或.pem实际所在的位置。

报告进展情况。