null, 'apikey' => null, 'login' => null, 'password' => null); var $session = array('ssid' => null); public function set_config($name, $var) { if (is_array($var) && count($var)) { foreach ($var as $key => $key_var) { $this -> set($key, $key_var); } } else { $this -> config[$name] = $var; } } public function start_session() { $this -> curl = curl_init(); curl_setopt($this -> curl, CURLOPT_COOKIEFILE , 'cookie.dat'); curl_setopt($this -> curl, CURLOPT_COOKIEJAR , 'cookie.dat'); curl_setopt($this -> curl, CURLOPT_USERAGENT, 'Bot'); curl_setopt($this -> curl, CURLOPT_RETURNTRANSFER, true); } public function auth() { curl_setopt($this -> curl, CURLOPT_REFERER, $this -> config['site']); curl_setopt($this -> curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($this -> curl, CURLOPT_URL, $this -> config['site'] . 'index/sub/'); curl_setopt($this -> curl, CURLOPT_POSTFIELDS, 'user=' . $this -> config['login'] . '&password=' . $this -> config['password'] . '&rem=1&a=2&ajax=1&rnd=' . rand(100, 999)); if (strpos(curl_exec($this -> curl), 'Неправильный логин или пароль') === false) { curl_setopt($this -> curl, CURLOPT_POST, false); curl_setopt($this -> curl, CURLOPT_URL, $this -> config['site'] . 'index/14-0-0-1'); preg_match('/name\=\"ssid\"\s*?value\=\"([^"]+)\"/', curl_exec($this -> curl), $this -> session['ssid'], PREG_OFFSET_CAPTURE); $this -> session['ssid'] = $this -> session['ssid'][1][0]; curl_setopt($this -> curl, CURLOPT_POST, false); curl_setopt($this -> curl, CURLOPT_URL, $this -> config['site'] . 'shop/invoices'); return true; } else return false; } public function get_api($url) { curl_setopt($this -> curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($this -> curl, CURLOPT_POST, false); curl_setopt($this -> curl, CURLOPT_URL, $this -> config['site'] . '/api/' . $url . '?apikey=' . $this -> config['apikey']); return xmlrpc_decode(curl_exec($this -> curl)); } public function get_json($url) { curl_setopt($this -> curl, CURLOPT_HEADER, false); curl_setopt($this -> curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($this -> curl, CURLOPT_POST, false); curl_setopt($this -> curl, CURLOPT_URL, $this -> config['site']. $url); $response = curl_exec($this -> curl); if (strpos(curl_exec($this -> curl), 'Доступ запрещен') === false) { $response = substr($response, strpos($response, '>') + 1); $response = substr($response, 0, strrpos($response, '<')); return json_decode($response, true); } else return false; } public function send_post($url, $referer, $post) { foreach ($post as $key => $value) $post_line = $post_line . $key . '=' . $value . '&'; if ($referer != null) curl_setopt($this -> curl, CURLOPT_REFERER, $referer); curl_setopt($this -> curl, CURLOPT_URL, $this -> config['site'] . $url); curl_setopt($this -> curl, CURLOPT_POST, true); curl_setopt($this -> curl, CURLOPT_POSTFIELDS, $post_line); return curl_exec($this -> curl); } } ?>