/** * @test */ public function wontAddDuplicates() { $message = new SmsMessage('Tussi', 'Lussutaja', ['358503028030', '358503028030']); $this->assertSame(array('358503028030'), $message->getTo()); $message->addTo('358503028030'); $this->assertSame(array('358503028030'), $message->getTo()); }
/** * Generates endpoint URL to send message * * @param SmsMessage $message * * @return string The generated endpoint URL */ private function generateUrl(SmsMessage $message) { $receivers = implode(',', $message->getTo()); $signature = md5($this->account . implode(',', $message->getTo()) . $message->getBody() . $this->password); $sender = rawurlencode($message->getFrom()); $body = rawurlencode($message->getBody()); return $this->endpoint . "?account={$this->account}&signature={$signature}&" . "receivers={$receivers}&sender={$sender}&message={$body}"; }
/** * @test */ public function settersAndGettersShouldWork() { $message = new SmsMessage(); $this->assertNull($message->getFrom()); $this->assertNull($message->getBody()); $this->assertEquals(array(), $message->getTo()); $message->setFrom('Losoposki'); $message->setBody('Ollaanko kavereita?'); $message->addTo('358503028030'); $this->assertEquals('Losoposki', $message->getFrom()); $this->assertEquals('Ollaanko kavereita?', $message->getBody()); $this->assertEquals(array('358503028030'), $message->getTo()); $message->addTo('35850666'); $this->assertEquals(array('358503028030', '35850666'), $message->getTo()); $message->setTo('358503028031'); $this->assertEquals(array('358503028031'), $message->getTo()); }
/** * @see GatewayInterface::send * @todo Implement a smarter method of sending (batch) */ public function send(SmsMessage $message) { $msg = new Message(); $msg->originator = $message->getFrom(); $msg->recipients = $message->getTo(); $msg->body = $message->getBody(); $this->getClient()->messages->create($msg); return true; }
/** * @see GatewayInterface::send * @todo Implement a smarter method of sending (batch) */ public function send(SmsMessage $message) { $body = urlencode(utf8_decode($message->getBody())); $from = urlencode($message->getFrom()); foreach ($message->getTo() as $to) { $url = "{$this->endpoint}/http/sendmsg?api_id={$this->apiKey}&user={$this->user}" . "&password={$this->password}&to={$to}&text={$body}&from={$from}"; $this->getClient()->post($url, array()); } return true; }
/** * @see GatewayInterface::send * @todo Implement a smarter method of sending (batch) */ public function send(SmsMessage $message) { $body = urlencode(utf8_decode($message->getBody())); $from = urlencode($message->getFrom()); foreach ($message->getTo() as $to) { $url = "{$this->endpoint}/xml/sms" . '?gateway=' . urlencode($this->gateway) . '&username='******'&password='******'&originator=' . $from . '&recipients=' . urlencode($to) . '&type=' . urlencode($this->type) . '&message=' . $body; $ret = $this->getClient()->post($url, array()); } return true; }
/** * @see FilterInterface::accept */ public function accept(SmsMessage $message) { $to = $message->getTo(); if ($this->whitelisted) { $to = array_filter($to, array($this, 'handleWhitelisted')); } if ($this->blacklisted) { $to = array_filter($to, array($this, 'handleBlacklisted')); } return (bool) $to; }
/** * @see GatewayInterface::send * @param SmsMessage $message */ public function send(SmsMessage $message) { // Sending is limited to max 100 addressees if (count($message->getTo()) > 100) { $return = array(); foreach (array_chunk($message->getTo(), 100) as $tos) { $message_alt = clone $message; $message_alt->setTo($tos); $response = $this->send($message_alt); $return = array_merge($return, $response); } return $return; } $params = array('api_id' => $this->apiKey, 'user' => $this->user, 'password' => $this->password, 'to' => implode(',', $message->getTo()), 'text' => utf8_decode($message->getBody()), 'from' => $message->getFrom(), 'mo' => 1); $response_string = $this->getClient()->get($this->endpoint . '/http/sendmsg?' . http_build_query($params), array()); $response = $this->parseResponse($response_string); if (!empty($response['ERR'])) { throw new SmsException(sprintf('Error(s): %s', var_export($response['ERR'], true))); } if (empty($response['ID'])) { throw new SmsException('Error: No message ID returned'); } return $response['ID']; }
/** * @param SmsMessage $message * @return bool */ public function send(SmsMessage $message) { if (!$message->getTo()) { throw new RuntimeException('Cannot send a message with no receivers'); } foreach ($this->getFilters() as $filter) { /** @var FilterInterface $filter */ if (!$filter->accept($message)) { $event = new FilterEvent($message, $filter); $this->ed->dispatch(Events::FILTER_DENY, $event); return false; } } $ret = $this->gateway->send($message); if ($ret) { $event = new SmsMessageEvent($message); $this->ed->dispatch(Events::SEND, $event); } return $ret; }
/** * @see GatewayInterface::send */ public function send(SmsMessage $message) { $writer = new XMLWriter(); $writer->openMemory(); $writer->startDocument('1.0', 'UTF-8'); $writer->startElement('SMS'); $writer->startElement('authentication'); $writer->startElement('username'); $writer->text($this->user); $writer->endElement(); $writer->startElement('password'); $writer->text($this->password); $writer->endElement(); $writer->endElement(); $writer->startElement('message'); $writer->startElement('sender'); $writer->text($message->getFrom()); $writer->endElement(); $writer->startElement('datacoding'); $writer->text('3'); $writer->endElement(); $writer->startElement('text'); $writer->text(utf8_decode($message->getBody())); $writer->endElement(); $writer->endElement(); $writer->startElement('recipients'); foreach ($message->getTo() as $to) { $writer->startElement('gsm'); $writer->text($to); $writer->endElement(); } $writer->endElement(); $writer->endElement(); $writer->endDocument(); $requestBody = 'XML=' . preg_replace('/<\\?xml.*\\?>\\n?/', '', $writer->outputMemory()); $this->getClient()->post($this->endpoint . '/v3/sendsms/xml', array(), $requestBody); return true; }
/** * @param \Xi\Sms\SmsMessage $message * @return boolean true if send was successful for all receivers */ public function send(SmsMessage $message) { $result = $this->sendMessage($message->getFrom(), $message->getTo(), $message->getBody()); return $result; }
public function send(SmsMessage $message) { return $this->sms($message->getBody(), $message->getTo(), $message->getFrom()); }