You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

105 lines
3.3 KiB

#!/usr/bin/php -q
<?php
echo "Testando a funcao: \n";
$cpf = $argv[1];
$cliente = ProcuraCliente($cpf);
echo "Resultado: " . print_r($cliente, true) . "\n";
echo "CPF: " . print_r($cliente['cpf_cnpj'][0], true) . "\n";
function ProcuraCliente($param) {
$cpfMask = "%s%s%s.%s%s%s.%s%s%s-%s%s";
$url = 'http://177.74.128.21/server.php';
$_user = rawurlencode('254R0JIT4V');
$_passwd = rawurlencode('254R0JITNP');
$_consulta = '011G0NP05B';
$_formato_padrao = 'X';
$_cpf = vsprintf($cpfMask, str_split($param));
$xml = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
$xml .= "<methodCall>\n";
$xml .= "<methodName>view.execute</methodName>\n";
$xml .= "<params>\n";
$xml .= '<param name="_user">' . "\n";
$xml .= "<value>\n";
$xml .= "<string><![CDATA[$_user]]></string>\n";
$xml .= "</value>\n";
$xml .= "</param>\n";
$xml .= '<param name="_passwd">' . "\n";
$xml .= "<value>\n";
$xml .= "<string><![CDATA[$_passwd]]></string>\n";
$xml .= "</value>\n";
$xml .= "</param>\n";
$xml .= '<param name="_consulta">' . "\n";
$xml .= "<value>\n";
$xml .= "<string><![CDATA[$_consulta]]></string>\n";
$xml .= "</value>\n";
$xml .= "</param>\n";
$xml .= '<param name="formato_padrao">' . "\n";
$xml .= "<value>\n";
$xml .= "<string><![CDATA[$_formato_padrao]]></string>\n";
$xml .= "</value>\n";
$xml .= "</param>\n";
$xml .= '<param name="cpf">' . "\n";
$xml .= "<value>\n";
$xml .= "<string><![CDATA[$_cpf]]></string>\n";
$xml .= "</value>\n";
$xml .= "</param>\n";
$xml .= "</params>\n";
$xml .= "</methodCall>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: ' . strlen($xml)));
$result = curl_exec($ch);
$curlError = curl_error($ch);
if ($curlError == '') {
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 200) {
if ($result == '') {
echo ("Void Response");
} else {
$xml = simplexml_load_string($result, null, LIBXML_NOBLANKS | LIBXML_NOCDATA);
$retorno = array();
$retorno['cpf_cnpj'] = $xml->params->param[1]->value->DOMElement->result->row->cpf_cnpj;
$retorno['susp_deb'] = $xml->params->param[1]->value->DOMElement->result->row->susp_deb;
$retorno['codcli'] = $xml->params->param[1]->value->DOMElement->result->row->codcli;
$res = json_decode(json_encode($retorno), 1);
}
} else {
echo ("HTTP error ocurred, number: $httpCode");
}
} else {
curl_close($ch);
echo ("HTTP error ocurred: $curlError");
}
return $res;
}
/*function xmlToArray($xmlObj, $output = array()) {
foreach ((array) $xmlObj as $index => $node) {
$output[$index] = (is_object($node)) ? xmlToArray($node) : $node;
}
return $output;
}*/