IOS 推送通知在本地有效,但在 bluehost 上无效
IOS Push notifications works locally but not on bluehost
我使用下面的 php 脚本发送推送通知,如果使用“wamp 服务器”从我的本地计算机发送,它工作完美
我现在正在使用 bluehost 服务并购买了专用 ip,他们为我打开了 apns 端口 2195 和 2196
但我总是收到“APNS 连接失败:0”,而同一代码在本地运行完美
有什么帮助吗?提前致谢。
stream_socket_client(): Failed to enable crypto in
/public_html/simplepush.php
stream_socket_client(): unable to connect to
ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in
/public_html/simplepush.php
代码:
<?php
//$tHost = 'gateway.sandbox.push.apple.com';
$tHost = 'gateway.sandbox.push.apple.com';
$tPort = 2195;
// Provide the Certificate and Key Data.
$tCert = 'Key.pem';
$tPassphrase = 'mypasssss';
$tToken = "5d0897edddb84f38b951109dce8b99b7a7c7446d57b78a154f057d47dd878ac2";
$tAlert = 'New news has been added';
$tBadge = 1;
$tSound = 'default';
$tPayload = 'xxx';
$tBody['aps'] = array (
'alert' => $tAlert,
'badge' => $tBadge,
'sound' => $tSound,
);
$tBody ['payload'] = $tPayload;
$tBody = json_encode ($tBody);
$tContext = stream_context_create ();
stream_context_set_option ($tContext, 'ssl', 'local_cert', $tCert);
stream_context_set_option ($tContext, 'ssl', 'passphrase', $tPassphrase);
// Open the Connection to the APNS Server.
$tSocket = stream_socket_client ('ssl://'.$tHost.':'.$tPort, $error, $errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $tContext);
// Check if we were able to open a socket.
if (!$tSocket)
exit ("APNS Connection Failed: $error $errstr" . PHP_EOL);
// Build the Binary Notification.
$tMsg = chr (0) . chr (0) . chr (32) . pack ('H*', $tToken) . pack ('n', strlen ($tBody)) . $tBody;
// Send the Notification to the Server.
$tResult = fwrite ($tSocket, $tMsg, strlen ($tMsg));
if ($tResult)
echo 'Delivered Message to APNS' . PHP_EOL;
else
echo 'Could not Deliver Message to APNS' . PHP_EOL;
// Close the Connection to the Server.
fclose ($tSocket);
?>
遇到这个问题的每个人都去生成一个全新的 .pem 文件,一切都会正常
我使用下面的 php 脚本发送推送通知,如果使用“wamp 服务器”从我的本地计算机发送,它工作完美
我现在正在使用 bluehost 服务并购买了专用 ip,他们为我打开了 apns 端口 2195 和 2196
但我总是收到“APNS 连接失败:0”,而同一代码在本地运行完美
有什么帮助吗?提前致谢。
stream_socket_client(): Failed to enable crypto in /public_html/simplepush.php
stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /public_html/simplepush.php
代码:
<?php
//$tHost = 'gateway.sandbox.push.apple.com';
$tHost = 'gateway.sandbox.push.apple.com';
$tPort = 2195;
// Provide the Certificate and Key Data.
$tCert = 'Key.pem';
$tPassphrase = 'mypasssss';
$tToken = "5d0897edddb84f38b951109dce8b99b7a7c7446d57b78a154f057d47dd878ac2";
$tAlert = 'New news has been added';
$tBadge = 1;
$tSound = 'default';
$tPayload = 'xxx';
$tBody['aps'] = array (
'alert' => $tAlert,
'badge' => $tBadge,
'sound' => $tSound,
);
$tBody ['payload'] = $tPayload;
$tBody = json_encode ($tBody);
$tContext = stream_context_create ();
stream_context_set_option ($tContext, 'ssl', 'local_cert', $tCert);
stream_context_set_option ($tContext, 'ssl', 'passphrase', $tPassphrase);
// Open the Connection to the APNS Server.
$tSocket = stream_socket_client ('ssl://'.$tHost.':'.$tPort, $error, $errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $tContext);
// Check if we were able to open a socket.
if (!$tSocket)
exit ("APNS Connection Failed: $error $errstr" . PHP_EOL);
// Build the Binary Notification.
$tMsg = chr (0) . chr (0) . chr (32) . pack ('H*', $tToken) . pack ('n', strlen ($tBody)) . $tBody;
// Send the Notification to the Server.
$tResult = fwrite ($tSocket, $tMsg, strlen ($tMsg));
if ($tResult)
echo 'Delivered Message to APNS' . PHP_EOL;
else
echo 'Could not Deliver Message to APNS' . PHP_EOL;
// Close the Connection to the Server.
fclose ($tSocket);
?>
遇到这个问题的每个人都去生成一个全新的 .pem 文件,一切都会正常