【问题标题】:Push Notifications APNS suddenly stopped working- sandbox - php推送通知 APNS 突然停止工作-沙盒-php
【发布时间】:2011-05-06 10:04:31
【问题描述】:

我正在开发一个使用推送通知的 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"}}。知道那里可能有什么问题吗?

谢谢

【问题讨论】:

    标签: php notifications push apple-push-notifications


    【解决方案1】:

    我的猜测是您的证书已过期。我有一个过期的开发证书,Apple 只是毫无怨言地接受了该消息,尽管它从未到达。当我更新证书时,消息开始到达。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-10
      • 2014-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多