我开发推送通知的iPhone应用程序,并且当我在本地主机上运行php文件时遇到了错误。我已经正确创建了证书.pem文件。然后当我测试我的本地主机上的应用程序时,会显示警告。PHP上的推送通知错误(iOS上的简单推送通知)
警告:stream_socket_client()[function.stream插槽客户端]:无法设置/应用程序的私有密钥文件'/Applications/XAMPP/xamppfiles/htdocs/PushNotificationProject/ck.pem”/XAMPP/xamppfiles/htdocs中/ PushNotificationProject/simplepush.php第21行
警告:stream_socket_client()[function.stream插槽客户端]:无法创建/应用程序的SSL手柄/ XAMPP/xamppfiles/htdocs中/ PushNotificationProject /simplepush.php on line 21
Warning:stream_socket_client()[functio n.stream-插座客户]:无法使加密在/Applications/XAMPP/xamppfiles/htdocs/PushNotificationProject/simplepush.php第21行
警告:stream_socket_client()[function.stream插座-客户]:无法连接到第21行的/Applications/XAMPP/xamppfiles/htdocs/PushNotificationProject/simplepush.php中的ssl://gateway.sandbox.push.apple.com:2195(未知错误) 未能连接:0
我得到这个错误。什么可能是这个错误的原因?
这是我的PHP代码。
<?php
// Put your device token here (without spaces):
$deviceToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// Put your private key's passphrase here:
$passphrase = 'xxxxxxxxxx';
// Put your alert message here:
$message = 'My first push notification!';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.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',
'badge' => '1'
);
// 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);
?>
请帮我解决这个错误。
你好@Tapas帕尔。谢谢你提醒我。我没有使用我的SSL证书,也许我忘了它。我已经下载了名为:aps_development.cer的文件作为默认文件名。接下来我应该做什么? – Jarich
我认为你已经下载了错误的一个SSL证书扩展名是.pem不是.cer –
我可以在哪里生成SSL证书?我在证书类别下生成它。 – Jarich