/**
  * Retorna o response do socket
  *
  * @param resource $sock
  * @return string
  */
 public static function getResponse($sock)
 {
     $response = "";
     while (!feof($sock)) {
         $response .= fgets($sock, 128);
     }
     $response = explode("\r\n\r\n", $response);
     $header = $response[0];
     $responsecontent = $response[1];
     if (!(strpos($header, "Transfer-Encoding: chunked") === false)) {
         $aux = explode("\r\n", $responsecontent);
         $countAux = count($aux);
         for ($i = 0; $i < $countAux; $i++) {
             if ($i == 0 || $i % 2 == 0) {
                 $aux[$i] = "";
             }
         }
         $responsecontent = implode("", $aux);
     }
     $responsecontent = explode("\n", rtrim($responsecontent));
     $result = array();
     foreach ($responsecontent as $resp) {
         $humanResponse = new HumanResponse();
         $respAux = explode(" - ", $resp);
         $humanResponse->setCode($respAux[0]);
         $humanResponse->setMessage($respAux[1]);
         array_push($result, $humanResponse);
     }
     return $result;
 }
 /**
  * @param string $body Texto da mensagem
  * @param string $to Destinatário da mensagem
  * @param string $msgId ID da mensagem
  * @param string $from Remetente da mensagem
  * @param string $schedule Agendamento da mensagem
  * @param string $callbackOption Callback da mensagem
  *
  * @return \HumanResponse
  */
 public function send($body, $to, $msgId = null, $from = null, $schedule = null, $callbackOption = null)
 {
     $message = new \HumanSimpleMessage();
     $message->setBody($body);
     $message->setTo($to);
     $message->setFrom($from ?: $this->_module->from);
     $message->setMsgId($msgId);
     $message->setSchedule($schedule);
     if ($this->_module->simulate === true) {
         $response = new \HumanResponse();
         $response->setCode('000');
         $response->setMessage('Simulado');
         Yii::trace(VarDumper::dumpAsString($message));
     } else {
         $response = $this->humanSimpleSend->sendMessage($message, $callbackOption ?: $this->_module->callBack);
     }
     return $response;
 }