Ejemplo n.º 1
0
 public function feedback()
 {
     $feedback = new ApnsPHP_Feedback($env, $this->app_cert_path);
     $feedback->connect();
     $error = $feedback->receive();
     $feedback->disconnect();
     return $error;
 }
Ejemplo n.º 2
0
 public function check()
 {
     // Instanciate a new ApnsPHP_Feedback object
     $feedback = new \ApnsPHP_Feedback($this->environment, IosUtils::getTempFileName($this->certificateTempResource));
     $feedback->setLogger($this->logger);
     // Connect to the Apple Push Notification Feedback Service
     $feedback->connect();
     try {
         $aDeviceTokens = $feedback->receive();
     } catch (\Exception $e) {
         throw new PushException('Impossible de recevoir la liste de tokens du Feedback service');
     }
     // Disconnect from the Apple Push Notification Feedback Service
     $feedback->disconnect();
     return $this->getOldTokens($aDeviceTokens);
 }
Ejemplo n.º 3
0
 * Feedback demo
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://code.google.com/p/apns-php/wiki/License
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to aldo.armiento@gmail.com so we can send you a copy immediately.
 *
 * @author (C) 2010 Aldo Armiento (aldo.armiento@gmail.com)
 * @version $Id$
 */
// Adjust to your timezone
date_default_timezone_set('Europe/Rome');
// Report all PHP errors
error_reporting(-1);
// Using Autoload all classes are loaded on-demand
require_once 'ApnsPHP/Autoload.php';
// Instanciate a new ApnsPHP_Feedback object
$feedback = new ApnsPHP_Feedback(ApnsPHP_Abstract::ENVIRONMENT_SANDBOX, 'server_certificates_bundle_sandbox.pem');
// Connect to the Apple Push Notification Feedback Service
$feedback->connect();
$aDeviceTokens = $feedback->receive();
if (!empty($aDeviceTokens)) {
    var_dump($aDeviceTokens);
}
// Disconnect from the Apple Push Notification Feedback Service
$feedback->disconnect();
 function feedback_provider()
 {
     pnfw_log(PNFW_FEEDBACK_PROVIDER_LOG, __("Feedback Provider is running.", 'pnfw'));
     require_once dirname(__FILE__) . '/../libs/ApnsPHP/Abstract.php';
     require_once dirname(__FILE__) . '/../libs/ApnsPHP/Exception.php';
     require_once dirname(__FILE__) . '/../libs/ApnsPHP/Feedback.php';
     require_once dirname(__FILE__) . '/../libs/ApnsPHP/Message.php';
     require_once dirname(__FILE__) . '/../libs/ApnsPHP/Log/Interface.php';
     require_once dirname(__FILE__) . '/../libs/ApnsPHP/Log/Embedded.php';
     require_once dirname(__FILE__) . '/../libs/ApnsPHP/Message/Custom.php';
     require_once dirname(__FILE__) . '/../libs/ApnsPHP/Message/Exception.php';
     require_once dirname(__FILE__) . '/../libs/ApnsPHP/Push.php';
     require_once dirname(__FILE__) . '/../libs/ApnsPHP/Push/Exception.php';
     require_once dirname(__FILE__) . '/../libs/ApnsPHP/Push/Server.php';
     require_once dirname(__FILE__) . '/../libs/ApnsPHP/Push/Server/Exception.php';
     require_once dirname(__FILE__) . '/class-pnfw-apnsphp-logger.php';
     $certificate = get_attached_file(get_option("pnfw_production_ssl_certificate_media_id"));
     $passphrase = get_option("pnfw_production_ssl_certificate_password");
     $environment = ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION;
     if (get_option("pnfw_ios_use_sandbox")) {
         $certificate = get_attached_file(get_option("pnfw_sandbox_ssl_certificate_media_id"));
         $passphrase = get_option("pnfw_sandbox_ssl_certificate_password");
         $environment = ApnsPHP_Abstract::ENVIRONMENT_SANDBOX;
     }
     if (empty($certificate)) {
         pnfw_log(PNFW_FEEDBACK_PROVIDER_LOG, __("iOS SSL certificate is not correctly set.", 'pnfw'));
         return;
     }
     if (empty($passphrase)) {
         pnfw_log(PNFW_FEEDBACK_PROVIDER_LOG, __("iOS SSL certificate password is not correctly set.", 'pnfw'));
         return;
     }
     if (!file_exists($certificate)) {
         pnfw_log(PNFW_FEEDBACK_PROVIDER_LOG, __("iOS SSL Certificate does not exists.", 'pnfw'));
         return;
     }
     try {
         // Instantiate a new ApnsPHP_Feedback object
         $feedback = new ApnsPHP_Feedback($environment, $certificate);
         $feedback->setLogger(new PNFW_ApnsPHP_Logger());
         $feedback->setProviderCertificatePassphrase($passphrase);
         // Connect to the Apple Push Notification Feedback Service
         $feedback->connect();
         // Retrieve devices from Apple Push Notification Feedback Service
         $devices = $feedback->receive();
         // Disconnect from the Apple Push Notification Feedback Service
         $feedback->disconnect();
     } catch (Exception $e) {
         pnfw_log(PNFW_FEEDBACK_PROVIDER_LOG, strip_tags($e->getMessage()));
         return;
     }
     global $wpdb;
     $push_tokens = $wpdb->get_blog_prefix() . 'push_tokens';
     foreach ($devices as &$device) {
         $user_id = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$push_tokens} WHERE os = 'iOS' AND token = %s", $device['deviceToken']));
         $wpdb->delete($push_tokens, array('token' => $device['deviceToken'], 'os' => 'iOS'));
         pnfw_log(PNFW_FEEDBACK_PROVIDER_LOG, sprintf(__("The Feedback Provider removed iOS token of user %s: %s.", 'pnfw'), $user_id, $device['deviceToken']));
         $user = new WP_User($user_id);
         if (in_array(PNFW_Push_Notifications_for_WordPress_Lite::USER_ROLE, $user->roles) && empty($user->user_email)) {
             pnfw_log(PNFW_SYSTEM_LOG, sprintf(__("Automatically deleted the anonymous user %s (%s) since left without tokens.", 'pnfw'), $user->user_login, $user_id));
             if (is_multisite()) {
                 require_once ABSPATH . 'wp-admin/includes/ms.php';
                 if (is_user_member_of_blog($user_id)) {
                     wpmu_delete_user($user_id);
                 }
             } else {
                 wp_delete_user($user_id);
             }
         }
     }
     unset($device);
 }
Ejemplo n.º 5
0
<?php

// include auto-loader
require __DIR__ . '/vendor/autoload.php';
// load configuration
require 'config.inc.php';
// set up our database connection
$db = new PDO(DB_DSN, DB_USER, DB_PASSWORD);
// create an instance of the feedback class
$feedback = new ApnsPHP_Feedback(ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION, APS_CERT_PATH);
$feedback->connect();
// get device tokens from feedback service
$response = $feedback->receive();
// disconnect from feedback service
$feedback->disconnect();
// loop through the response
foreach ($response as $item) {
    // convert and quote the "before" stamp
    $stamp = $db->quote(date('Y-m-d H:i:s', $item['timestamp']));
    // delete it from the database if the token hasn't been updated since the timestamp of the feedback entry
    $db->exec('delete from devices where token=' . $db->quote($item['deviceToken']) . ' and ((created_at < ' . $stamp . ' and updated_at is null) or (updated_at < ' . $stamp . '))');
}
// done!