Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajuste para novo endpoint dos correios #21

Merged
merged 1 commit into from
Oct 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 44 additions & 36 deletions src/Cagartner/CorreiosConsulta/CorreiosConsulta.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CorreiosConsulta
{

const FRETE_URL = 'http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx?WSDL';
const CEP_URL = 'http://m.correios.com.br/movel/buscaCepConfirma.do';
const CEP_URL = 'http://www.buscacep.correios.com.br/sistemas/buscacep/resultadoBuscaCepEndereco.cfm';
const RASTREIO_URL = 'http://www2.correios.com.br/sistemas/rastreamento/resultado_semcontent.cfm';

private static $tipos = array(
Expand All @@ -29,8 +29,8 @@ public static function getTipos()
}

/**
* Verifica se uma solicita��o de varios $tipos
*
* Verifica se e uma solicitacao de varios $tipos
*
* @param $valor string
* @return boolean
*/
Expand All @@ -49,8 +49,8 @@ public static function getTipoIndex($valor)
}

/**
* Retorna todos os c�digos em uma linha
*
* Retorna todos os codigos em uma linha
*
* @param $valor string
* @return string
*/
Expand Down Expand Up @@ -90,8 +90,8 @@ public function frete($dados, $options = array())
*/

/*
1 Formato caixa/pacote
2 Formato rolo/prisma
1 eh Formato caixa/pacote
2 eh Formato rolo/prisma
3 - Envelope
*/
$dados['cep_destino'] = preg_replace("/[^0-9]/", '', $dados['cep_destino']);
Expand All @@ -102,7 +102,7 @@ public function frete($dados, $options = array())
'exceptions' => true,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'connection_timeout' => 1000
), $options);
), $options);

$soap = new \SoapClient($endpoint, $options);

Expand Down Expand Up @@ -160,51 +160,59 @@ public function frete($dados, $options = array())
public function cep($cep)
{
$data = array(
'cepEntrada' => $cep,
'tipoCep' => '',
'cepTemp' => '',
'metodo' => 'buscarCep',
'relaxation' => $cep,
'tipoCEP' => 'ALL',
'semelhante' => 'N',
);

$curl = new Curl;

$html = $curl->simple(self::CEP_URL, $data);

phpQuery::newDocumentHTML($html, $charset = 'utf-8');
phpQuery::newDocumentHTML($html, $charset = 'ISO-8859-1');

$pq_form = phpQuery::pq('');
//$pq_form = phpQuery::pq('.divopcoes,.botoes',$pq_form)->remove();
$pesquisa = array();
foreach (phpQuery::pq('#frmCep > div') as $pq_div)
{
if (phpQuery::pq($pq_div)->is('.caixacampobranco') || phpQuery::pq($pq_div)->is('.caixacampoazul'))
if(phpQuery::pq('.tmptabela')){
$linha = 0;
foreach (phpQuery::pq('.tmptabela tr') as $pq_div)
{
$dados = array();
$dados['cliente'] = trim(phpQuery::pq('.resposta:contains("Cliente: ") + .respostadestaque:eq(0)', $pq_div)->text());

if (count(phpQuery::pq('.resposta:contains("Endere�o: ") + .respostadestaque:eq(0)', $pq_div)))
$dados['logradouro'] = trim(phpQuery::pq('.resposta:contains("Endere�o: ") + .respostadestaque:eq(0)', $pq_div)->text());
else
$dados['logradouro'] = trim(phpQuery::pq('.resposta:contains("Logradouro: ") + .respostadestaque:eq(0)', $pq_div)->text());
$dados['bairro'] = trim(phpQuery::pq('.resposta:contains("Bairro: ") + .respostadestaque:eq(0)', $pq_div)->text());

$dados['cidade/uf'] = trim(phpQuery::pq('.resposta:contains("Localidade") + .respostadestaque:eq(0)', $pq_div)->text());
$dados['cep'] = trim(phpQuery::pq('.resposta:contains("CEP: ") + .respostadestaque:eq(0)', $pq_div)->text());

$dados['cidade/uf'] = explode('/', $dados['cidade/uf']);

$dados['cidade'] = trim($dados['cidade/uf'][0]);

$dados['uf'] = trim($dados['cidade/uf'][1]);

unset($dados['cidade/uf']);
if($linha){
$itens = array();
foreach (phpQuery::pq('td', $pq_div) as $pq_td){
$children = $pq_td->childNodes;
$innerHTML = '';
foreach ($children as $child) {
$innerHTML .= $child->ownerDocument->saveXML( $child );
}
$texto = preg_replace("/&#?[a-z0-9]+;/i","",$innerHTML);
$itens[] = trim( $texto );
}
$dados = array();
$dados['logradouro'] = trim($itens[0]);
$dados['bairro'] = trim($itens[1]);
$dados['cidade/uf'] = trim($itens[2]);
$dados['cep'] = trim($itens[3]);

$dados['cidade/uf'] = explode('/', $dados['cidade/uf']);

$dados['cidade'] = trim($dados['cidade/uf'][0]);

$dados['uf'] = trim($dados['cidade/uf'][1]);

unset($dados['cidade/uf']);

$pesquisa = $dados;
}

$pesquisa = $dados;
$linha++;
}
}
return $pesquisa;
}


public function rastrear($codigo)
{
$curl = new Curl;
Expand Down