2011-05-06 110 views
2

我正在使用推送通知的Iphone應用程序。它以前工作正常,突然停止工作。我的PHP代碼是推送通知APNS突然停止工作 - 沙箱 - 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); 
?> 

我正在連接OK發送消息:{ 「APS」:{ 「警告」: 「測試消息」}}從瀏覽器運行時。有什麼想法可能是錯的嗎?

感謝

回答

0

我的猜測是,你的證書已過期。我有一個過期的開發證書,蘋果公司沒有投訴就接受了這個消息,儘管它沒有到達。當我更新證書時,郵件開始到達。