1
|
|
|
<?php namespace zServices\Sintegra\Services\Portais\SP; |
2
|
|
|
|
3
|
|
|
use Captcha\Interfaces\ServiceInterface as DecaptcherServiceInterface; |
4
|
|
|
use zServices\Miscellany\Interfaces\ServiceInterface; |
5
|
|
|
use zServices\Sintegra\Services\Portais\SP\Search; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
class Service implements ServiceInterface { |
11
|
|
|
/** |
12
|
|
|
* Armazena as URLs e selectors do serviço a ser consultado |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
public $configurations = [ |
16
|
|
|
'base' => 'http://pfeserv1.fazenda.sp.gov.br', |
17
|
|
|
'home' => 'http://pfeserv1.fazenda.sp.gov.br/sintegrapfe/consultaSintegraServlet', |
18
|
|
|
'captcha' => 'http://pfeserv1.fazenda.sp.gov.br/sintegrapfe/consultaSintegraServlet', |
19
|
|
|
'data' => 'http://pfeserv1.fazenda.sp.gov.br/sintegrapfe/sintegra', |
20
|
|
|
'selectors' => [ |
21
|
|
|
'image' => 'body > center > table > tr > td > form > table > tbody > tr:nth-child(1) > td:nth-child(3) > img', |
22
|
|
|
'paramBot' => 'body > center > table > tr > td > form > input[type="hidden"]:nth-child(2)', |
23
|
|
|
'data' => [ |
24
|
|
|
'error' => 'body > center:nth-child(8) > table > tr > td > font > b', |
25
|
|
|
'inscricao_estadual' => 'body > center:nth-child(9) > table > tr > td:nth-child(4) > font', |
26
|
|
|
'razao_social' => 'body > center:nth-child(10) > table > tr > td:nth-child(2) > font', |
27
|
|
|
'logradouro' => 'body > center:nth-child(13) > table > tr > td:nth-child(2) > font', |
28
|
|
|
'numero' => 'body > center:nth-child(14) > table > tr > td:nth-child(2) > font', |
29
|
|
|
'complemento' => 'body > center:nth-child(14) > table > tr > td:nth-child(4) > font', |
30
|
|
|
'bairro' => 'body > center:nth-child(15) > table > tr > td:nth-child(2) > font', |
31
|
|
|
'municipio' => 'body > center:nth-child(16) > table > tr > td:nth-child(2) > font', |
32
|
|
|
'uf' => 'body > center:nth-child(16) > table > tr > td:nth-child(4) > font', |
33
|
|
|
'cep' => 'body > center:nth-child(17) > table > tr > td:nth-child(2) > font', |
34
|
|
|
'atividade_economica' => 'body > center:nth-child(20) > table > tr > td:nth-child(2) > font', |
35
|
|
|
'situacao' => 'body > center:nth-child(21) > table > tr > td:nth-child(2) > font', |
36
|
|
|
'situacao2' => 'body > center:nth-child(21) > table > tr > td:nth-child(3) > font', |
37
|
|
|
'data_situacao' => 'body > center:nth-child(22) > table > tr > td:nth-child(2) > font', |
38
|
|
|
'regime' => 'body > center:nth-child(23) > table > tr > td:nth-child(2) > font', |
39
|
|
|
'data_emissor_nfe' => 'body > center:nth-child(24) > table > tr > td:nth-child(2) > font', |
40
|
|
|
'indicator_obrigatoriedade_nfe' => 'body > center:nth-child(25) > table > tr > td:nth-child(2) > font', |
41
|
|
|
'data_inicio_obrigatoriedade_nfe' => 'body > center:nth-child(26) > table > tr > td:nth-child(2) > font', |
42
|
|
|
'consulta' => 'body > center:nth-child(28) > table > tr:nth-child(2) > td:nth-child(2) > font > b', |
43
|
|
|
'observacoes' => 'body > center:nth-child(30) > table > tr > td > font:nth-child(1)', |
44
|
|
|
], |
45
|
|
|
], |
46
|
|
|
'headers' => [ |
47
|
|
|
'Origin' => 'http://pfeserv1.fazenda.sp.gov.br', |
48
|
|
|
'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0', |
49
|
|
|
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
50
|
|
|
'Accept-Language' => 'pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3', |
51
|
|
|
'Accept-Encoding' => 'gzip, deflate', |
52
|
|
|
'Host' => 'pfeserv1.fazenda.sp.gov.br', |
53
|
|
|
], |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Search instance |
58
|
|
|
* @var object |
59
|
|
|
*/ |
60
|
|
|
private $search; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get search instance |
64
|
|
|
* @return void |
|
|
|
|
65
|
|
|
*/ |
66
|
|
|
public function __construct() { |
67
|
|
|
$this->search = new Search; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Executa primeira requisição preparando |
72
|
|
|
* o cookie e captcha |
73
|
|
|
* @return Service |
74
|
|
|
*/ |
75
|
|
|
public function request() { |
76
|
|
|
$this->search->request($this->configurations); |
77
|
|
|
|
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Retorna o base64 da imagem do captcha |
83
|
|
|
* @return string base64_image |
84
|
|
|
*/ |
85
|
|
|
public function captcha() { |
86
|
|
|
return $this->search->getCaptcha(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Cookie da requisição |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
public function cookie() { |
94
|
|
|
return $this->search->getCookie(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* DecaptcherServiceInterface from decaptcher |
99
|
|
|
* |
100
|
|
|
* Impoe o serviço a ser utilizado para efetuar a quebra do captcha |
101
|
|
|
* @param DecaptcherServiceInterface $decaptcher |
102
|
|
|
* @return Search |
103
|
|
|
*/ |
104
|
|
|
public function decaptcher(DecaptcherServiceInterface $decaptcher) { |
105
|
|
|
$this->search->decaptcher = $decaptcher; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get params |
112
|
|
|
* @return array |
113
|
|
|
*/ |
114
|
|
|
public function params() { |
115
|
|
|
return $this->search->getParams(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Informações da entidade no serviço |
120
|
|
|
* @return array |
121
|
|
|
*/ |
122
|
|
|
public function data($document, $cookie, $captcha, array $params = []) { |
123
|
|
|
return $this->search->getData($document, $cookie, $captcha, $params, $this->configurations); |
124
|
|
|
} |
125
|
|
|
} |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.