1
|
|
|
<?php |
2
|
|
|
namespace Eduardokum\CorreiosPhp; |
3
|
|
|
|
4
|
|
|
use Eduardokum\CorreiosPhp\Contracts\Config\Config as ConfigContract; |
5
|
|
|
|
6
|
|
|
class Rastreio extends Correios |
7
|
|
|
{ |
8
|
|
|
public function __construct(ConfigContract $config = null, $type = 'curl') |
9
|
|
|
{ |
10
|
|
|
parent::__construct($config, $type); |
11
|
|
|
$this->setWs($this->getWs('rastreamento')); |
12
|
|
|
|
13
|
|
|
if ($this->getConfig()->getEnvironment() == 'testing') { |
14
|
|
|
$this->getConfig()->setUserRastro('ECT'); |
15
|
|
|
$this->getConfig()->setPasswordRastro('SRO'); |
16
|
|
|
} |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param array $codes |
21
|
|
|
* |
22
|
|
|
* @return \stdClass |
23
|
|
|
*/ |
24
|
|
|
public function rastreamento(array $codes) |
25
|
|
|
{ |
26
|
|
|
$request = '<res:buscaEventosLista>'; |
27
|
|
|
$request .= sprintf('<usuario>%s</usuario>', $this->getConfig()->getUserRastro()); |
28
|
|
|
$request .= sprintf('<senha>%s</senha>', $this->getConfig()->getPasswordRastro()); |
29
|
|
|
$request .= sprintf('<tipo>%s</tipo>', 'L'); |
30
|
|
|
$request .= sprintf('<resultado>%s</resultado>', 'T'); |
31
|
|
|
$request .= sprintf('<lingua>%s</lingua>', '101'); |
32
|
|
|
foreach ($codes as $c) { |
33
|
|
|
$request .= sprintf('<objetos>%s</objetos>', $c); |
34
|
|
|
} |
35
|
|
|
$request .= '</res:buscaEventosLista>'; |
36
|
|
|
$namespaces = [ |
37
|
|
|
'xmlns:res' => 'http://resource.webservice.correios.com.br/', |
38
|
|
|
]; |
39
|
|
|
$actions = [ |
40
|
|
|
'curl' => 'buscaEventosLista', |
41
|
|
|
'native' => 'buscaEventosLista', |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
$result = $this->getSoap()->send($this->url(), $actions, $request, $namespaces); |
45
|
|
|
$result = $result->return; |
46
|
|
|
$result->objeto = is_array($result->objeto) ? $result->objeto : [$result->objeto]; |
47
|
|
|
foreach($result->objeto as $objeto) { |
48
|
|
|
$objeto->evento = isset($objeto->evento) |
49
|
|
|
? is_array($objeto->evento) ? $objeto->evento : [$objeto->evento] |
50
|
|
|
: []; |
51
|
|
|
} |
52
|
|
|
return $result; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|