推送通知 APNS 突然停止工作-沙箱-php

发布于 2024-11-05 07:31:26 字数 1448 浏览 2 评论 0原文

我正在开发一个使用推送通知的 iPhone 应用程序。它之前工作正常,但突然停止工作。我的 php 代码是

<?php

$deviceToken = ''; // masked for security reason
// Passphrase for the private key (ck.pem file)
$pass = 'appendit';
// Get the parameters from http get or from command line
$message = $_GET['message'] or $message = $argv[1] or $message = 'Test Message';
$badge = (int)$_GET['badge'] or $badge = (int)$argv[2];
$sound = $_GET['sound'] or $sound = $argv[3];
// Construct the notification payload
$body = array();
$body['aps'] = array('alert' => $message);
if ($badge)
$body['aps']['badge'] = $badge;
if ($sound)
$body['aps']['sound'] = $sound;
/* End of Configurable Items */
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev.pem');
// assume the private key passphase was removed.
 stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
 $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
 if (!$fp) {
 print "Failed to connect $err $errstrn";
 return;
 }
 else {
 print "Connection OK \n";
 }
 $payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
print "sending message :" . $payload . "\n";
fwrite($fp, $msg);
fclose($fp);
?>

我在从浏览器运行时收到 Connection OK 发送消息 :{"aps":{"alert":"Test Message"}} 。知道那里可能出了什么问题吗?

谢谢

I am working on a Iphone app that uses push notification.It was working fine earlier and suddenly stopped working. My php code is

<?php

$deviceToken = ''; // masked for security reason
// Passphrase for the private key (ck.pem file)
$pass = 'appendit';
// Get the parameters from http get or from command line
$message = $_GET['message'] or $message = $argv[1] or $message = 'Test Message';
$badge = (int)$_GET['badge'] or $badge = (int)$argv[2];
$sound = $_GET['sound'] or $sound = $argv[3];
// Construct the notification payload
$body = array();
$body['aps'] = array('alert' => $message);
if ($badge)
$body['aps']['badge'] = $badge;
if ($sound)
$body['aps']['sound'] = $sound;
/* End of Configurable Items */
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev.pem');
// assume the private key passphase was removed.
 stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
 $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
 if (!$fp) {
 print "Failed to connect $err $errstrn";
 return;
 }
 else {
 print "Connection OK \n";
 }
 $payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
print "sending message :" . $payload . "\n";
fwrite($fp, $msg);
fclose($fp);
?>

I am getting Connection OK sending message :{"aps":{"alert":"Test Message"}} while running from browser. Any idea what may be wrong there ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余生共白头 2024-11-12 07:31:26

我的猜测是您的证书已过期。我的开发证书已经过期,苹果公司毫无怨言地接受了这条消息,尽管它从未到达。当我更新证书时,消息开始到达。

My guess is that your certificate has expired. I had an expired dev certificate and Apple just accepted the message without complaint, although it never arrived. When I updated the certificate the messages started arriving.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文