/** * 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; }
/** * 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; }