我的应用程序中的推送通知有问题。我刚开始使用推送通知,所以我不知道我的问题是什么原因,我在谷歌中找不到解决方案。因此,我使用本教程http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12作为推送通知编程的示例。当我在终端上运行“php simplepush.php”时,一切都很好,我在设备上收到了通知。但是当我在服务器上加载该脚本并尝试从那里运行它时,没有执行任何操作。只有 30 秒的等待和消息“连接失败:110 连接超时”
这是我的脚本的代码
<?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);