【问题标题】:Push Notification Crypto error推送通知加密错误
【发布时间】:2015-06-27 16:46:55
【问题描述】:

我在我的 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);

    }
}

我测试了连接:

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert ck.pem -debug -showcerts -CAfile entrust_2048_ca.cer

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

【问题讨论】:

标签: php laravel push-notification


【解决方案1】:

不确定,但可能是您在开发环境中的 php 设置。

尝试定位 cacert.pem 文件。

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

找到位置后,找到php.ini 文件并找到这一行:

;openssl.cafile =

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

报告进展情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 2023-03-22
    • 2011-05-31
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多