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";
<?php

include '../config.php';
class apns extends DB_Mysql
{
    function checkParameters($app_id, $device_token)
    {
        if ($app_id == '' || $device_token == '') {
            $dataDB['Result']['Data'][0]['Status'] = "missing parameters";
            $this->display($dataDB);
            exit;
        }
        $this->InsertToken($app_id, $device_token);
    }
    function display($dataDB)
    {
        echo DB_Mysql::encode($dataDB);
    }
    function InsertToken($app_id, $device_token)
    {
        $query = CLS_MYSQL::Execute("INSERT INTO apns (app_id,device_token) VALUES('{$app_id}','{$device_token}')");
        $dataDB['Result']['Data'][0]['Status'] = $query == true ? "Success" : "Failure";
        $this->display($dataDB);
    }
}
$app_id = $_REQUEST[app_id];
$device_token = $_REQUEST[device_token];
$apns = new apns();
$apns->checkParameters($app_id, $device_token);
Пример #3
0
             }
         }
     }
     //查询设备记录
     $sql = "select pid from " . DB_PREFIX . "apns_devices where 1=1 ";
     if (count($uids) > 0) {
         $sql .= " and clientid in (" . implode(",", $uids) . ") ";
     }
     $sql .= " and pid>" . $last_id . " order by pid asc";
     $pid = intval($GLOBALS['db']->getOne($sql, true));
     if ($pid > 0) {
         //有ID
         //发送过程.....
         require_once APP_ROOT_PATH . "system/libs/apns.php";
         $pids[] = $pid;
         $apns = new apns();
         $apns->newMessage($pids);
         $apns->addMessageAlert($message['content']);
         //$apns->addMessageBadge(2);
         $apns->addMessageSound('bingbong.aiff');
         $apns->queueMessage($message['id']);
         $apns->processQueue();
         //end发送
         $GLOBALS['db']->query("update " . DB_PREFIX . "conf set value = " . intval($pid) . " where name='APNS_MSG_PAGE'");
     } else {
         $GLOBALS['db']->query("update " . DB_PREFIX . "apns_messages set status = 2 where id = " . intval($message['id']));
         $GLOBALS['db']->query("update " . DB_PREFIX . "conf set value = 0 where name='APNS_MSG_PAGE'");
     }
 }
 header("Content-Type:text/html; charset=utf-8");
 echo intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "apns_messages where status <> 2 and send_time <=" . get_gmtime()));
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";