php - 尝试通过 php 文件执行 Apple 推送通知时出错
<p><p>我正在使用 php 服务器在 IOS 中处理推送通知,并且我生成了应用程序的证书和 key ,我还确保从 ssl://gateway.sandbox.push.apple.com:2196 和2195,但在尝试连接 ssl 时,我总是收到此错误,我也确信来自所有关键文件的许可</p>
<pre><code>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
</code></pre>
<p>已编辑:</p>
<p>当我尝试这个命令时</p>
<pre><code>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
</code></pre>
<p>我收到此错误</p>
<pre><code>CONNECTED(00000003)
write:errno=54
</code></pre>
<p>php 文件:</p>
<pre><code><?php
// Put your device token here (without spaces):
$deviceToken = 'mydevicetokenhere';
// Put your private key's passphrase here:
$passphrase = '1234';
$message = $argv;
$url = $argv;
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);
</code></pre>
<p>我对这个问题进行了很多搜索,并尝试了所有可能的解决方案,但没有任何结果我现在能做什么?</p>
<p>已编辑:</p>
<p>在 openssl 命令中添加 -debug 后最奇怪的是以下几行:
<a href="/image/0iAiR.png" rel="noreferrer noopener nofollow"><img src="/image/0iAiR.png" alt="enter image description here"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>stream_context_set_option($ctx, 'ssl', 'local_cert','apple_push_notification_production.pem');
</code></pre>
<p>此行看起来您正在使用生产证书连接到沙盒 APNS。尝试使用开发证书。您可以从苹果开发者仪表板中获得相同的信息。</p></p>
<p style="font-size: 20px;">关于php - 尝试通过 php 文件执行 Apple 推送通知时出错,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38945342/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38945342/
</a>
</p>
页:
[1]