Amazon EC2无法在iOS上发送推送通知 [英] Amazon ec2 can't send push notification on ios
问题描述
我在Amazon ec2,php 7中使用以下php代码
I am using below php code in Amazon ec2, php 7
<?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);
}
当我调用此函数时,出现以下成功消息.
when i call this function i got below success message.
Connected to APNS
Message successfully delivered
当我尝试使用相同的pem文件和设备令牌进行在线测试时,它可以正常工作,但 在Amazon ec2上不起作用 .
When i try same pem file and device token to test online then it works properly but not work on Amazon ec2.
推荐答案
您正在使用APN
服务发送推送通知.它将访问端口2195
& 2196
在内部使用TCPSocket
发送推送通知.
You are using APN
service to send push notifications . It will access ports 2195
& 2196
to send push notifications using TCPSocket
internally.
您的本地系统将可以访问所有端口,这样就不会有问题.
Your local system will have access to all ports, then there will be no problem.
EC2
实例无权访问这些端口.您可以在ec2
实例security groups
中允许/打开这些端口.
EC2
instance in default doesn't have access to those ports. You can allow/open those ports in your ec2
instance security groups
.
还允许端口443
.
这篇关于Amazon EC2无法在iOS上发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!