/** * 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; }
/** * 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; }
public function __construct(SMSApi\Api\SmsFactory $factory, SMSApi\Client $client, $options = []) { $this->factory = $factory; $this->factory->setClient($client); $this->options = $options; }