NFePHP\Common\Soap\CurlSoap::send PHP Метод

send() публичный Метод

Envia mensagem ao webservice
public send ( $urlservice, string $namespace, string $header, string $body, string $method ) : boolean | string
$namespace string
$header string
$body string
$method string
Результат boolean | string
    public function send($urlservice, $namespace, $header, $body, $method)
    {
        //monta a mensagem ao webservice
        $data = '<?xml version="1.0" encoding="utf-8"?>' . '<soap12:Envelope ';
        $data .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
        $data .= 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ';
        $data .= 'xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">';
        $data .= '<soap12:Header>' . $header . '</soap12:Header>';
        $data .= '<soap12:Body>' . $body . '</soap12:Body>';
        $data .= '</soap12:Envelope>';
        $data = Strings::clearMsg($data);
        $this->lastMsg = $data;
        //tamanho da mensagem
        $tamanho = strlen($data);
        //estabelecimento dos parametros da mensagem
        //$parametros = array(
        //    'Content-Type: application/soap+xml;charset=utf-8;action="'.$namespace."/".$method.'"',
        //    'SOAPAction: "'.$method.'"',
        //    "Content-length: $tamanho");
        $parametros = array('Content-Type: application/soap+xml;charset=utf-8', 'SOAPAction: "' . $method . '"', "Content-length: {$tamanho}");
        //solicita comunicação via cURL
        $resposta = $this->zCommCurl($urlservice, $data, $parametros);
        if (empty($resposta)) {
            $msg = "Não houve retorno do Curl.\n {$this->errorCurl}";
            throw new Exception\RuntimeException($msg);
        }
        //obtem o bloco html da resposta
        $xPos = stripos($resposta, "<");
        $blocoHtml = substr($resposta, 0, $xPos);
        if ($this->infoCurl["http_code"] != '200') {
            //se não é igual a 200 houve erro
            $msg = $blocoHtml;
            throw new Exception\RuntimeException($msg);
        }
        //obtem o tamanho da resposta
        $lenresp = strlen($resposta);
        //localiza a primeira marca de tag
        $xPos = stripos($resposta, "<");
        //se não existir não é um xml nem um html
        if ($xPos !== false) {
            $xml = substr($resposta, $xPos, $lenresp - $xPos);
        } else {
            $xml = '';
        }
        //testa para saber se é um xml mesmo ou é um html
        $result = simplexml_load_string($xml, 'SimpleXmlElement', LIBXML_NOERROR + LIBXML_ERR_FATAL + LIBXML_ERR_NONE);
        if ($result === false) {
            //não é um xml então pode limpar
            $xml = '';
        }
        if ($xml == '') {
            $msg = "Não houve retorno de um xml verifique soapDebug!!";
            throw new Exception\RuntimeException($msg);
        }
        if ($xml != '' && substr($xml, 0, 5) != '<?xml') {
            $xml = '<?xml version="1.0" encoding="utf-8"?>' . $xml;
        }
        return $xml;
    }