2011-12-14 72 views
6

声明:因此我发现了许多类似的问题和一些答案,但没有解决我的问题PHP与Apple通知网关的套接字连接失败

我有这个简单的PHP代码:

<?php 
    $deviceToken = "myDeviceToken"; 
    $message = "Hello from server"; 
    $badge = 1; 
    $sound = "default"; 

    // Construct the notification payload 
    $body['aps'] = array(
     'alert' => $message 
    ); 

    if ($badge) { 
     $body['aps']['badge'] = $badge; 
    } 

    if ($sound) { 
     $body['aps']['sound'] = $sound; 
    } 

    /* End of Configurable Items */ 
    $ctx = stream_context_create(); 
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'my.pem'); 

    $fp = stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); 

    if (!$fp) { 
     print "Failed to connect $err $errstrn"; 
     return; 
    } else { 
     print "Connection OK\n"; 
    } 

    $payload = json_encode($body); 
    $msg = chr(0) . pack("n", 32) . pack("H*", str_replace(" ", "", $deviceToken)) . pack("n", strlen($payload)) . $payload; 
    print "sending message :" . $payload . "\n"; 
    fwrite($fp, $msg); 
    fclose($fp); 
?> 

当从浏览器调用我得到:

[13-Dec-2011 18:52:52] PHP Warning: stream_socket_client() [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure in /home/srv/public_html/myTest.php on line 28

[13-Dec-2011 18:52:52] PHP Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /home/srv/public_html/myTest.php on line 28

[13-Dec-2011 18:52:52] PHP Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /home/srv/public_html/myTest.php on line 28

发生了什么事的任何想法?

+0

http://stackoverflow.com/questions/7453015/ios-push-notification-problem-when-using-crontab-scheduler

  • 权限问题 这个链接是上述问题的答案 – 2013-12-30 13:13:05

  • 回答

    8

    从互联网上一些随机的发现,可以帮助:

    1. 这可能是一个证书的问题。试试流选项allow_self_signedverify_peer来检查。

    2. 尝试明确地使用sslv2://sslv3://?上 “的/ dev/urandom的”

    +0

    这是一个证书问题,但比你的要点1更加愚蠢。产生证书的开发者插入了一个未请求的密码,但没有提及他做过。感谢质量指针。 – AsTheWormTurns 2011-12-14 13:07:07