我已经正确设置了我的配置文件和应用程序以接收推送通知,但我在使用PHP to send the notification
. 我正在使用如下所述的脚本,但收到此警告:
Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused).
我对这个问题做了很多研究,但不知道如何解决这个问题。任何想法都会非常有帮助。谢谢你们!
<?php
$message=$_POST['message'];
if ($message)
{
$device_token = "TOKEN_HERE";
$payload = '{
"aps": {
"badge": 1,
"alert": "Hello world!",
"sound": "bingbong.aiff"
}
}';
$ctx = stream_context_create();
stream_context_set_option ($ctx, 'ssl', 'local_cert', 'PEM_FILE_HERE' );
stream_context_set_option ($ctx, 'ssl', 'passphrase', 'PASSPHRASE_HERE' );
$fp = stream_socket_client ('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr,
60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print "Failed";
return;
}
else {
print "Sent";
}
$devArray = array();
$devArray[] = $deviceToken;
foreach($devArray as $deviceToken) {
$msg = chr(0) . pack("n",32) . pack ('H*', str_replace(' ', '', $deviceToken)) . pack
("n",strlen($payload)) . $payload . "n";
print "Sending Message :" . $payload . "n";
fwrite($fp,$msg);
}
fclose($fp);
}
?>
<form action="" method="post">
<input type = "text" name = "message">
<input type = "submit" value = "Send Notification">
</form>