public function sendPushNotification(PushNotification $notification)
 {
     $email = new Email();
     $email->setFrom($this->getSetting('From'));
     $email->setSubject($this->getSetting('Subject'));
     $email->setBody($notification->Content);
     foreach ($notification->getRecipients() as $recipient) {
         $email->setTo($recipient->Email);
         $email->send();
     }
 }
Esempio n. 2
0
 /**
  * Builds a PushNotification object from the given JSON object
  * @param type $vo_json the JSON representation of the PushNotification
  * @return PushNotification a push notification object
  * @author Rob Kurst <*****@*****.**>
  */
 public static function buildFromJSON($vo_json)
 {
     $o_return = new PushNotification();
     if (array_key_exists("push_notification_type", $vo_json) && $vo_json["push_notification_type"] == "PING") {
         $o_return->setPING();
     }
     if (array_key_exists("push_notification_settlement_batch", $vo_json)) {
         $o_return->setSettlementBatch(SettlementBatch::buildFromJSON($vo_json["push_notification_settlement_batch"]));
     }
     if (array_key_exists("push_notification_bank_account_transaction", $vo_json)) {
         $o_return->setBankAccountTransaction(BankAccountTransaction::buildFromJSON($vo_json["push_notification_bank_account_transaction"]));
     }
     return $o_return;
 }
Esempio n. 3
0
 public function __construct($title = '', $message = '', $destinations = [], $is_link = false, $link_url = '')
 {
     parent::__construct($title, $message, $destinations, include CONFIG . 'pushbullet_key.php');
     $this->is_link_push = $is_link;
     $this->link_url = $link_url;
     $this->url = "https://api.pushbullet.com/v2/pushes";
 }
Esempio n. 4
0
 public function pushNotification(User $user, $message)
 {
     if ($user->device_token === null) {
         return;
     }
     // only support android notifications for now
     PushNotification::app('appNameAndroid')->to($user->device_token)->send($message);
 }
Esempio n. 5
0
 public static function message_push_notification($device_token)
 {
     $error_code = ApiResponse::OK;
     $devices = PushNotification::DeviceCollection(array(PushNotification::Device($device_token, array('badge' => 5))));
     $message = PushNotification::Message('This is message test', array('badge' => 1, 'actionLocKey' => 'Action button title!', 'locKey' => 'localized key', 'custom' => array('custom data' => array('we' => 'want', 'send to app'))));
     $data = PushNotification::app('YineLover')->to($devices)->send($message);
     return $data;
 }
 public function startQueueMessage($devices, $data)
 {
     $deviceCollection = $this->generateDeviceCollection($devices);
     $devices = PushNotification::DeviceCollection($deviceCollection);
     $message = PushNotification::Message($data['message'], array('badge' => 1));
     Queue::push(function ($job) use($devices, $data) {
         //PushNotification::app('appNameIOS')
         //  ->to($devices)
         //  ->send($message);
         $message = '';
         foreach ($devices as $device) {
             $message .= 'sending message(' . $data['message'] . ') to ' . $device->token . ' : ';
         }
         File::append(app_path() . '/queue.txt', $message . PHP_EOL);
         $job->delete();
     });
 }
Esempio n. 7
0
 public static function sendToAllDevices($userId, $message, $prod)
 {
     $deviceTokens = User::getUsersDeviceTokensAsArray($userId);
     $allDelivered = array();
     if (isset($deviceTokens) && is_array($deviceTokens) && count($deviceTokens > 0)) {
         foreach ($deviceTokens as $deviceToken) {
             // save all the results of whether a message was delivered
             $delivered = PushNotification::send($deviceToken, $message, $prod);
             array_push($allDelivered, $delivered);
         }
         // return whether or not pushes to all devices are successful
         return count(array_keys($allDelivered, true)) === count($allDelivered);
     }
     //otherwise, there are no records for that user so return false
     //because no messages were sent
     return false;
 }
