Esempio n. 1
0
 public function send(Sms $sms)
 {
     $result = new Result();
     try {
         $actionSend = $this->factory->actionSend();
         $this->setOptions($actionSend, array_merge($this->options, $sms->options));
         $actionSend->setTo($sms->recipient);
         $actionSend->setText($sms->message);
         $response = $actionSend->execute();
         if (isset($this->options['test']) && $this->options['test'] && $this->logger) {
             $this->logger->info(sprintf("Sending sms to %s: '%s'", $sms->recipient, $sms->message));
         }
         if ($response instanceof SMSApi\Api\Response\StatusResponse) {
             foreach ($response->getList() as $status) {
                 if ($status->getError()) {
                     $result->setSuccess(false);
                     $result->setMessage($status->getError());
                 }
             }
         } elseif ($response instanceof SMSApi\Api\Response\ErrorResponse) {
             $result->setSuccess(false);
             $result->setMessage($response->message);
         } else {
             $result->setSuccess(false);
             $result->setMessage("Unrecognized response");
         }
     } catch (SMSApi\Exception\SmsapiException $exception) {
         $result->setMessage(false);
         $result->setMessage($exception->getMessage());
     }
     return $result;
 }
Esempio n. 2
0
 public function testDetails()
 {
     $someMessage = 'test message';
     $sendSms = $this->smsFactory->actionSend()->setTo($this->getNumberTest())->setText($someMessage)->setDetails(true);
     $result = $sendSms->execute();
     $this->assertEquals($someMessage, $result->getMessage());
     $this->assertEquals(strlen($someMessage), $result->getLength());
     $this->assertEquals(1, $result->getParts());
 }
Esempio n. 3
0
 /**
  * Login
  *
  * @return SMSApi\Api\SmsFactory;
  */
 public function login()
 {
     $client = new Client($this->config['login']);
     $client->setPasswordHash(md5($this->config['password']));
     $proxy = null;
     if ($this->config['second_channel']) {
         $proxy = new Native('https://api2.smsapi.pl');
     }
     $smsapi = new SmsFactory($proxy);
     $smsapi->setClient($client);
     return $smsapi;
 }
Esempio n. 4
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;
 }