我有我的应用程序推送通知问题。我刚开始使用推送通知,所以我不知道我的问题是什么原因,我无法在谷歌找到解决方案。 因此,我使用本教程http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12作为推送通知编程的示例。当我在终端上运行“php simplepush.php”时,一切都很好,并且在我的设备上收到通知。但是当我在服务器上加载该脚本并尝试从那里运行时,不会执行任何操作。只有30秒的等待和消息“无法连接:110连接超时”问题与推送通知IPhone
这里OS我的脚本
<?php
Put your device token here (without spaces):
$deviceToken = '***************';
// Put your private key's passphrase here:
$passphrase = '**************';
// Put your alert message here:
$message = 'My first push notification!';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
终端和服务器是否在相同主办?您是否验证过主机可以使用来自主机的SSL连接到gateway.sandbox.push.apple.com?您可能需要在主机上安装SSL证书。 –
对不起,但我不清楚如何检查主机上是否安装了SSL证书。我如何检查它?顺便说一下,我们的主机是由bluehost支持的,bluehost提供安装SSL证书的一个钱?这是你正在谈论的证书吗?还有一件事 - 如果我从'ssl://gateway.sandbox.push.apple.com:2195'通知中删除“sandbox”,那么即使从我的Mac终端上也不会在设备上传递通知。但仍然有一条消息'Message successfully delivered' – NewObjective
如果你已经解决了这个问题,你可以在下面发布解决方案吗?它可能会帮助其他人处理类似的情况。谢谢。 –