示例#1
0
 /**
  * Save message in file
  * @param SmsMessageModel $message
  * @return bool
  */
 public function send(MessageInterface $message, $skipErrors = true)
 {
     $this->clearErrors();
     $storePath = $this->getParam('store_path');
     if (empty($storePath)) {
         throw new ConfigurationException(__CLASS__ . ' is not configured properly. Please set "store_path" parameter.');
     }
     $pathChmod = $this->getParam('path_chmod');
     $dir = realpath($storePath);
     if (!is_dir($dir)) {
         if (!mkdir($storePath, $pathChmod, true)) {
             return false;
         }
     }
     $format = $this->getParam('format');
     foreach ($message->getRecipient() as $recipient) {
         $savePath = $storePath . DIRECTORY_SEPARATOR . $this->getFileName($recipient);
         $content = sprintf($format, $recipient, $message->getText());
         $return = file_put_contents($savePath, $content);
         if ($return === false) {
             $errorMsg = sprintf("Error while saving file \"%s\" with SMS message.", $savePath);
             $this->addError(new SendingError($recipient, self::ERROR_NOT_SAVED, $errorMsg));
             if (!$skipErrors) {
                 throw new RuntimeException($errorMsg, self::ERROR_NOT_SAVED);
             }
         }
     }
     return $this->getErrors()->count() > 0;
 }
示例#2
0
 /**
  * Send message through SmsCenter.pl gateway
  * @param SmsMessageModel $message
  * @return bool
  */
 public function send(MessageInterface $message, $skipErrors = true)
 {
     $mobitex = $this->getClient();
     foreach ($message->getRecipient() as $recipient) {
         try {
             $mobitex->sendMessage($recipient, $message->getText());
         } catch (Exception $e) {
             $this->addError(new SendingError($recipient, $e->getCode(), $e->getMessage()));
             if (!$skipErrors) {
                 throw new \RuntimeException($e->getMessage(), $e->getCode());
             }
         }
     }
     return $this->getErrors()->count() === 0;
 }
示例#3
0
 /**
  * Send message
  * @param SmsMessageModel $message
  * @return bool
  */
 public function send(MessageInterface $message, $skipErrors = true)
 {
     $this->clearErrors();
     $command = $this->prepareCommand($message->getText());
     foreach ($message->getRecipient() as $recipient) {
         // execute command
         $command = str_replace('#RECIPIENT#', $recipient, $command);
         $return = 0;
         $output = [];
         exec($command, $output, $return);
         if ($return !== 0) {
             $errorMsg = sprintf("Error while sending message to \"%s\".", $recipient);
             $this->addError(new SendingError($recipient, self::ERROR_NOT_SAVED, $errorMsg));
             if (!$skipErrors) {
                 throw new RuntimeException($errorMsg, self::ERROR_NOT_SAVED);
             }
         }
     }
     return $this->getErrors()->count() === 0;
 }
示例#4
0
 /**
  * Send message through Clickatell.com gateway
  * @param SmsMessageModel $message
  * @return bool
  */
 public function send(MessageInterface $message, $skipErrors = true)
 {
     // check clickatell limit
     if (count($message->getRecipients()) > 600) {
         $this->addError(new SendingError($message->getRecipients(), 'You have excedded provider limit of messages to send in one time.', $message->error));
     }
     $gateway = $this->getClient();
     try {
         $response = $gateway->sendMessage($message->getRecipients(), $message->getText());
         foreach ($response as $message) {
             if ($message->errorCode) {
                 $this->addError(new SendingError($message->destination, $message->errorCode, $message->error));
             }
         }
     } catch (Exception $e) {
         $this->addError(new SendingError('', $e->getCode(), $e->getMessage()));
         if (!$skipErrors) {
             throw new \RuntimeException($e->getMessage(), $e->getCode());
         }
     }
     return $this->getErrors()->count() === 0;
 }
示例#5
0
 /**
  * Send message through infobip.com gateway
  * @param SmsMessageModel $error
  * @return bool
  */
 public function send(MessageInterface $error, $skipErrors = true)
 {
     $sender = $this->getParam('sender');
     $request = $this->getRequest();
     $body = ['from' => $sender, 'to' => $error->getRecipients(), 'text' => $error->getText()];
     $request->setContent(json_encode($body));
     try {
         $client = new Client();
         $response = $client->send($request);
         $status = $response->getStatusCode();
         if ($status !== 200) {
             // OK code
             $error = $this->decodeError($response);
         } else {
             $this->decodeResponse($response);
         }
     } catch (Exception $e) {
         $this->addError(new SendingError(json_encode($body), $e->getCode(), $e->getMessage()));
         if (!$skipErrors) {
             throw new \RuntimeException($e->getMessage());
         }
     }
     return $this->getErrors()->count() === 0;
 }
示例#6
0
 /**
  * Send message through SmsApi.pl gateway
  * @param SmsMessageModel $message
  * @return bool
  */
 public function send(MessageInterface $message, $skipErrors = true)
 {
     $smsapi = new SmsFactory();
     $smsapi->setClient($this->getClient());
     $actionSend = $smsapi->actionSend();
     // Name of the sender must be defined in SMSApi admin panel first.
     // If $sender is set to "ECO", then the ECO SMS will be send
     $sender = $this->getParam('sender');
     if (empty($sender)) {
         throw new ConfigurationException(__CLASS__ . ' is not configured properly. Please set "sender" parameter properly.');
     }
     $actionSend->setSender($sender);
     $actionSend->setText($message->getText());
     foreach ($message->getRecipient() as $recipient) {
         try {
             $actionSend->setTo($recipient);
             // Numer odbiorcy w postaci 48xxxxxxxxx lub xxxxxxxxx
             $response = $actionSend->execute();
             foreach ($response->getList() as $status) {
                 // @see https://www.smsapi.pl/statusy-wiadomosci
                 if (in_array($status->getStatus(), [407, 406, 405, 401, 402])) {
                     $this->addError(new SendingError($status->getNumber(), $status->getStatus(), $status->getError()));
                     if (!$skipErrors) {
                         throw new \RuntimeException($e->getMessage());
                     }
                 }
             }
         } catch (SmsapiException $e) {
             $this->addError(new SendingError($recipient, $e->getCode(), $e->getMessage()));
             if (!$skipErrors) {
                 throw new \RuntimeException($e->getMessage());
             }
         }
     }
     return $this->getErrors()->count() === 0;
 }