consultarNotificacion(); if ($notificacion === null) { $this->stdout("No hay notificaciones pendientes\n"); return; } $this->stdout("Procesando notificación {$notificacion->id}\n"); $params = \Yii::$app->params; $wab = null; if(isset($params["wab"])) { $wab = $params["wab"]; } if($wab === null) { $this->stdout("No existe la configuración\n"); } try { /** @var \app\models\Notificacion $notificacion */ $notificacion->estatus = Notificacion::ESTATUS_ENVIANDO; $notificacion->save(); $notificacionUsuario = NotificacionUsuario::find() ->andWhere(["idNotificacion" => $notificacion->id]); foreach ($notificacionUsuario->each() as $nu) { // if ($nu->telefono !== '6624473145' && $nu->telefono !== '6621564051' && $nu->telefono !== '6621115643'){ // continue; // } $this->stdout("Enviando mensaje a ".$nu->telefono."\n"); /** @var \app\models\NotificacionUsuario $nu */ // $msgTo = "526624473145"; $msgTo = $nu->telefono; if (strlen($nu->telefono) === 10) { $msgTo = "52".$nu->telefono; } $template = "laud_resumen_eventos"; if($nu->plantilla) { $template = $nu->plantilla; } // $template = "informe_de_eventos"; try { $wa = (new Whatsapp()) ->set_access_token($wab["access-token"]) ->msg_from($wab["phone-id"]) ->msg_to($msgTo) ->template($template); foreach ($nu['parametros'] as $param) { $wa->add_body_param($param['text'], $param['type']); } $resultado = $wa->send_template_message(); if($resultado === null) { $this->stdout("Ocurrió un error al enviar el mensaje\n"); return; } $nu->detalle = $resultado; $nu->save(); // $this->stdout("Proceso terminado\n"); } catch (\Exception $e) { $this->stdout("Error al enviar el mensaje: {$e->getMessage()}\n"); } } $notificacion->estatus = Notificacion::ESTATUS_TERMINADO; $notificacion->save(); } catch(\Exception $e) { $notificacion->estatus = Notificacion::ESTATUS_ERROR; $notificacion->detalle = "Ocurrió un error en el servidor al generar la notificación {$e->getMessage()} {$e->getCode()}"; $notificacion->save(); $this->stdout($e->getMessage() . "\n"); } } public function actionFecha() { $domingo = 0; $fecha = strtotime('2023-05-07'); $dia = intval(date("w", $fecha)); if($dia !== $domingo) { $fecha = strtotime('next Sunday'); } $siguienteDomingo = date("Y-m-d", $fecha); $this->stdout("{$siguienteDomingo}\n"); } }