// require_once('classes/class_DbConnect.php'); // CREATE DATABASE OBJECT ( MAKE SURE TO CHANGE LOGIN INFO IN CLASS FILE ) $db = new DbConnect('localhost', 'codebrew_super', 'core2duo', 'codebrew_naseeb'); //$db->show_errors(); // FETCH $_GET OR CRON ARGUMENTS TO AUTOMATE TASKS $apns = new APNS($db); /** /* ACTUAL SAMPLES USING THE 'Examples of JSON Payloads' EXAMPLES (1-5) FROM APPLE'S WEBSITE. * LINK: http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW15 */ //$id=$_REQUEST['apn_id']; // APPLE APNS EXAMPLE 1 $apns->newMessage(1); $apns->addMessageAlert('Dummy Message received from server'); $apns->addMessageCustom('acme2', array('bang', 'whiz')); $apns->queueMessage(); /* // APPLE APNS EXAMPLE 2 $apns->newMessage(1, '2010-01-01 00:00:00'); // FUTURE DATE NOT APART OF APPLE EXAMPLE $apns->addMessageAlert('Bob wants to play poker', 'PLAY'); $apns->addMessageBadge(5); $apns->addMessageCustom('acme1', 'bar'); $apns->addMessageCustom('acme2', array('bang', 'whiz')); $apns->queueMessage(); // APPLE APNS EXAMPLE 3 $apns->newMessage(1); $apns->addMessageAlert('You got your emails.'); $apns->addMessageBadge(9); $apns->addMessageSound('bingbong.aiff'); $apns->addMessageCustom('acme1', 'bar');
public function send() { $content = trim($_REQUEST['content']); $user_names = trim($_REQUEST['user_names']); if (empty($content)) { $this->error(L('CONTENT_REQUIRE')); } $pids = NULL; if (!empty($user_names)) { $user_names = explode(',', $user_names); $user_names = array_unique($user_names); $condition = array('user_name' => array('in', $user_names), 'status' => 1); $users = D('User')->where($condition)->field('uid')->findAll(); $uids = array(); foreach ($users as $user) { $uids[] = (int) $user['uid']; } if (count($uids) > 0) { $pids = array(); $condition = array('clientid' => array('in', $uids), 'status' => 'active'); $devices = D('ApnsDevices')->where($condition)->field('pid')->findAll(); foreach ($devices as $device) { $pids[] = (int) $devices['pid']; } if (count($pids) == 0) { $this->error(L('UIDS_ERROR2')); } } else { $this->error(L('UIDS_ERROR1')); } } Vendor('common'); require fimport('class/apns'); $apns = new APNS(); $apns->newMessage($pids); $apns->addMessageAlert($content); //$apns->addMessageBadge(2); $apns->addMessageSound('bingbong.aiff'); $apns->queueMessage(); $fp = fsockopen($_SERVER['HTTP_HOST'], 80, &$errno, &$errstr, 5); if ($fp) { $request = "GET " . SITE_URL . "apns.php?process=1 HTTP/1.0\r\n"; $request .= "Host: " . $_SERVER['HTTP_HOST'] . "\r\n"; $request .= "Connection: Close\r\n\r\n"; fwrite($fp, $request); while (!feof($fp)) { fgets($fp, 128); break; } fclose($fp); } $this->success(L('SEND_SUCCESS')); }