|
1
|
|
|
<?php |
|
2
|
|
|
namespace Eduardokum\CorreiosPhp\Soap; |
|
3
|
|
|
|
|
4
|
|
|
use Eduardokum\CorreiosPhp\Contracts\Soap\Soap as SoapContract; |
|
5
|
|
|
|
|
6
|
|
|
class SoapCurl extends Soap implements SoapContract |
|
7
|
|
|
{ |
|
8
|
|
|
public function send($url, array $action = [], $request = '', $namespaces = [], $auth = []) |
|
9
|
|
|
{ |
|
10
|
|
|
$this->request = $this->envelop($request, $namespaces); |
|
11
|
|
|
$headers = array_filter([ |
|
12
|
|
|
'Content-Type: text/xml;charset=utf-8', |
|
13
|
|
|
array_key_exists('curl', $action) && !empty(trim($action['curl'])) ? sprintf('SOAPAction: "%s"', $action['curl']) : null, |
|
14
|
|
|
'Accept: text/xml', |
|
15
|
|
|
'Cache-Control: no-cache', |
|
16
|
|
|
'Pragma: no-cache', |
|
17
|
|
|
sprintf('Content-length: %s', strlen($this->request)), |
|
18
|
|
|
]); |
|
19
|
|
|
$curl = curl_init(); |
|
20
|
|
|
if ($this->proxyIP != '') { |
|
21
|
|
|
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, true); |
|
|
|
|
|
|
22
|
|
|
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); |
|
23
|
|
|
curl_setopt($curl, CURLOPT_PROXY, $this->proxyIP.':'.$this->proxyPort); |
|
24
|
|
|
if ($this->proxyUser != '') { |
|
25
|
|
|
curl_setopt($curl, CURLOPT_PROXYUSERPWD, $this->proxyUser.':'.$this->proxyPass); |
|
26
|
|
|
curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
curl_setopt($curl, CURLOPT_URL, $url); |
|
30
|
|
|
curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); |
|
31
|
|
|
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->soapTimeout); |
|
32
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, $this->soapTimeout + 20); |
|
33
|
|
|
curl_setopt($curl, CURLOPT_HEADER, false); |
|
34
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); |
|
35
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
36
|
|
|
curl_setopt($curl, CURLOPT_SSLVERSION, $this->soapProtocol); |
|
37
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
38
|
|
|
if ($auth) { |
|
39
|
|
|
curl_setopt($curl, CURLOPT_USERPWD, $auth['user'] . ":" . $auth['password']); |
|
40
|
|
|
} |
|
41
|
|
|
curl_setopt($curl, CURLOPT_POST, true); |
|
42
|
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->request); |
|
43
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); |
|
44
|
|
|
$this->response = $response = curl_exec($curl); |
|
|
|
|
|
|
45
|
|
|
$this->soapError = curl_error($curl); |
|
|
|
|
|
|
46
|
|
|
$this->soapInfo = curl_getinfo($curl); |
|
|
|
|
|
|
47
|
|
|
curl_close($curl); |
|
|
|
|
|
|
48
|
|
|
return $this->response($response); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|