Ejemplo n.º 1
0
 public function run($args)
 {
     $this->_logger->log(__METHOD__, array('args' => $args));
     if (count($args) < 3) {
         $this->_logger->log(__METHOD__ . ' Too few params.');
         echo 'Expected 3 parameters: [COM_PORT: COM#], [PHONE_NUMBER: ######], [SMS_MESSAGE: string]';
         exit;
     }
     $phpSerial = new PhpSerial($this->_logger);
     $smsSender = new SmsMessageSender($this->_logger, new Listener(), $phpSerial, Yii::app()->params['com_connect_params'], $args[0], $args[1], $args[2]);
     $this->_logger->log(__METHOD__ . ' perform sending', array('serial_port' => $args[0], 'phone_number' => $args[1], 'message' => $args[2]));
     if (!$smsSender->send()) {
         $this->_logger->log(__METHOD__ . ' Errors occured', array('errors' => $smsSender->errors()));
         exit;
     }
 }
Ejemplo n.º 2
0
 /**
  * Send sms commands
  *
  * @param $cycle int
  */
 protected function sendSMSByModem($cycle)
 {
     $this->_logger->log(__CLASS__ . ' ' . __METHOD__, array('cycle' => $cycle));
     // Find unsent sms
     /** @var array|SMSCommand[] $sms_commands */
     $sms_commands = SMSCommand::model()->with('station')->findAllByAttributes(['sms_command_status' => SMSCommand::STATUS_NEW], ['limit' => 5]);
     // Sent sms
     if (isset($sms_commands) && ($count = count($sms_commands))) {
         foreach ($sms_commands as $sms_command) {
             $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' sms_command_id: ' . $sms_command->sms_command_id);
             $sms = new SmsMessageSender($this->_logger, $this->listener, new PhpSerial($this->_logger), Yii::app()->params['com_connect_params'], $this->source, $sms_command->station->phone_number, $sms_command->sms_command_message);
             if ($sms->send()) {
                 $sms_command->sms_command_status = SMSCommand::STATUS_SENT;
                 if (!$sms_command->save()) {
                     $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' sms_command: ' . 'not save! ' . json_encode($sms_command->getErrors()));
                 }
             } elseif ($sms->hasError()) {
                 foreach ($sms->errors() as $error) {
                     $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' error: ' . $error);
                 }
             }
             $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' sms_command_status: ' . $sms_command->sms_command_status);
         }
         $sms_commands_sent = array_filter($sms_commands, function ($sms_command) {
             return $sms_command->sms_command_status == SMSCommand::STATUS_SENT;
         });
         if ($count = count($sms_commands_sent)) {
             ListenerProcess::addComment($this->listener->listener_id, 'sms_command', 'Sending complete. Submitted ' . $count . ' SMS command.
                 SMSCommand ids:' . implode(', ', array_keys(CHtml::listData($sms_commands_sent, 'sms_command_id', 'sms_command_message'))));
         } else {
             ListenerProcess::addComment($this->listener->listener_id, 'sms_command', 'Sending complete. Submitted ' . $count . ' SMS command.');
         }
     }
 }