Пример #1
0
 /**
  * Parses the response as JSON.
  *
  * Objects will be decoded as associative arrays.
  *
  * @return mixed
  *
  * @throws \Brick\Json\JsonException
  */
 public function parseJson()
 {
     static $jsonDecoder;
     if (!$jsonDecoder) {
         $jsonDecoder = new JsonDecoder();
         $jsonDecoder->decodeObjectsAsArrays(true);
     }
     return $jsonDecoder->decode($this->getText());
 }
Пример #2
0
 /**
  * Sends a SMS message to one or several recipients.
  *
  * @param array  $numbers The numbers in international format, without the + sign
  * @param string $from    The sender name
  * @param string $message The message to send
  *
  * @throws \Brick\Service\Exception
  */
 public function sendSms(array $numbers, $from, $message)
 {
     foreach ($numbers as $number) {
         if (!ctype_digit($number)) {
             throw new Exception('Invalid phone number: ' . $number);
         }
     }
     $numbers = implode(',', $numbers);
     $postData = ['uname' => $this->username, 'pword' => $this->password, 'numbers' => $numbers, 'message' => $message, 'from' => $from, 'json' => '1'];
     $curl = new Curl(self::API_URL);
     $curl->setOption(CURLOPT_POST, true);
     $curl->setOption(CURLOPT_POSTFIELDS, http_build_query($postData));
     $json = $curl->execute();
     $data = $this->jsonDecoder->decode($json);
     if (isset($data->Error)) {
         throw new Exception('TextLocal error: ' . $data->Error);
     }
 }