Esempio n. 8
0
 public function entregado()
 {
     $envios = Envios::find(Input::get('id'));
     $usuario = UsuariosHD::where('username', '=', Input::get('username'))->first();
     $pedido = Pedidos::where('id', '=', Input::get('id_pedido'))->first();
     $usuario->estatus_u = 'ocupado';
     $usuario->save();
     $reg = Input::get('reg_id');
     if ($reg != "") {
         $valor = PushNotification::Message('¡Tu pedido ha llegado!', array('valor' => 2, 'sound' => 'example.aiff', 'actionLocKey' => 'Action button title!', 'locKey' => 'localized key', 'locArgs' => array('localized args', 'localized args'), 'launchImage' => 'image.jpg', 'custom' => array('custom data' => array('we' => 'want', 'send to app'))));
         PushNotification::app('Tasty')->to($reg)->send($valor);
     }
     $user = User::where('id', '=', $pedido->id_usuario)->first();
     $envios->estatus = 'entregado';
     $envios->save();
     return Response::json('success');
 }
 public function hogarPedidos()
 {
     $pedido = Pedidos::find(Input::get('idpedido'));
     $user = $usuario = User::where('id', '=', $pedido->id_usuario)->first();
     $restaurante = Restaurantes::where('id', '=', $pedido->id_restaurante);
     $var = Auth::user()->id_restaurante;
     $validacion = hd::where('id_restaurante', '=', $var)->get();
     if (Input::has('Confirmar')) {
         $pedido->estatus = 'sinPagar';
         $pedido->save();
         $envios = new Envios();
         $envios->estatus = 'pendiente';
         $envios->id_pedido = $pedido->id;
         $envios->coordenadas_accidente = 0;
         $envios->id_restaurante = $pedido->id_restaurante;
         $envios->save();
         foreach ($validacion as $key2 => $info2) {
             if ($info2->decision == 0) {
                 $reg = UsuariosHD::reg($var)->get();
                 if ($reg != "") {
                     foreach ($reg as $key => $info) {
                         $valor = PushNotification::Message('¡Envíos disponibles!', array('valor' => 1, 'sound' => 'example.aiff', 'actionLocKey' => 'Action button title!', 'locKey' => 'localized key', 'locArgs' => array('localized args', 'localized args'), 'launchImage' => 'image.jpg', 'custom' => array('custom data' => array('we' => 'want', 'send to app'))));
                         PushNotification::app('HappyDelivery')->to($info->reg_id)->send($valor);
                     }
                 }
             }
             if ($info2->decision == 1) {
                 $reg = UsuariosHD::reg2($var)->get();
                 if ($reg != "") {
                     foreach ($reg as $key => $info) {
                         $valor = PushNotification::Message('¡Envíos disponibles!', array('valor' => 1, 'sound' => 'example.aiff', 'actionLocKey' => 'Action button title!', 'locKey' => 'localized key', 'locArgs' => array('localized args', 'localized args'), 'launchImage' => 'image.jpg', 'custom' => array('custom data' => array('we' => 'want', 'send to app'))));
                         PushNotification::app('HappyDelivery')->to($info->reg_id)->send($valor);
                     }
                 }
             }
         }
         return Redirect::to('/')->with('success', 'Orden Aceptada Con Exito');
     } elseif (Input::has('Declinar')) {
         $pedido->estatus = 'declinada';
         $pedido->save();
         return Redirect::to('/')->with('success', 'Orden Cancelada Con Exito');
     }
 }
Esempio n. 10
0
 public function created($model)
 {
     if (Config::get('var.push', false)) {
         $dispositivos = Dispositivo::active()->eventos()->get();
         $disp = [];
         foreach ($dispositivos as $dispositivo) {
             $disp[] = PushNotification::Device($dispositivo->token);
         }
         $devices = PushNotification::DeviceCollection($disp);
         $actions = [];
         $actions[0] = new stdClass();
         $actions[0]->icon = 'eye';
         $actions[0]->title = 'ver';
         $actions[0]->callback = 'mycallback';
         $devices = PushNotification::DeviceCollection($disp);
         $message = PushNotification::Message($model->user->nombre . ' ha agregado un nuevo evento', ['badge' => 1, 'image' => 'www/logo.png', 'soundname' => 'alert', 'title' => 'Nueva Evento', "ledColor" => [0, 146, 234, 255], 'actions' => $actions]);
         $collection = PushNotification::app('android')->to($devices)->send($message);
     }
 }
