Notifications Apple推送通知脚本不工作
我正在使用这个php脚本,但它的输出消息已成功传递,但未发送通知。我已经检查了设备id和证书,它们是完美的,可以与另一个脚本配合使用Notifications Apple推送通知脚本不工作,notifications,push,Notifications,Push,我正在使用这个php脚本,但它的输出消息已成功传递,但未发送通知。我已经检查了设备id和证书,它们是完美的,可以与另一个脚本配合使用 <?php // Put your device token here (without spaces): $deviceToken = 'fbf04bf4ace2f1e823016082da3a798cf3ab666ae99a395b65e364eb4c6d6d4a'; // Put your private key's pass
<?php
// Put your device token here (without spaces):
$deviceToken = 'fbf04bf4ace2f1e823016082da3a798cf3ab666ae99a395b65e364eb4c6d6d4a';
// Put your private key's passphrase here:
$passphrase = '123';
// Put your alert message here:
$message = 'A push notification has been sent!';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'key.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client('ssl://gateway.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' => array('body' => $message, 'action-loc-key' => 'Look', ), 'badge' => 2, 'sound' => 'oven.caf', );
// 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));
echo "<pre>Result : ";
print_r($result);
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
?>
我在第一次启动iOS推送通知时遇到类似的问题
您可能正在进行开发推动,而不是生产推动
将服务器更改为ssl://gateway.sandbox.push.apple.com:2195 并使用开发推送通知键进行尝试
这就解决了我的问题我想你必须更改端口号
您的代码:ssl://gateway.push.apple.com:2195.
2195
用于沙箱,而2196
用于现场
你能换一下试试吗
希望这能奏效。点击此链接。也许这会帮助你解决问题。谢谢,但苹果设备终端的阿里·哈菲兹吉关注点。。。他对服务器端一无所知。为什么不试试这个===,它肯定和我刚才做的一样有效。