OpenCart 🇺🇦

Схема

private mixed call ( $call, array $post = null, array $options = array(), $content_type = 'json' )

Аргументы

Аргумент Возможный тип Описание
$call
array $post = null
array $options = array()
$content_type = 'json'

Описание

Метод пока еще не документирован.

Исходный код

if (defined("HTTP_CATALOG")) {
	$domain = HTTP_CATALOG;
} else {
	$domain = HTTP_SERVER;
}

$data = array(
	'token' => '',
	'language' => $this->config->get('openbay_language'),
	'secret' => '',
	'server' => 1,
	'domain' => $domain,
	'openbay_version' => (int)$this->config->get('openbay_version'),
	'data' => $post,
	'content_type' => $content_type,
	'ocversion' => VERSION
);

$useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

$defaults = array(
	CURLOPT_POST => 1,
	CURLOPT_HEADER => 0,
	CURLOPT_URL => $this->url . $call,
	CURLOPT_USERAGENT => $useragent,
	CURLOPT_FRESH_CONNECT => 1,
	CURLOPT_RETURNTRANSFER => 1,
	CURLOPT_FORBID_REUSE => 1,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_SSL_VERIFYPEER => 0,
	CURLOPT_SSL_VERIFYHOST => 0,
	CURLOPT_POSTFIELDS => http_build_query($data, '', "&")
);

$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
$result = curl_exec($ch);
curl_close($ch);


if ($content_type == 'json') {
	$encoding = mb_detect_encoding($result);

	/* some json data may have BOM due to php not handling types correctly */
	if ($encoding == 'UTF-8') {
		$result = preg_replace('/[^(\x20-\x7F)]*/', '', $result);
	}

	$result = json_decode($result, 1);
	$this->lasterror = $result['error'];
	$this->lastmsg = $result['msg'];

	if (!empty($result['data'])) {
		return $result['data'];
	} else {
		return false;
	}
} elseif ($content_type == 'xml') {
	$result = simplexml_load_string($result);
	$this->lasterror = $result->error;
	$this->lastmsg = $result->msg;

	if (!empty($result->data)) {
		return $result->data;
	} else {
		return false;
	}
}