利用APNS的feedback返回已卸载应用的Token值,来维护推送列表
应用没有问题的!
密码以及证书都与推送的的一样,只用ssl的服务器换成了 feedback 和端口2196
<?php $passphrase = 'cheshi123'; $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'cheshi_productionck.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); //stream_context_set_option($ctx, 'ssl', 'verify_peer', false); // assume the private key passphase was removed. $fp = stream_socket_client('ssl://feedback.push.apple.com:2196', $error, $errorString, 60, STREAM_CLIENT_CONNECT, $ctx); // Development server is ssl://feedback.sandbox.push.apple.com:2196 if(!$fp){ print "Failed to connect feedback server: $err $errstr\n"; return; }else{ print "Connection to feedback server OK\n"; } print "APNS feedback results\n"; $count1 = 0; $count2 = 0; while ($devcon = fread($fp, 38)){ $count1 ++ ; $arr = unpack("H*", $devcon); $rawhex = trim(implode("", $arr)); $feedbackTime = hexdec(substr($rawhex, 0, 8)); $feedbackDate = date('Y-m-d H:i', $feedbackTime); $feedbackLen = hexdec(substr($rawhex, 8, 4)); $feedbackDeviceToken = substr($rawhex, 12, 64); //print "TIMESTAMP:" . $feedbackDate . "\n"; //print "DEVICE ID:" . $feedbackDeviceToken. "\n\n"; $db->select_db('mobile_app'); $sql = "UPDATE device_token SET status=-1 WHERE token = '$feedbackDeviceToken' LIMIT 1"; $query = $db ->query($sql); if($query){ $count2 ++; } } echo '<br />'; echo 'FeedBack:'. $count1 . '<br />'; echo '关闭成功(status=-1):' . $count2; fclose($fp);