gpt4 book ai didi

php - 尝试通过 php 文件执行 Apple 推送通知时出错

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:58:22 26 4
gpt4 key购买 nike

我正在使用 php 服务器在 IOS 中处理推送通知,我生成了应用程序的证书和 key ,我还确保从 ssl://gateway.sandbox.push.apple.com:2196 和2195 但我一直在尝试连接 ssl 时收到此错误我也确定所有 key 文件的许可

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

我对这个问题进行了很多搜索,并尝试了所有可能的解决方案,但没有任何结果,我现在该怎么办?

编辑:

在 openssl 命令中添加 -debug 之后,最奇怪的是这些行: enter image description here

最佳答案

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

此行看起来您正在使用生产证书连接到沙盒 APNS。尝试使用开发证书。您可以从苹果开发者仪表板获得相同的信息。

关于php - 尝试通过 php 文件执行 Apple 推送通知时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38945342/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com