Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
caller.php
1<?php
2
4
9
10class Caller
11{
12 protected $http;
13 protected $apiUrl;
14
15 public function __construct($params)
16 {
17 $this->http = new HttpClient(array(
18 "version" => "1.1",
19 "socketTimeout" => 60,
20 "streamTimeout" => 60,
21 "redirect" => true,
22 "redirectMax" => 5,
23 ));
24
25 if(!isset($params["COMPATIBILITY-LEVEL"]))
26 $params["COMPATIBILITY-LEVEL"] = 945;
27
28 if(!isset($params["EBAY_SITE_ID"]))
29 $params["EBAY_SITE_ID"] = 215; //RU
30
31 if(!isset($params["URL"]))
32 throw new ArgumentNullException("params[\"URL\"]");
33
34 $this->apiUrl = $params["URL"];
35 $this->http->setHeader("X-EBAY-API-COMPATIBILITY-LEVEL", $params["COMPATIBILITY-LEVEL"]);
36 $this->http->setHeader("X-EBAY-API-SITEID", $params["EBAY_SITE_ID"]);
37 $this->http->setHeader("Content-Type", "text/xml");
38 }
39
40 public function sendRequest($callName, $data, $devId = "", $apiAppId = "", $certId = "")
41 {
42 if($callName == '')
43 throw new ArgumentNullException("callName");
44
45 $this->http->setHeader("X-EBAY-API-CALL-NAME", $callName);
46
47 if($devId <> '')
48 $this->http->setHeader("X-EBAY-API-DEV-NAME", $devId);
49
50 if($apiAppId <> '')
51 $this->http->setHeader("X-EBAY-API-APP-NAME", $apiAppId);
52
53 if($certId <> '')
54 $this->http->setHeader("X-EBAY-API-CERT-NAME", $certId);
55
56
57 if(mb_strtolower(SITE_CHARSET) != 'utf-8')
58 $data = Encoding::convertEncodingArray($data, SITE_CHARSET, 'UTF-8');
59
60 $result = @$this->http->post($this->apiUrl, $data);
61 $errors = $this->http->getError();
62
63 if (!$result && !empty($errors))
64 {
65 $strError = "";
66
67 foreach($errors as $errorCode => $errMes)
68 $strError .= $errorCode.": ".$errMes;
69
70 throw new SystemException($strError);
71 }
72 else
73 {
74 $status = $this->http->getStatus();
75
76 if ($status != 200)
77 throw new SystemException(sprintf('HTTP error code: %d', $status));
78 }
79
80 return $result;
81 }
82}
sendRequest($callName, $data, $devId="", $apiAppId="", $certId="")
Definition caller.php:40