繁体   English   中英

Amazon EC2无法在iOS上发送推送通知

[英]Amazon ec2 can't send push notification on ios

我在Amazon EC2,PHP 7中使用以下php代码

<?php
    function sendApplePushNotificationMessage( $data, $message )
    {
        global $notification;
        $apns_settings = $notification['apns_user'];
        $ctx = stream_context_create();
        stream_context_set_option($ctx, 'ssl', 'local_cert', $apns_settings['pemFile']);
        $fp = stream_socket_client('ssl://gateway.'.(($apns_settings['environment'] == $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

        if (!$fp)
        exit("Failed to connect amarnew: $err $errstr" . PHP_EOL);
        echo 'Connected to APNS' . PHP_EOL;
        $body['aps'] = array(
            'alert' => $message,
            'sound' => 'default'
        );
        $payload = json_encode($body+$extra_values);
        $msg = chr(0) . pack('n', 32) . pack('H*', $data['token']) . pack('n', strlen($payload)) . $payload;
        $result = fwrite($fp, $msg, strlen($msg));
        if (!$result)
            echo 'Message not delivered' . PHP_EOL;
        else
            echo 'Message successfully delivered '.$message. PHP_EOL;   
        // Close the connection to the server
        fclose($fp);
    }

当我调用此函数时,出现以下成功消息。

Connected to APNS
Message successfully delivered

当我尝试相同的pem文件和设备令牌进行在线测试时,它可以正常运行,但不能在Amazon ec2上运行

您正在使用APN服务发送推送通知。 它将访问端口21952196以在内部使用TCPSocket发送推送通知。

您的本地系统将可以访问所有端口,因此不会有问题。

默认情况下, EC2实例无权访问这些端口。 您可以在ec2实例security groups允许/打开这些端口。

还允许端口443

编写自己的导致Apple Push Notification的功能的替代方法是使用Amazon Simple Notification Service(SNS)。

Amazon SNS可以将通知推送到iOS,Android,百度,Windows Mobile,Windows桌面和Mac桌面。

请参阅: Apple Push Notification Service入门

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM