iPhone中的PHP推送通知错误?

时间:2011-10-20 15:30:32

标签: php

我正在让设备注册,但我无法发送推送。 这是我需要与主机配置的端口问题吗?

以下是我的完整错误消息:

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) in /home/content/w/i/s/wiseinmotion/html/appologie/admin/push/push_notify.php on line 90
Connection Failed - iPhone Push Notifications ServerConnection timed out
110

Fatal error: Call to undefined function socket_close() in /home/content/w/i/s/wiseinmotion/html/appologie/admin/push/push_notify.php

这是我的代码,请告诉我哪里放错了一步?

function pushMessage($deviceToken,$message,$app) {
    echo "Sending iPhone Push Notifications to " . $deviceToken . "<br /><br />";
    echo "Your Message: " . $message . "<br />";
    $time = time();
    $apnsHost = 'gateway.push.apple.com'; 
    $apnsPort = 2195;
    $apnsCert = './apns-iclean.pem';
    $streamContext = stream_context_create();
    stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
    $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
    if($apns) {
            $payload = array();
            $payload['aps'] = array('alert' => $message, 'badge' => 1, 'sound' => 'default');
            $payload = json_encode($payload);
            $apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
            fwrite($apns, $apnsMessage);
    } else { 
            echo "Connection Failed - iPhone Push Notifications Server";
            echo $errorString."<br />";
            echo $error."<br />";
    }
    //socket_close($apns);
    fclose($apns);
}

请指导我。

谢谢

1 个答案:

答案 0 :(得分:0)

您正在致命错误消息(socket_close())中指示的PHP文件中调用名为/home/content/w/i/s/wiseinmotion/html/appologie/admin/push/push_notify.php的函数。它没有定义,或者您没有正确访问它。定义该功能或正确访问它,错误应该消失。