'SAIDA',
"reg_inicio" => date('Y-m-d H:i:s'),
"reg_fim" => '',
"nome" => '',
"fone" => '',
"cpf_cnpj" => '',
"plano" => '',
"endereco" => '',
"status" => ''
);
//$cpfCnpj = str_replace('*', '', $numeroDiscar);
$cliente = procuraCliente($codCliente);
$plano = retornaPlano($cliente['codcli']);
$statusPlano = retornaStatusPlano($plano['codest']);
if (!empty($cliente['cpf_cnpj'])) {
$arInfo = array_merge($cliente, $plano, $statusPlano);
$retorno_cliente = sprintf("%s|%s|%s|Nome:%s|CPF_CNPJ:%s|Plano:%s|Endereco:%s|Status:%s", '0', $cpfCnpj, '0', str_replace("|", "", trim($cliente['nome_cli'][0])), str_replace("|", "", trim($cliente['cpf_cnpj'][0])), str_replace("|", "", trim($plano['plano'][0])), str_replace("|", "", trim($plano['endereco_i'][0])), str_replace("|", "", trim($statusPlano['descri_est'][0])));
$infoIntegracao['nome'] = trim($cliente['nome_cli'][0]);
$infoIntegracao['cpf_cnpj'] = trim($cliente['cpf_cnpj'][0]);
$infoIntegracao['plano'] = trim($plano['plano'][0]);
$infoIntegracao['endereco'] = trim($plano['endereco_i'][0]);
$infoIntegracao['status'] = trim($statusPlano['descri_est'][0]);
$tel = explode(',', $cliente['fone']);
$cel = explode(',', $cliente['celular']);
$infoIntegracao['fone'] = $tel[0] . '@' . $cel[0];
$infoIntegracao['reg_fim'] = date('Y-m-d H:i:s');
$_SESSION['SSIntegracaoAtivo'] = $infoIntegracao;
}
} catch (Exception $ex) {
$reg_msg = $ex->getMessage();
$reg_status_exec = 'Er';
__logStr("Consulta de Cliente", $reg_msg . "InfoCliente: " . print_r($cliente, true), $script, true);
}
function procuraCliente($param) {
try {
if (strlen($param) == 11) {
$pattern = '/^([[:digit:]]{3})([[:digit:]]{3})([[:digit:]]{3})([[:digit:]]{2})$/';
$replacement = '$1.$2.$3-$4';
$format = preg_replace($pattern, $replacement, $param);
$url = 'http://177.74.128.21/server.php';
$_user = rawurlencode('254R0JIT4V');
$_passwd = rawurlencode('254R0JITNP');
$_consulta = '011G0NP05B';
$_formato_padrao = 'X';
$xml = '' . "\n";
$xml .= "\n";
$xml .= "view.execute\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "";
} elseif (strlen($param) == 14) {
$pattern = '/^([[:digit:]]{2})([[:digit:]]{3})([[:digit:]]{3})([[:digit:]]{4})([[:digit:]]{2})$/';
$replacement = '$1.$2.$3/$4-$5';
$format = preg_replace($pattern, $replacement, $param);
$url = 'http://177.74.128.21/server.php';
$_user = rawurlencode('254R0JIT4V');
$_passwd = rawurlencode('254R0JITNP');
$_consulta = '011G0NP05B';
$_formato_padrao = 'X';
$xml = '' . "\n";
$xml .= "\n";
$xml .= "view.execute\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "";
} else {
return false;
}
$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 (!empty($curlError)) {
curl_close($ch);
throw new Exception("HTTP error ocurred: $curlError");
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode != 200) {
throw new Exception("HTTP error ocurred, number: $httpCode");
}
if ($result == '') {
throw new Exception("Void Response");
}
$xml = simplexml_load_string($result);
$retorno = array();
$retorno['codcli'] = $xml->params->param[1]->value->DOMElement->result->row->codcli;
$retorno['nome_cli'] = $xml->params->param[1]->value->DOMElement->result->row->nome_cli;
$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['fone'] = $xml->params->param[1]->value->DOMElement->result->row->fone;
$retorno['celular'] = $xml->params->param[1]->value->DOMElement->result->row->celular;
$retorno['email'] = $xml->params->param[1]->value->DOMElement->result->row->email;
return $retorno;
} catch (Exception $ex) {
$msg = $ex->getMessage();
return $msg;
}
}
function retornaPlano($param) {
try {
$url = 'http://177.74.128.21/server.php';
$_user = rawurlencode('254R0JIT4V');
$_passwd = rawurlencode('254R0JITNP');
$_consulta = '027C0HMRIZ';
$_formato_padrao = 'X';
$xml = '' . "\n";
$xml .= "\n";
$xml .= "view.execute\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "";
$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);
$retorno = array();
$retorno['plano'] = $xml->params->param[1]->value->DOMElement->result->row->codcli;
$retorno['codsercli'] = $xml->params->param[1]->value->DOMElement->result->row->codsercli;
$retorno['plano'] = $xml->params->param[1]->value->DOMElement->result->row->plano;
$retorno['endereco_i'] = $xml->params->param[1]->value->DOMElement->result->row->endereco_i;
$retorno['bairro_i'] = $xml->params->param[1]->value->DOMElement->result->row->bairro_i;
$retorno['cep_i'] = $xml->params->param[1]->value->DOMElement->result->row->cep_i;
$retorno['cidade_i'] = $xml->params->param[1]->value->DOMElement->result->row->cidade_i;
$retorno['uf_i'] = $xml->params->param[1]->value->DOMElement->result->row->uf_i;
$retorno['codest'] = $xml->params->param[1]->value->DOMElement->result->row->codest;
}
} else {
throw new Exception("HTTP error ocurred, number: $httpCode");
}
} else {
curl_close($ch);
throw new Exception("HTTP error ocurred: $curlError");
}
} catch (Exception $ex) {
$msg = $ex->getMessage();
return $msg;
}
return $retorno;
}
function retornaStatusPlano($param) {
try {
$url = 'http://177.74.128.21/server.php';
$_user = rawurlencode('254R0JIT4V');
$_passwd = rawurlencode('254R0JITNP');
$_consulta = '027C0IB9DF';
$_formato_padrao = 'X';
$xml = '' . "\n";
$xml .= "\n";
$xml .= "view.execute\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= '' . "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "";
$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);
$retorno = array();
$retorno['codest'] = $xml->params->param[1]->value->DOMElement->result->row->codest;
$retorno['descri_est'] = $xml->params->param[1]->value->DOMElement->result->row->descri_est;
}
} else {
throw new Exception("HTTP error ocurred, number: $httpCode");
}
} else {
curl_close($ch);
throw new Exception("HTTP error ocurred: $curlError");
}
} catch (Exception $ex) {
$msg = $ex->getMessage();
return $msg;
}
return $retorno;
}
?>