Esempio n. 11
0
 public function timevaloracion()
 {
     $reg = Input::get('reg_id');
     if ($reg != "") {
         $valor = PushNotification::Message('¡Valora tu pedido!', array('valor' => 1, 'sound' => 'example.aiff', 'actionLocKey' => 'Action button title!', 'locKey' => 'localized key', 'locArgs' => array('localized args', 'localized args'), 'launchImage' => 'image.jpg', 'custom' => array('custom data' => array('we' => 'want', 'send to app'))));
         PushNotification::app('Tasty')->to($reg)->send($valor);
     }
     return Response::json('1');
 }
Esempio n. 12
0
 public static function sendPnsToIOSDevices($device_tokens, $message, $data = null)
 {
     try {
         $i_devices_collection = array();
         foreach ($device_tokens as $device_token) {
             $i_devices_collection[] = \PushNotification::Device($device_token);
         }
         if ($i_devices_collection) {
             $i_devices_collection = \PushNotification::DeviceCollection($i_devices_collection);
             if ($data && is_array($data)) {
                 $message = \PushNotification::Message($message, $data);
             }
             \PushNotification::app(self::$pns_ios_app_name)->to($i_devices_collection)->send($message);
         }
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
Esempio n. 13
0
 public function push()
 {
     Notificacion::InsertarNotificacionesMasivas(Input::get('titulo'), Input::get('mensaje'));
     //Notificaciones en android
     $dispositivos = Dispositivo::active()->mensajes()->get();
     $disp = [];
     foreach ($dispositivos as $dispositivo) {
         $disp[] = PushNotification::Device($dispositivo->token);
     }
     $devices = PushNotification::DeviceCollection($disp);
     $message = PushNotification::Message(Input::get('mensaje'), ['badge' => 1, 'image' => 'www/logo.png', 'soundname' => 'alert', "ledColor" => [0, 146, 234, 255], 'title' => Input::get('titulo'), "style" => "inbox", "summaryText" => "Tienes %n% notificaciones", 'actions' => [["title" => "Abrir", "callback" => "abrir", "foreground" => false]]]);
     $collection = PushNotification::app('android')->to($devices)->send($message);
     // notificaciones en el navegador
     require_once 'vendor/autoload.php';
     Pushpad\Pushpad::$auth_token = '3f31ce907b0008fbde64d2f21399b9c7';
     Pushpad\Pushpad::$project_id = 1211;
     $notification = new Pushpad\Notification(array('body' => Input::get('mensaje', ''), 'title' => Input::get('titulo', 'Residencias Online')));
     $notification->broadcast(['tags' => []]);
     Session::flash('success', 'Mensaje enviado');
     return Redirect::back();
 }
Esempio n. 14
0
<?php

define('ACCESS', true);
require_once __DIR__ . '/../../vendor/autoload.php';
// If you get an error on this line, you need to run `composer update`
require_once __DIR__ . '/../../app/library/SingletonAbstract.php';
// require_once __DIR__.'/../app/helpers/Log.php';
require_once __DIR__ . '/../../app/library/DB.php';
require_once __DIR__ . '/../../app/config/config.php';
require_once __DIR__ . '/../../app/library/User.php';
require_once __DIR__ . '/../../app/library/Campaign.php';
require_once __DIR__ . '/../../app/library/Settings.php';
require_once __DIR__ . '/../../app/helpers/functions.php';
require_once __DIR__ . '/../../app/helpers/_settings.php';
require_once __DIR__ . '/../../app/library/Action.php';
require_once __DIR__ . '/../../app/library/Message.php';
require_once __DIR__ . '/../../app/library/OBCampaign.php';
require_once __DIR__ . '/../../app/library/KickCampaign.php';
require_once __DIR__ . '/../../app/library/Analytics.php';
require_once __DIR__ . '/../../app/library/PushNotification.php';
$userId = 40;
// change whether to send through development or production APNS server
// depends on how you built/installed the app
// make sure you have the appropriate ck.pem file with the
// correct certificates/private keys for production or development
$sendThroughProd = false;
$result = PushNotification::sendToAllDevices($userId, "Hullo", $sendThroughProd);
error_log(print_r($result, true));
error_log(gettype($result));
Esempio n. 15
0
//         'badge' => 1,
//         'sound' => 'example.aiff',
//         'locArgs' => array(
//             'u1' => 3,
//             'u2' => 2,
//             'mid' => 7,
//         ),
//     ));
//     // send push
//     $send = PushNotification::app('appNameIOS')
//         ->to('84271d42284100e0e53c35f9cd2656bdbd2dc2afe8c0eb3dc83e786080d23878')
//         ->send($message);
//     /*$send = PushNotification::app('appNameIOS')
//     ->to('7d1195ae9b14d962dde3f383bdefb4cfafce2dfd4e57a308556647906d8860e0')
//     ->send(); */
//     dd($send);
//     if($send)
//         echo('Sent!');
//     else
//         echo('Not sent!');
// });
Route::get('testing-push-ios', function () {
    $send = PushNotification::app('appNameIOS')->to('75f7abe210345a4201efdb71c4351fd4cdd02f1077f6226eaf797bd35ef6d007')->send('Dummy push, from server');
    dd($send);
});
Route::get('testing-push-android', function () {
    $send = PushNotification::app('appNameAndroid')->to('APA91bH3PY1qGMsLIJ-lJMOETw3OZGbjBxhQM0BwKdNQZ_Ym1hSapbOmqpwBmOePZYaVF-AZVSZa8EluFdc1KXDWfebx2p50iRbshCcxyNjJoiNXnGqbZKuOZTfPB5Q9Rr3emw9shTGK')->send('Dummy push, from server');
    dd($send);
});
// Test S3 image upload
Route::post('api/test_s3_upload', array('uses' => 'ApiController@testS3Upload', 'as' => 'api.testS3Upload'));
Esempio n. 16
0
/**
 * (ES)
 * 
 * Archivo de ejemplo para mostrar como enviar notificaciones push a dispositivo iOS y Android
 *
 * (EN)
 * 
 * Sample file to show how send push notifications to iOS & Android devices.
 * 
 */
/**
* Requerimos el archivo de la clase y creamos el objeto PushNotification();
* Require file class.pushmobile.php and create new object PushNotification();
*/
require_once '../src/class.pushmobile.php';
$push = new PushNotification();
/**
* Enviar notificación push a dispositivo iOS, método:
* Send push notification to iOS device, method:
* 
* Set:
* $device_token (required)
* $message (required)
* $args (optional)
*/
$device_token = "123456abcd";
$message = "Hola, soy una alerta push a iOS";
$args = array();
$push->ios($device_token, $message, $args);
/**
* Enviar notificación push a dispositivo Android, mediante Google Cloud Messaging.
Esempio n. 17
0
 /**
  * creates a push notification from the passed in string
  * 
  * @param type $vs_json the passed in string
  * @return the push notification
  * @author Rob Kurst <*****@*****.**>
  */
 public function handlePushNotification($vs_json)
 {
     $triple_des = new TripleDESService($this->is_key);
     $o_json = $triple_des->decrypt($vs_json);
     $o_json = trim($o_json, "..");
     $o_json = json_decode($o_json, TRUE);
     if (array_key_exists("push_notification_type", $o_json) && $o_json["push_notification_type"] == PushNotification::$XS_PN_TYPE_JSON) {
         $o_return = JSONPushNotification::buildFromJSON($o_json);
     } else {
         $o_return = PushNotification::buildFromJSON($o_json);
     }
     return $o_return;
 }
Esempio n. 18
0
Route::resource('/crm/mail_setting', 'MailSettingController');
Route::resource('/crm/permission_pos_type', 'PermPosTypeSettingController');
Route::resource('/crm/system_icon', 'SystemIconController');
// Post Routes ------------------------------------------------------------------------------------->
Route::resource('/crm/post', 'PostController');
// Notification Routes ------------------------------------------------------------------------------------->
Route::resource('/crm/notification', 'NotificationController');
// API Routes Start ------------------------------------------------------------------------------------->
Route::group(array('prefix' => '/api/v1'), function () {
    Route::post('login', 'Api\\v1\\LoginApiController@login');
    Route::post('get_posts', 'Api\\v1\\PostApiController@getPosts');
    Route::post('get_post', 'Api\\v1\\PostApiController@getPost');
    Route::post('new_post', 'Api\\v1\\PostApiController@newPost');
    Route::post('like_post', 'Api\\v1\\PostApiController@likePost');
    Route::post('unlike_post', 'Api\\v1\\PostApiController@unlikePost');
    Route::post('get_notifications', 'Api\\v1\\NotificationApiController@getNotifications');
    Route::post('post_comment', 'Api\\v1\\CommentApiController@postComment');
    Route::post('get_comments', 'Api\\v1\\CommentApiController@getComments');
});
// API Routes End ------------------------------------------------------------------------------------->
/*Start Test Routes*/
Route::post('/test/pns', function () {
    $deviceToken = Input::get('device_token');
    PushNotification::app('l5fAndroid')->to($deviceToken)->send('Hello World, i`m a push message');
});
Route::post('/test/artisan', function (Request $request) {
    $command = $request->get('command');
    $exitCode = Artisan::call($command, ['--force' => true]);
    return $exitCode;
});
/*End Test Routes*/
 function buildArrayResponse($json)
 {
     $pushListObject = array();
     $channelList = array();
     $jsonObj = new JSONObject($json);
     $jsonObjApp42 = $jsonObj->__get("app42");
     $jsonObjResponse = $jsonObjApp42->__get("response");
     $jsonObjPush = $jsonObjResponse->__get("push");
     if ($jsonObjPush instanceof JSONObject) {
         $pushObj = new PushNotification();
         $pushObj->setChannelList($channelList);
         $this->buildObjectFromJSONTree($pushObj, $jsonObjPush);
         if ($jsonObjPush->has("channels")) {
             $jsonPushChannels = $jsonObjPush->__get("channels");
             if ($jsonPushChannels->__get("channel") instanceof JSONObject) {
                 // Only One attribute is there
                 $jsonObjchannel = $jsonPushChannels->__get("channel");
                 $channelList1 = new Channel($pushObj);
                 $this->buildObjectFromJSONTree($channelList1, $jsonObjchannel);
             } else {
                 // There is an Array of attribute
                 $jsonObjChanelArray = $jsonPushChannels->getJSONArray("channel");
                 for ($i = 0; $i < count($jsonObjChanelArray); $i++) {
                     // Get Individual Attribute Node and set it into Object
                     $jsonObjChannelLi = $jsonObjChanelArray[$i];
                     $channelListObj = new Channel($pushObj);
                     $jsonObjChann = new JSONObject($jsonObjChannelLi);
                     $this->buildObjectFromJSONTree($channelListObj, $jsonObjChann);
                 }
             }
         }
         $pushObj->setStrResponse($json);
         $pushObj->setResponseSuccess($this->isRespponseSuccess($json));
         array_push($pushListObject, $pushObj);
     } else {
         $pushJSONArray = $jsonObjResponse->getJSONArray("push");
         for ($i = 0; $i < count($pushJSONArray); $i++) {
             $pushObject = new PushNotification();
             $pushObject->setChannelList($channelList);
             $pushJSONObj = $pushJSONArray[$i];
             $pushJSONObject = new JSONObject($pushJSONObj);
             $this->buildObjectFromJSONTree($pushObject, $pushJSONObject);
             if ($pushJSONObject->has("channels")) {
                 $jsonPushChannelss = $pushJSONObject->__get("channels");
                 if ($jsonPushChannelss->has("channel")) {
                     if ($jsonPushChannelss->__get("channel") instanceof JSONObject) {
                         // Only One attribute is there
                         $jsonObjchannelA = $jsonPushChannelss->__get("channel");
                         $channelListObject = new Channel($pushObject);
                         $this->buildObjectFromJSONTree($channelListObject, $jsonObjchannelA);
                     } else {
                         // There is an Array of attribute
                         $jsonObjChanelArray = $jsonPushChannelss->getJSONArray("channel");
                         for ($i = 0; $i < count($jsonObjChanelArray); $i++) {
                             // Get Individual Attribute Node and set it into Object
                             $jsonObjChannelList = $jsonObjChanelArray[$i];
                             $channelList2 = new Channel($pushObject);
                             $jsonObjChannel = new JSONObject($jsonObjChannelList);
                             $this->buildObjectFromJSONTree($channelList2, $jsonObjChannel);
                             //   $pushObj->setChannelList($channelList);
                         }
                     }
                 }
             }
             $pushObject->setStrResponse($json);
             $pushObject->setResponseSuccess($this->isRespponseSuccess($json));
             array_push($pushListObject, $pushObject);
         }
     }
     return $pushListObject;
 }
Esempio n. 20
0
 function send_pn_action()
 {
     $helper_obj = new Helper();
     if ($helper_obj->user_is_logged_in() && $helper_obj->check_role(SUPER_ADMIN_ROLE_ID)) {
         $db_functions_obj = new DbFunctions();
         $cid = $_POST['add_client'];
         $msg = $_POST['msg'];
         $client_info = $db_functions_obj->get_client_by_id($cid);
         $tokens = $db_functions_obj->get_tokens($cid);
         define("GOOGLE_API_KEY", $client_info->api);
         // Place your Google API Key
         include_once 'includes/classes/GCM.php';
         $gcm = new GCM();
         foreach ($tokens as $token) {
             $user_token = $token->token;
             $type = $token->type;
             //ios
             if ($type == 1) {
                 $pn_obj = new PushNotification();
                 $pn_obj->push_notification($msg, $user_token, 2, $client_info->pem);
             } else {
                 if ($type == 2) {
                     $m = array("message" => $msg);
                     $deviceId[] = $user_token;
                     $result = $gcm->send_notification($deviceId, $m);
                 }
             }
         }
         exit;
     }
 }
Esempio n. 21
0
 /**
  * Builds a PushNotification object from the given JSON object
  * @param type $vo_json the JSON representation of the PushNotification
  * @return PushNotification a push notification object
  * @author Rob Kurst <*****@*****.**>
  */
 public static function buildFromJSON($vo_json)
 {
     $o_return = new PushNotification();
     if (array_key_exists("push_notification_type", $vo_json) && $vo_json["push_notification_type"] == "PING") {
         $o_return->setPING();
     }
     if (array_key_exists("push_notification_type", $vo_json) && $vo_json["push_notification_type"] == "INCOMING CHARGEBACK") {
         if (array_key_exists("push_notification_chargeback", $vo_json)) {
             $o_return->setIncomingChargeback(Chargeback::buildFromJSON($vo_json["push_notification_chargeback"]));
         }
     }
     if (array_key_exists("push_notification_settlement_batch", $vo_json)) {
         $o_return->setSettlementBatch(SettlementBatch::buildFromJSON($vo_json["push_notification_settlement_batch"]));
     }
     if (array_key_exists("push_notification_bank_account_transaction", $vo_json)) {
         $o_return->setBankAccountTransaction(BankAccountTransaction::buildFromJSON($vo_json["push_notification_bank_account_transaction"]));
     }
     if (array_key_exists("push_notification_id", $vo_json)) {
         $o_return->setID($vo_json["push_notification_id"]);
     }
     return $o_return;
 }
Esempio n. 22
0
 public function cargarCobros()
 {
     $mes = Input::get('mes');
     $año = Input::get('año');
     foreach (Residencias::all() as $residencia) {
         $solvencia = Solvencia::firstorNew(['mes' => $mes, 'año' => $año, 'residencia_id' => $residencia->id]);
         $solvencia->estado = 3;
         $solvencia->monto = getdeuda($residencia->id, $mes, $año);
         $solvencia->save();
     }
     Notificacion::InsertarNotificacionesMasivas("Nuevo Recibo Agregado", "Se ha agregado el recibo de " . getMeses()[$mes] . $año);
     Session::flash('success', "Cobros cargados Correctamente");
     if (Config::get('var.push', false)) {
         $dispositivos = Dispositivo::active()->mensajes()->get();
         $disp = [];
         foreach ($dispositivos as $dispositivo) {
             $disp[] = PushNotification::Device($dispositivo->token);
         }
         $devices = PushNotification::DeviceCollection($disp);
         $message = PushNotification::Message("Se ha agregado el recibo de " . getMeses()[$mes] . $año, ['badge' => 1, 'image' => 'www/logo.png', 'soundname' => 'alert', "ledColor" => [0, 146, 234, 255], 'title' => 'Nueva Recibo Agregado']);
         $collection = PushNotification::app('android')->to($devices)->send($message);
     }
     return Redirect::to('admin/Finanzas/gestion?mes=' . $mes . '&año=' . $año);
 }
Esempio n. 23
0
 public function pushWords($words)
 {
     function implode_r($glue, array $arr)
     {
         $ret = '';
         foreach ($arr as $piece) {
             if (is_array($piece)) {
                 $ret .= '; ' . implode_r($glue, $piece);
             } else {
                 $ret .= $glue . $piece;
             }
         }
         return $ret;
     }
     $users = User::where('device', '<>', '')->with('subscriptions')->get();
     $rawdevices = $users->filter(function ($user) {
         return $user->subscriptions->count() > 0;
     })->map(function ($user) {
         return PushNotification::Device($user->device, ['badge' => 1]);
     });
     dd($rawdevices->toArray());
     $devices = PushNotification::DeviceCollection($rawdevices);
     PushNotification::app('IOS')->to($devices)->send("Пора знакомится с новыми словами", ["custom" => ["cdata" => $words, "type" => 1]]);
     $this->info('Pushed wordcards');
     $this->info(implode_r(', ', $words));
 }
Esempio n. 24
0
 private static function mobile_debug_push(\ApiParam $params)
 {
     $udid = $params->udid;
     $apiKey = $params->api_key;
     $deviceToken = $params->deviceToken;
     $action = $params->action ?: "info";
     $title = $params->title ?: "<" . $action . "> Pust Test Title 0 1 2 3 4 5 6 7 8 9 10." . " 0 1 2 3 4 5 6 7 8 9 10. 0 1 2 3 4 5 6 7 8 9 10.";
     $title = date('[m-d h:m:s]') . $title;
     $data = $params->data ?: "";
     $data = htmlspecialchars_decode($data);
     $jsonData = json_decode($data, true);
     if (!empty($data) && !is_array($jsonData)) {
         return self::formatResult(403, '"data" 格式错误');
     }
     if (empty($udid) || empty($apiKey)) {
         return self::formatResult(403, '缺少参数 "udid" or "api_key"');
     }
     if ($apiKey != "api_mobile_android" && empty($deviceToken)) {
         return self::formatResult(403, '缺少参数 "deviceToken"');
     }
     $notificationToken = new \NotificationToken();
     $pushData = null;
     $queryArray = new \AndQuery(new \Query('appType', $apiKey), new \Query('deviceUniqueIdentifier', $udid));
     if ($apiKey != "api_mobile_android") {
         // 非 Android 需要 deviceToken
         $queryArray = new \AndQuery($queryArray, new \Query('deviceToken', $deviceToken));
     }
     $targets = $notificationToken->find($queryArray);
     if (empty($targets)) {
         return self::formatResult(403, 'Push表中无结果');
     } else {
         if (count($targets) > 1) {
             return self::formatResult(403, 'Push表异常,查出多个结果:' . count($targets));
         }
     }
     if (\Cache::getCountNumber('PushTestCount', 24 * 3600) > 100) {
         return self::formatResult(403, '测试超限');
     }
     \PushNotification::sendByTokens($title, $targets, $action, $title, $data);
     return self::formatResult();
 }
Esempio n. 25
0
 public function pushWord($word)
 {
     $word = WordCard::find($word['word_id']);
     DB::table('users')->where('word_id', 0)->update(['word_id' => Setting::first()->word_id]);
     User::where('device', '<>', '')->groupBy('device')->chunk(200, function ($users) use($word) {
         $devices = PushNotification::DeviceCollection($users->map(function ($user) {
             $this->line($user->device);
             return PushNotification::Device($user->device, ['badge' => 1]);
         })->toArray());
         //            foreach ($users as $user) {
         //                $rawdevices[] = PushNotification::Device($user->device, ['badge' => 1]);
         //            }
         //            $devices = PushNotification::DeviceCollection($rawdevices);
         $this->line('Sending chunk of 200...');
         try {
             PushNotification::app('IOS')->to($devices)->send($word->word . " - новое слово для изучения", ["custom" => ["cdata" => [["word_id" => $word->id, "cat_id" => $word->category_id]], "type" => 0]]);
         } catch (Exception $e) {
             $this->error($e);
         }
     });
     $this->info('Dayword ' . $word->word . '(' . $word->id . ') category ' . $word->category_id . ' pushed.');
 }
 public function getSendMessage($device_token = null, $message = null)
 {
     PushNotification::app('featherqAndroid')->to($device_token)->send($message);
 }