forked from SimplesIP/pabx-app
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.
133 lines
4.5 KiB
133 lines
4.5 KiB
2 years ago
|
#!/usr/bin/php -q
|
||
|
<?php
|
||
|
ini_set('display_errors', 1);
|
||
|
ini_set('display_startup_erros', 0);
|
||
|
error_reporting(E_ALL);
|
||
|
header("Content-Type: text/plain");
|
||
|
# $numero = $argv[1];
|
||
|
try {
|
||
|
$resp = RemoveMask('21979500006');
|
||
|
|
||
|
$telCliente = GetTelefoneCliente($resp);
|
||
|
|
||
|
print_r($telCliente);
|
||
|
} catch (Exception $ex) {
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
function GetTelefoneCliente($param) {
|
||
|
|
||
|
$url = 'http://138.99.133.20/server.php';
|
||
|
$_user = rawurlencode('25A50GL3HQ');
|
||
|
$_passwd = rawurlencode('25A50GL40Z');
|
||
|
$_consulta = '014M0ZM398';
|
||
|
$_formato_padrao = 'X';
|
||
|
$_fone = $param['telefone'];
|
||
|
|
||
|
$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 .= sprintf('<param name="%s">' . "\n",$param['type']);
|
||
|
$xml .= "<value>\n";
|
||
|
$xml .= "<string><![CDATA[$_fone]]></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 == '') {
|
||
|
throw new Exception("Void Response");
|
||
|
} else {
|
||
|
|
||
|
$xml = simplexml_load_string($result);
|
||
|
$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;
|
||
|
}
|
||
|
} else {
|
||
|
throw new Exception("HTTP error ocurred, number: $httpCode");
|
||
|
}
|
||
|
} else {
|
||
|
curl_close($ch);
|
||
|
throw new Exception("HTTP error ocurred: $curlError");
|
||
|
}
|
||
|
return $retorno;
|
||
|
}
|
||
|
|
||
|
function RemoveMask($telefone) {
|
||
|
$retorno = array('telefone' => '', 'type' => '');
|
||
|
|
||
|
if (strlen($telefone) == 9) {
|
||
|
$telefone = "(21)" . $telefone;
|
||
|
$retorno['telefone'] = $telefone;
|
||
|
$retorno['type'] = 'celular';
|
||
|
|
||
|
} else if (strlen($telefone) == 11) {
|
||
|
$ddd = substr($telefone, 0, 2);
|
||
|
$numero = substr($telefone, 2, 10);
|
||
|
$telefone = sprintf("(%s)%s", $ddd, $numero);
|
||
|
$retorno['telefone'] = $telefone;
|
||
|
$retorno['type'] = 'celular';
|
||
|
|
||
|
} else if (strlen($telefone) == 8) {
|
||
|
$telefone = "(21)" . $telefone;
|
||
|
$retorno['telefone'] = $telefone;
|
||
|
$retorno['type'] = 'fone';
|
||
|
|
||
|
} else if (strlen($telefone) == 10) {
|
||
|
$ddd = substr($telefone, 0, 2);
|
||
|
$numero = substr($telefone, 2, 9);
|
||
|
$telefone = sprintf("(%s)%s", $ddd, $numero);
|
||
|
$retorno['telefone'] = $telefone;
|
||
|
$retorno['type'] = 'fone';
|
||
|
}
|
||
|
|
||
|
return $retorno;
|
||
|
}
|
||
|
|
||
|
?>
|