Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getData($data = [])
- {
- if ($this->encoding != 'utf-8') {
- $login = iconv('utf-8', $this->encoding . '//IGNORE', $this->login);
- $password = iconv('utf-8', $this->encoding . '//IGNORE', $this->password);
- } else {
- $login = $this->login;
- $password = $this->password;
- }
- $get = [
- 'exportOff' => '1',
- 'sort___search_results_by' => 'final_price',
- 'article' => $this->code,
- 'user' => $login,
- 'password' => $password
- ];
- //отключение поиска аналогов при выключенной опции или предпроценке
- if ($this->getOption('analogs') != 'Y' || $this->preOrderSearch) {
- $get['smode'] = 'A0';
- }
- if ($this->isTestMode()) {
- $get['smode'] = 'B0';
- }
- $get = array_merge($get, $data);
- // для отладки
- $parseUrl = [];
- if (!(parse_url($this->host, PHP_URL_SCHEME))) {
- $parseUrl['scheme'] = 'http';
- $parseUrl['host'] = $this->host;
- } else {
- $parseUrl = parse_url($this->host);
- }
- $this->query_url = $parseUrl['scheme'] . '://' . $this->warUser . ':' . $this->warPassword . '@' . $parseUrl['host'] . '/service/search/?' . http_build_query($get);
- if (isset($this->request->useCache) && $this->request->useCache == false) {
- $res = false;
- } else {
- $res = $this->cache->get($this->query_url);
- // http://support.tradesoft.ru/WorkOrder.do?woMode=viewW..
- if (stripos($res, '503 Service Temporarily Unavailable')) {
- $this->cache->set($this->query_url, null);
- $res = false;
- }
- }
- if ($res === false || $this->preOrderSearch) {
- if ($this->limitEnabled) {
- $key = md5($this->providerName . ':' . $this->login);
- $comment = $this->providerName . ':' . $this->login;
- $accessDeny = $this->isLimitReached($key, $this->queryLimit, 3600, $comment);
- if ($accessDeny) {
- $this->error('Доступ временно заблокирован.');
- }
- }
- $url = $this->host . '/service/search/?' . http_build_query($get);
- $httpRequest = new HttpRequest();
- $httpRequest->setUrl($url);
- $httpRequest->addHeader('Expect:');
- $httpRequest->setExtra([
- $this,
- ]);
- $curlOptionList = [
- CURLOPT_TIMEOUT => 50,
- CURLOPT_CONNECTTIMEOUT => 3,
- CURLOPT_DNS_CACHE_TIMEOUT => 86400,
- ];
- if ($this->compression) {
- $curlOptionList[CURLOPT_ENCODING] = 'gzip';
- }
- if (!empty($this->warUser) && !empty($this->warPassword)) {
- $curlOptionList[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
- $curlOptionList[CURLOPT_USERPWD] = $this->warUser . ':' . $this->warPassword;
- }
- $httpClient = $this->di->get('httpClient');
- $httpClient->addCurlOptionList($curlOptionList);
- $httpResponse = $httpClient->execute($httpRequest);
- $body = $httpResponse->getBody();
- $header = $httpResponse->getHeader();
- $httpCode = $httpResponse->getCode();
- $res = $header . "\r\n\r\n" . $body;
- $errno = $httpResponse->getExtra('curlErrNo');
- $info = $httpResponse->getExtra('curlInfo');
- if ($errno != CURLE_OK) {
- $errorMessage = Curl::getErrorMessage($errno);
- $this->errorProvider($errorMessage);
- }
- if ($httpCode >= 400) {
- $errorMessage = HttpCodes::getDescriptionByCode($httpCode, true);
- $this->errorProvider($errorMessage);
- }
- $this->checkError($res);
- if ($info['size_download'] == 8) {
- return [];
- }
- $this->cache->set($this->query_url, $res, 3600);
- }
- if (preg_match('#PHPSESSID=(.*);#i', $res, $PHPSESSID) > 0) {
- $this->userData = $PHPSESSID[1];
- } else {
- $this->userData = null;
- }
- $res = substr($res, strpos($res, "\r\n\r\n") + 4);
- if (stripos($res, 'Превышено количество одновременных подключений к базе данных')) {
- $this->errorProvider('Превышено количество одновременных подключений к базе данных');
- }
- try {
- $res_array = [];
- $res = base64_decode($res);
- if (Parse::isSerialized($res)) {
- $res_array = unserialize($res)
- }
- $res_array = @unserialize(base64_decode($res));
- } catch (\Exception $e) {
- $context = [
- 'text' => $res,
- 'url' => !empty($url) ? $url : '',
- 'code' => $this->code,
- 'login' => $this->login,
- ];
- $this->di->get('logger')->addDebug($this->name, $context);
- throw $e;
- }
- if ($res_array === false) {
- $context = [
- 'code' => $this->code,
- 'brand' => $this->producer,
- 'get' => http_build_query($get),
- 'request' => $this->query_url,
- 'responce' => base64_encode($res),
- ];
- if (strlen($res) <= 256) {
- $context['res'] = $res;
- }
- $this->di->get('logger')->addDebug($this->host, $context);
- $this->errorProvider();
- }
- if (!is_array($res_array)) {
- $this->cache->set($this->query_url, false);
- $this->errorProvider($errno);
- }
- return $res_array;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement