function processFeed($feed) { echo "\n<br/>Checking feed: [{$feed->FeedName}] [{$feed->FeedUrl}]"; //load the xml. $feedContents = file_get_contents($feed->FeedUrl); $feedXml = simplexml_load_string($feedContents); //check if its an RSS feed. if (!$feedXml->channel->item) { echo "Is does not appear to be RSS. Atom is not supported for the moment."; return false; } //check for new messages $newItems = array(); foreach ($feedXml->channel->item as $item) { //var_dump($item); //check if message is new $timestamp = strtotime($item->pubDate); $itemDate = date('Y-m-d H:i:s', $timestamp); //echo "<br/>itemDate: {$itemDate} ++ DateLastUpdated: {$feed->DateLastUpdated}"; if ($itemDate <= $feed->DateLastUpdated) { echo "\n<br/>Item is older, skipping. Item Date: [{$itemDate}] < Date Last Updated:[{$feed->DateLastUpdated}] [{$item->title}] "; continue; } //update the dateLastUpdated for the feed DataService::singleton()->updateFeedDateLastUpdated($feed->FeedId, $itemDate); //Add title to list $message = (string) $feed->FeedName . ": " . (string) $item->title; array_push($newItems, $message); //We can only push one item, so this will be it. break; } //update the dateLastChecked for the feed DataService::singleton()->updateFeedDateLastChecked($feed->FeedId); //if nothing found continue if (count($newItems) == 0) { return; } echo "<textarea cols=50 rows=10>"; var_dump($newItems); echo "</textarea>"; //get list of Devices associated to feed. $devices = DataService::singleton()->getFeedDevices($feed->FeedId); //var_dump($devices); //create a new message on the queue for each of them foreach ($devices as $device) { echo "in devices"; //if we are in test mode, only submit to test devices if ($_GET['onlyTestDevices'] == 1 && $device->IsTestDevice == 0) { continue; } //submit the messages to the queue foreach ($newItems as $item) { echo "\n<br/>Message submitted to queue for DeviceId: [{$device->DeviceId}] DeviceNotes: [{$device->DeviceNotes}]"; DataService::singleton()->addMessage($device->CertificateId, $device->DeviceId, $item); } } }
require_once 'classes/DataService.php'; require_once 'classes/Apns.php'; echo "<br/>Started processing message queue"; //get the certificates $certificates = DataService::singleton()->getCertificates(); foreach ($certificates as $certificate) { //get N new messages from queue. We can get more messages on the next schedule echo "<br/>Getting messages for: [{$certificate->CertificateName}]"; //var_dump($certificate); $messagesArray = DataService::singleton()->getMessages($certificate->CertificateId, MessageStatus::UNPROCESSED, 1000); //if no messages for app continue with next if (count($messagesArray) == 0) { continue; } //connect to apple push notification server with the app credentials $certificatePath = $certificateFolder . '/' . $certificate->KeyCertFile; echo $certificatePath; $server = DataService::singleton()->getCertificateServer($certificate->CertificateId, 1); //var_dump($server); $apns = new apns($server->ServerUrl, $certificatePath, $certificate->Passphrase); //send each message foreach ($messagesArray as $message) { //send payload to device $apns->sendMessage($message->DeviceToken, $message->Message, $message->Badge, $message->Sound); //mark as sent DataService::singleton()->setMessageStatus($message->MessageId, 2); } //execute the APNS desctructor so the connection is closed. unset($apns); } echo "<br/>Completed processing messages queue";
## ## This file is part of APNS. ## ## APNS is free software: you can redistribute it and/or modify ## it under the terms of the GNU Lesser General Public License as ## published by the Free Software Foundation, either version 3 of ## the License, or (at your option) any later version. ## ## APNS is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with APNS. If not, see <http://www.gnu.org/licenses/>. ## ## ## $Id: getSubscriptions.php 168 2010-08-28 01:24:04Z Benjamin Ortuzar Seconde $ ## require_once "../config.php"; require_once "../classes/DataService.php"; if (!isset($_REQUEST['certificateId']) || $_REQUEST['certificateId'] == '') { exit("\nParameter not set"); } //Get the certificate object $certificate = DataService::singleton()->GetCertificate($_REQUEST['certificateId']); //var_dump($certificate); //get the subscriptions $subscriptionsArray = DataService::singleton()->getAppSubscriptions($certificate->AppId); //var_dump($subscriptionsArray); echo json_encode($subscriptionsArray);
<div id="main"> <form method="POST" action="" onsubmit="javascript:return confirmSubmit()"> <fieldset> <legend>Push Notifications</legend> <label for="message">Message:</label><br/> <textarea cols="20" rows="4" name="message" id="message"></textarea> <br/> <label for="certificateId">Certificate:</label><br/> <select name="certificateId" id="certificateId"> <?php //get all apps $certificatesArray = DataService::singleton()->getCertificates(); foreach ($certificatesArray as $certificate) { echo "<option value='{$certificate->CertificateId}'>{$certificate->CertificateName}</option>"; } ?> </select> <br/> <!--! subscriptions container--> <div id="subscriptions"> <label for="subscriptionId">Subscription:</label><br/> <select name="subscriptionId" id="subscriptionId"> </select> </div>
require_once 'config.php'; require_once 'classes/DataService.php'; require_once 'classes/Apns.php'; echo "<br/>Started processing Feedback"; //get the certificates $certificates = DataService::singleton()->getCertificates(); foreach ($certificates as $certificate) { //only process apps that have a certificate associated to it. if ($certificate->KeyCertFile == '') { echo "<br/>Certfile not set for App: [{$certificate->CertificateName}]"; continue; } //var_dump($certificate); //connect to feedback server $certificatePath = $certificateFolder . '/' . $certificate->KeyCertFile; $server = DataService::singleton()->getCertificateServer($certificate->CertificateId, 2); $apns = new apns($server->ServerUrl, $certificatePath, $certificate->Passphrase); //get tokens $feedbackTokens = $apns->getFeedbackTokens(); //close connection unset($apns); //print the number of tokens to check for $countTotal = count($feedbackTokens); echo "<br/>There are [{$countTotal}] tokens notified by feedback"; //loop trough the tokens foreach ($feedbackTokens as $feedbackToken) { //only DeActivate devices that where updated before they where removed. Otherwise the user could of installed the app again. DataService::singleton()->setDeviceInactive($feedbackToken['devtoken'], $app->AppId, $feedbackToken['timestamp']); } } echo "<br/>Completed processing Feedback";
<?php require_once 'config.php'; require_once 'classes/DataService.php'; if (!isset($_REQUEST['deviceToken']) || $_REQUEST['deviceToken'] == '') { echo $_REQUEST['deviceToken']; exit("No deviceToken set"); } if (!isset($_REQUEST['appId']) || $_REQUEST['appId'] == '') { echo $_REQUEST['appId']; exit('Not appId set'); } echo "<br/>Registering Device (if it does not exist already)"; DataService::singleton()->RegisterDevice($_REQUEST['deviceToken']); echo "<br/>Enabling Device for App: [{$_REQUEST['appId']}] (if not enabled already)"; DataService::singleton()->setDeviceActive($_REQUEST['deviceToken'], $_REQUEST['appId'], 1); //optional if (isset($_REQUEST['appSubscriptionId'])) { echo "<br/>Registering for Subscription" . $_REQUEST['appSubscriptionId']; DataService::singleton()->updateAppSubscription($_REQUEST['deviceToken'], $_REQUEST['appSubscriptionId'], 1); } if (isset($_REQUEST['feedUrl'])) { echo "\n<br/>Register Feed: {$_REQUEST['feedUrl']} "; $feedId = DataService::singleton()->registerFeed($_REQUEST['feedUrl']); echo "\n<br/>FeedId: {$feedId}"; DataService::singleton()->subscribeDeviceToFeed($_REQUEST['deviceToken'], $_REQUEST['appId'], $feedId, $_REQUEST['feedEnable']); }