Example #1
0
 function Send(PagueVeloz_Boleto_Model_Common_HttpContext $context)
 {
     if (empty($context)) {
         throw new PagueVeloz_Boleto_Model_Exceptions_ArgumentNullException("{$context} is null");
     }
     curl_setopt($this->_curl, CURLOPT_URL, $context->getHost());
     curl_setopt($this->_curl, CURLOPT_CUSTOMREQUEST, $context->getMethod());
     curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $context->getBody());
     curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($this->_curl, CURLOPT_HEADER, 1);
     if (substr($context->getHost(), 0, 5) == 'https') {
         curl_setopt($this->_curl, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($this->_curl, CURLOPT_SSL_VERIFYPEER, 0);
     }
     if (in_array($context->getMethod(), array('post', 'put'))) {
         $context->addHeader('Content-Length: ' . strlen($context->getBody()));
     }
     curl_setopt($this->_curl, CURLOPT_HTTPHEADER, $context->getHeaders());
     // curl_setopt($this->_curl, CURLOPT_PROXY, '127.0.0.1:8888');
     $raw_result = curl_exec($this->_curl);
     $pos = strpos($raw_result, "\r\n\r\n");
     $headers = explode("\r\n", substr($raw_result, 0, $pos));
     $response = new PagueVeloz_Boleto_Model_Common_HttpResponse();
     $response->addHeaders($headers);
     // +4 porque é duplo \r\n que são as 2 linhas no fim do header
     $response->setBody(substr($raw_result, $pos + 4));
     $return_info = curl_getinfo($this->_curl);
     $response->setStatus($return_info['http_code']);
     return $response;
 }
Example #2
0
    public function Post(PagueVeloz_Boleto_Model_Dto_AssinarDTO $dto)
    {
        $contexto = new PagueVeloz_Boleto_Model_Common_HttpContext();
        $contexto->setMethod('post');
        $contexto->addHeader($this->_default_header);
        $contexto->setHost($this->getHost());
        $json = '{ 
			        "Nome": "%s",
					"Documento": "%s",
					"TipoPessoa": "%s",
					"Email": "%s",
					"LoginUsuarioDefault": "%s" 
				 }';
        $json = sprintf($json, $dto->getNome(), $dto->getDocumento(), $dto->getTipoPessoa(), $dto->getEmail()->getEmail(), $dto->getLoginUsuarioDefault()->getEmail());
        $contexto->setBody($json);
        return $this->getMachine()->Send($contexto);
    }