使用带有apns.php密码的pem


using pem with password for apns - php

如果这是一个基本的问题,但似乎在任何地方都找不到确切的解决方案,我们深表歉意。

有一个用于APNS的php代码设置并正常工作。现在已经获得了受密码保护的生产pem文件。

请说明如何在php中传递密码参数。推送代码如下:

 $apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = GetPemUrl();
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 10, STREAM_CLIENT_CONNECT, $streamContext);
$sent = False;
if ($apns) {
    $apm = fwrite($apns, $apnsMessage);
    if ($apm)
    {
        $sent = true;
    }
    else
    {
        $sent = FALSE;
    }
    //socket_close($apns);
    fclose($apns);
}

co偶然发现了这个解决方案,并正在发布,以防其他人需要它。在流上下文中添加另一个选项:

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($streamContext, 'ssl', 'passphrase', "pem file passphrase"); // simlply add this

以下是完整帖子的链接:

http://learn-php-by-example.blogspot.com/2013/01/working-with-apple-push-notification.html