2016-08-14 39 views
2

我正在使用php服务器在IOS中推送通知,并且我生成了应用程序的证书和密钥,并且我确保从ssl://网关的unblocking端口.sandbox.push.apple.com:2196和2195,但在所有的时间,我得到尝试在这个错误对SSL连接也是我从所有关键文件的权限当尝试通过php文件执行Apple推送通知时出错

Warning: stream_socket_client(): SSL: crypto enabling timeout in /Users/samahahmaed/Desktop/CER/newspush.php on line 24 

Warning: stream_socket_client(): Failed to enable crypto in /Users/samahahmaed/Desktop/CER/newspush.php on line 24 

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Users/samahahmaed/Desktop/CER/newspush.php on line 24 
Failed to connect: 0 

编辑肯定:

当我尝试这个命令时

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushCertificate.pem -key PushKey.pem -CApath /etc/ssl/certs/Entrust_Root_Certification_Authority.pem 

我得到这个错误

CONNECTED(00000003) 
write:errno=54 

php文件:

<?php 

    // Put your device token here (without spaces): 
    $deviceToken = 'mydevicetokenhere'; 

// Put your private key's passphrase here: 
$passphrase = '1234'; 

$message = $argv[1]; 
$url = $argv[2]; 

if (!$message || !$url) 
exit('Example Usage: $php newspush.php \'Breaking News!\' \'https://raywenderlich.com\'' . "\n"); 



$ctx = stream_context_create(); 
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apple_push_notification_production.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', 
    'link_url' => $url, 
); 

    // 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); 

我搜索了很多关于这个问题,我尝试了所有可能的解决方案,但没有任何结果,我现在可以做什么?

编辑:

附加-debug OpenSSL的命令最奇怪的事情后,这些线路: enter image description here

+0

????? :(我试图从这个问题2天没有任何结果,直到现在:(((( –

+0

正如@kerry在他们的答案中提出的,这似乎是一个证书问题。尝试添加'-debug'标志到你的'openssl你可以提供更多的信息来解决你的问题 – Palpatim

+0

@Palpatim正如我对克里所说的那样我试着对开发和生产证书的两种情况以及同样的结果进行了尝试,我更新了我的帖子正如你在添加-debug到openssl命令之后所建议的那样 –

回答

0
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apple_push_notification_production.pem'); 

这行看起来像您正在使用生产许可证连接到沙箱APNS。尝试使用开发证书。您可以从苹果开发人员仪表板获得相同的结果。

+0

我使用了两个没有任何更改错误的情况,我只在这里忘记了这个证书的名称 –