推送通知加密错误 [英] Push Notification Crypto error

查看:102
本文介绍了推送通知加密错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use Push Notifs in my PHP Laravel app. I created a pem file and tested it. When using it on my dev machine, it correctly pushes to the mobile device. When I now push the whole project to my production server, and start the pushnotif call, I get the error: Failed to enable crypto

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

Do I need to create a special pem file while being on production server? And I am not talking about "production certificates" I still want to use the sandbox for testing

<?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);

    }
}

我通过以下方式测试了连接:

I tested the connection with:

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

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

and it returns status 0 (ok) which is fine I think? but when I call the function I get: failed loading cafile stream

推荐答案

对此不确定,但这可能是您在开发环境中的php设置.

Not sure about this, but it might be your php settings in the dev enviroment.

尝试找到cacert.pem文件.

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

If you are using a linux system you can try locate cacert.pem using the terminal.

找到位置后,找到php.ini文件并找到以下行:

When you find the location find the php.ini file and find this line:

;openssl.cafile =

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

and change this to openssl.cafile= path from locate cacert.pem command or the location the .pem is actually located.

报告进展情况.

这篇关于推送通知加密错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