@@ -18,15 +18,51 @@ class GusApi
18
18
19
19
private $ loginData = ["pKluczUzytkownika " => "aaaaaabbbbbcccccdddd " ];
20
20
21
+ private $ searchData = [
22
+ 'jestWojPowGmn ' => true ,
23
+ 'pParametryWyszukiwania ' => [
24
+ 'AdsSymbolGminy ' => null ,
25
+ 'AdsSymbolMiejscowosci ' => null ,
26
+ 'AdsSymbolPowiatu ' => null ,
27
+ 'AdsSymbolUlicy ' => null ,
28
+ 'AdsSymbolWojewodztwa ' => null ,
29
+ 'Dzialalnosci ' => null ,
30
+ 'FormaPrawna ' => null ,
31
+ 'Krs ' => null ,
32
+ 'Krsy ' => null ,
33
+ 'NazwaPodmiotu ' => null ,
34
+ 'Nip ' => null ,
35
+ 'Nipy ' => null ,
36
+ 'NumerwRejestrzeLubEwidencji ' => null ,
37
+ 'OrganRejestrowy ' => null ,
38
+ 'PrzewazajacePKD ' => false ,
39
+ 'Regon ' => null ,
40
+ 'Regony14zn ' => null ,
41
+ 'Regony9zn ' => null ,
42
+ 'RodzajRejestru ' => null
43
+ ]
44
+ ];
45
+
21
46
/**
22
47
* @var string
23
48
*/
24
49
private $ captchaFileName = "captcha.jpeg " ;
25
50
26
51
private $ loginUrl = 'https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc/ajaxEndpoint/Zaloguj ' ;
27
52
53
+ private $ getCaptchaUrl = 'https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc/ajaxEndpoint/PobierzCaptcha ' ;
54
+
55
+ private $ checkCaptchaUrl = 'https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc/ajaxEndpoint/SprawdzCaptcha ' ;
56
+
57
+ private $ searchDataUrl = 'https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc/ajaxEndpoint/daneSzukaj ' ;
58
+
59
+ private $ getComplexDataUrl = 'https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc/ajaxEndpoint/DanePobierzPelnyRaport ' ;
60
+
61
+ private $ captchaStatus = false ;
62
+
28
63
public function __construct ()
29
64
{
65
+ $ this ->login ();
30
66
}
31
67
32
68
public function login ()
@@ -43,5 +79,121 @@ public function login()
43
79
$ this ->sid = $ curl ->response ->d ;
44
80
45
81
$ curl ->close ();
82
+
83
+ return $ this ;
84
+ }
85
+
86
+ public function getCaptcha ()
87
+ {
88
+ $ curl = new Curl ();
89
+ $ curl ->setHeader ('Content-Type ' , 'application/json ' );
90
+ $ curl ->setHeader ('sid ' , $ this ->sid );
91
+ $ curl ->post ($ this ->getCaptchaUrl ,'' );
92
+
93
+ $ image = fopen ($ this ->captchaFileName ,'w+ ' );
94
+ if (!$ image )
95
+ {
96
+ throw new \Exception ("NO file! " );
97
+ }
98
+
99
+ fwrite ($ image , base64_decode ($ curl ->response ->d ));
100
+ fclose ($ image );
101
+
102
+ $ curl ->close ();
103
+
104
+ return $ this ;
105
+ }
106
+
107
+ public function checkCaptcha ($ captcha )
108
+ {
109
+ $ curl = new Curl ();
110
+ $ curl ->setHeader ('Content-Type ' , 'application/json ' );
111
+ $ curl ->setHeader ('sid ' , $ this ->sid );
112
+ $ curl ->post ($ this ->checkCaptchaUrl , json_encode (array ('pCaptcha ' =>$ captcha )));
113
+ $ curl ->close ();
114
+
115
+ $ this ->captchaStatus = (bool )$ curl ->response ->d ;
116
+ return $ this ->captchaStatus ;
117
+ }
118
+
119
+ public function getInfoByNip ($ nip )
120
+ {
121
+ $ basicInfo = $ this ->getBasicInfoByNip ($ nip );
122
+
123
+ return $ this ->getComplexData ($ basicInfo [0 ]->Regon );
124
+ }
125
+
126
+ public function getInfoByRegon ($ regon )
127
+ {
128
+ $ basicInfo = $ this ->getBasicInfoByRegon ($ regon );
129
+
130
+ return $ this ->getComplexData ($ basicInfo [0 ]->Regon );
131
+ }
132
+
133
+ public function getInfoByKrs ($ krs )
134
+ {
135
+ $ basicInfo = $ this ->getBasicInfoByKrs ($ krs );
136
+
137
+ return $ this ->getComplexData ($ basicInfo [0 ]->Regon );
138
+ }
139
+
140
+ public function getBasicInfoByNip ($ nip )
141
+ {
142
+ $ this ->clearSearch ();
143
+ $ this ->searchData ['pParametryWyszukiwania ' ]['Nip ' ] = $ nip ;
144
+ return $ this ->search ();
145
+ }
146
+
147
+ public function getBasicInfoByRegon ($ regon )
148
+ {
149
+ $ this ->clearSearch ();
150
+ $ this ->searchData ['pParametryWyszukiwania ' ]['Regon ' ] = $ regon ;
151
+ return $ this ->search ();
152
+ }
153
+
154
+ public function getBasicInfoByKrs ($ krs )
155
+ {
156
+ $ this ->clearSearch ();
157
+ $ this ->searchData ['pParametryWyszukiwania ' ]['Krs ' ] = $ krs ;
158
+ return $ this ->search ();
159
+ }
160
+
161
+ public function getCaptchaStatus ()
162
+ {
163
+ return $ this ->captchaStatus ;
164
+ }
165
+
166
+ private function getComplexData ($ regon )
167
+ {
168
+ $ searchData = [
169
+ 'pNazwaRaportu ' =>'DaneRaportPrawnaPubl ' ,
170
+ 'pRegon ' => $ regon ,
171
+ 'pSilosID ' => 0
172
+ ];
173
+
174
+ $ curl = new Curl ();
175
+ $ curl ->setHeader ('Content-Type ' , 'application/json ' );
176
+ $ curl ->setHeader ('sid ' , $ this ->sid );
177
+ $ curl ->post ($ this ->getComplexDataUrl , json_encode ($ searchData ));
178
+ $ curl ->close ();
179
+
180
+ $ response = json_decode ($ curl ->response ->d );
181
+ return $ response [0 ];
182
+ }
183
+
184
+ private function clearSearch ()
185
+ {
186
+ array_walk ($ this ->searchData ['pParametryWyszukiwania ' ],function ($ item ,$ key ){ return null ; });
187
+ }
188
+
189
+ private function search ()
190
+ {
191
+ $ curl = new Curl ();
192
+ $ curl ->setHeader ('Content-Type ' , 'application/json ' );
193
+ $ curl ->setHeader ('sid ' , $ this ->sid );
194
+ $ curl ->post ($ this ->searchDataUrl , json_encode ($ this ->searchData ));
195
+ $ curl ->close ();
196
+
197
+ return json_decode ($ curl ->response ->d );
46
198
}
47
199
}
0 commit comments