public static function command($command, $post = array()) { $curl = new mycurl(PickPoint::$path . 'login'); $data = json_encode(array('Login' => PickPoint::$login, 'Password' => PickPoint::$password)); $curl->setPost($data); $curl->httpheader = array('Content-Type:application/json'); $curl->createCurl(); $json = json_decode($curl->__tostring()); $SessionId = $json->SessionId; try { $curl = new mycurl(PickPoint::$path . $command); $data = json_encode(array('Login' => PickPoint::$login, 'Password' => PickPoint::$password)); if (!empty($post)) { $curl->setPost($data); } $curl->httpheader = array('Content-Type:application/json'); $curl->createCurl(); $json = json_decode($curl->__tostring()); } catch (Exception $e) { print '<pre>'; print_r($e); } $curl = new mycurl(PickPoint::$path . 'logout'); $data = json_encode(array('SessionId' => $SessionId)); $curl->setPost($data); $curl->httpheader = array('Content-Type:application/json'); $curl->createCurl(); return $json; }
public function generate($url) { if (!isset($this->domain)) { $this->domain = $url; $this->sitemap[] = $url; } echo 'CURLing ' . $url . "\n"; $MyCurl = new mycurl(); $MyCurl->createCurl($url); if ($MyCurl->getHttpStatus() === 200) { $string = $MyCurl->__tostring(); $aTags = $this->pregMatchAllATags($string); $aTags = $this->parseFollowLinksOnly($aTags[0]); $this->url_keyed_list[$url] = $aTags; foreach ($aTags as $aTag) { if (!in_array($aTag['href'], $this->sitemap)) { $this->sitemap[] = $aTag['href']; } } foreach ($this->url_keyed_list[$url] as $link) { if (isset($this->url_keyed_list[$link['href']])) { continue; } foreach ($this->non200s as $status => $list) { if (in_array($link['href'], $list)) { continue 2; } } $this->generate($link['href']); } } else { echo 'Http Status: ' . $MyCurl->getHttpStatus() . "\n"; echo 'CURL of ' . $url . " failed.\n"; if (!isset($this->non200s[$MyCurl->getHttpStatus()])) { $this->non200s[$MyCurl->getHttpStatus()] = array(); } $this->non200s[$MyCurl->getHttpStatus()][] = $url; if (in_array($url, $this->sitemap)) { $key = array_search($url, $this->sitemap); if ($key !== false) { unset($this->sitemap[$key]); } } return false; } echo 'Http Status: ' . $MyCurl->getHttpStatus() . "\n"; echo 'CURL of ' . $url . " completed.\n"; return true; }
public function createOrder($paid = 0) { $curl = new mycurl(Funcs::$conf['settings']['source'] . '/api/bill/user'); $post = array('token' => $_SESSION['iuser']['token'], 'user_id' => $_SESSION['iuser']['user_id']); $curl->setPost($post); $curl->createCurl(); $data = json_decode($curl->__tostring()); $sql = 'SELECT id FROM {{iusers}} WHERE code=\'' . $data->user_id . '\' AND author=0'; $iuser = DB::getOne($sql); if (!$iuser) { $sql = ' INSERT INTO {{iusers}} SET code=\'' . $data->user_id . '\', name=\'' . $data->name . '\', phone=\'' . $data->tel . '\' '; $iuser = DB::exec($sql); } $curl = new mycurl(Funcs::$conf['settings']['source'] . '/api/bill/payment'); $post = array('token' => $_SESSION['iuser']['token'], 'pay_id' => $_SESSION['iuser']['pay_id']); $curl->setPost($post); $curl->createCurl(); $data = json_decode($curl->__tostring()); if (!empty($data->goods)) { foreach ($data->goods as $item) { $sql = 'SELECT id FROM {{iusers}} WHERE code=\'' . $item->author_id . '\' AND author=1'; $author = DB::getOne($sql); if (!$author) { $sql = ' INSERT INTO {{iusers}} SET code=\'' . $item->author_id . '\', name=\'' . $item->name_author . '\', author=1 '; $author = DB::exec($sql); } $authorprice = round($item->amount - $item->amount / 100 * Funcs::$conf['settings']['comm'], 2); $sql = ' INSERT INTO {{orders}} SET iuser='******', author=' . $author . ', iuserprice=' . $item->amount . ', authorprice=' . $authorprice . ', payid=' . $_SESSION['iuser']['pay_id'] . ', paymentid=\'' . $_POST['paymentid'] . '\', commision=' . Funcs::$conf['settings']['comm'] . ', goodsid=\'' . $item->id . '\', goodsname=\'' . $item->name . '\', cdate=NOW(), paid=' . $paid . ' '; $orderid = DB::exec($sql); if ($paid == 1) { $sql = 'UPDATE {{iusers}} SET balance=balance+' . $authorprice . ' WHERE id=' . $author . ''; DB::exec($sql); $sql = 'UPDATE {{iusers}} SET balance=balance+' . $item->amount . ' WHERE id=' . $iuser . ''; DB::exec($sql); } } } }
function get_url($url) { $content = ''; $cur_time = time(); $filename = "requests/" . md5($url) . ".json"; //echo $filename; $getNew = FALSE; if (file_exists($filename)) { //echo '<br>file exists'; $file = basename($filename, ".json"); $old_time = filemtime($filename); //echo '<br> Prev time: '.$old_time; $mins = $cur_time - $old_time; //echo " -- ".$mins; if ($mins >= 300) { $getNew = TRUE; } else { $content = file_get_contents($filename); } } else { //echo '<br>file does not exists'; $getNew = TRUE; } if ($getNew) { //echo '<br> getting new'; $needLogin = TRUE; if ($needLogin) { //echo '<br>need login'; $login_url = 'http://www.reddit.com/api/login/username'; $curl = new mycurl(); $curl->setCookiFileLocation('requests/cookie.txt'); $data = array('api_type' => 'json', 'user' => 'ReillyKlevre', 'passwd' => 'password'); $curl->setPost($data); $curl->createCurl($login_url); if ($curl->getHttpStatus() != 200) { echo '<br>LOGIN ERROR > HTTP STATUS: ' . $curl->getHttpStatus(); exit; } } //echo '<br>after: '.$url; $curl = new mycurl(); $curl->setCookiFileLocation('requests/cookie.txt'); $curl->createCurl($url); if ($curl->getHttpStatus() != 200) { echo '<br>REDDIT_URL ' . $url . ' > HTTP STATUS: ' . $curl->getHttpStatus(); exit; } $content = $curl->__tostring(); if ($content) { $fp = fopen($filename, 'w'); fwrite($fp, $content); fclose($fp); } } return $content; }
curl_setopt($s, CURLOPT_HEADER, true); } if ($this->_noBody) { curl_setopt($s, CURLOPT_NOBODY, true); } if ($this->_binaryTransfer) { curl_setopt($s, CURLOPT_BINARYTRANSFER, true); } if ($this->_freshConnect) { curl_setopt($s, CURLOPT_FRESH_CONNECT, $this->_freshConnect); } curl_setopt($s, CURLOPT_USERAGENT, $this->_useragent); curl_setopt($s, CURLOPT_REFERER, $this->_referer); $this->_webpage = curl_exec($s); $this->_status = curl_getinfo($s, CURLINFO_HTTP_CODE); curl_close($s); } public function getHttpStatus() { return $this->_status; } public function __tostring() { return $this->_webpage; } } $url = "http://shortmsg.net"; $curl = new mycurl($url); $curl->createCurl(); echo $curl->__tostring(); echo $curl->getHttpStatus();
public function &sendRequest($url, $checkResultTag = false, &$filecontent = null, $filename = '') { $url = str_replace('#', '%23', $url); if (isset($this->serial) && !is_null($this->serial)) { $url = 'https://' . $this->apihost . '/api/?key=' . $this->apikey . '&target=' . $this->serial . '&' . $url; } else { $url = 'https://' . $this->apihost . '/api/?key=' . $this->apikey . '&' . $url; } if ($this->showApiCalls) { print "API call: \"" . $url . "\"\r\n"; } $c = new mycurl($url); if (!is_null($filecontent)) { $c->setInfile($filecontent, $filename); } if (!$c->createCurl()) { derr('Could not retrieve URL: ' . $url . ' because of the following error: ' . $c->last_error); } $xmlobj = new XmlArray(); if ($c->getHttpStatus() != 200) { derr('HTTP API ret: ' . $c->__tostring()); } $xmlarr = $xmlobj->load_string($c->__tostring()); if (!is_array($xmlarr)) { derr('API didnt return a XML string: ' . $c->__tostring()); } if (!isset($xmlarr['attributes']['status'])) { derr('XML response has no "status" field: ' . array_to_xml($xmlarr)); } if ($xmlarr['attributes']['status'] != 'success') { derr('API reported a failure: ' . $c->__tostring()); } if (!is_null($filecontent)) { return $xmlarr['children']; } if (!$checkResultTag) { return $xmlarr['children']; } //print_r( $xmlarr['children'] ); $cursor =& searchForName('name', 'result', $xmlarr['children']); if (is_null($cursor)) { derr('XML API response has no <result> field:' . $c->__tostring()); } if (is_null($cursor['children'])) { derr('XML API <result> has no content'); } return $cursor['children']; }
if ($this->_noBody) { curl_setopt($s, CURLOPT_NOBODY, true); } /* if($this->_binary) { curl_setopt($s,CURLOPT_BINARYTRANSFER,true); } */ curl_setopt($s, CURLOPT_USERAGENT, $this->_useragent); curl_setopt($s, CURLOPT_REFERER, $this->_referer); $this->_webpage = curl_exec($s); $this->_status = curl_getinfo($s, CURLINFO_HTTP_CODE); curl_close($s); $dtime = $this->microtime_float(); $this->run_time = $dtime - $time; } public function getHttpStatus() { return $this->_status; } public function __tostring() { return $this->_webpage; } } $curl = new mycurl('https://qa.feed.biz:3001/get_process?system_num_process'); $curl->createCurl(); echo 'Output: ' . $curl->__tostring() . ' ' . $curl->run_time . '<br>'; $out = file_get_contents('https://qa.feed.biz:3001/get_process?system_num_process'); echo 'File get: ' . $out . '<br>';
/** * @param string $parameters * @param bool $checkResultTag * @param string|null $filecontent * @param string $filename * @param Array $moreOptions * @return DomDocument */ public function sendRequest(&$parameters, $checkResultTag = false, &$filecontent = null, $filename = '', $moreOptions = array()) { $sendThroughPost = false; if (is_array($parameters)) { $sendThroughPost = true; } $host = $this->apihost; if ($this->port != 443) { $host .= ':' . $this->port; } if (isset($this->serial) && !is_null($this->serial)) { $finalUrl = 'https://' . $host . '/api/'; if (!$sendThroughPost) { $finalUrl .= '?key=' . $this->apikey . '&target=' . $this->serial; } } else { $finalUrl = 'https://' . $host . '/api/'; if (!$sendThroughPost) { $finalUrl .= '?key=' . $this->apikey; } } if (!$sendThroughPost) { $url = str_replace('#', '%23', $parameters); $finalUrl .= '&' . $parameters; } if (isset($moreOptions['timeout'])) { $timeout = $moreOptions['timeout']; } else { $timeout = 7; } $c = new mycurl($finalUrl, false, $timeout); if (array_key_exists('lowSpeedTime', $moreOptions)) { $c->_lowspeedtime = $moreOptions['lowSpeedTime']; } if (!is_null($filecontent)) { $c->setInfile($filecontent, $filename); } if ($sendThroughPost) { if (isset($this->serial) && !is_null($this->serial)) { $parameters['target'] = $this->serial; } $parameters['key'] = $this->apikey; $properParams = http_build_query($parameters); $c->setPost($properParams); } if ($this->showApiCalls) { if ($sendThroughPost) { $paramURl = '?'; foreach ($parameters as $paramIndex => &$param) { $paramURl .= '&' . $paramIndex . '=' . str_replace('#', '%23', $param); } print "API call through POST: \"" . $finalUrl . '?' . $paramURl . "\"\r\n"; } else { print "API call: \"" . $finalUrl . "\"\r\n"; } } if (!$c->createCurl()) { derr('Could not retrieve URL: ' . $finalUrl . ' because of the following error: ' . $c->last_error); } if ($c->getHttpStatus() != 200) { derr('HTTP API ret: ' . $c->__tostring()); } $xmlDoc = new DOMDocument(); if (!$xmlDoc->loadXML($c->__tostring(), LIBXML_PARSEHUGE)) { derr('Invalid xml input :' . $c->__tostring()); } $firstElement = DH::firstChildElement($xmlDoc); if ($firstElement === false) { derr('cannot find any child Element in xml'); } $statusAttr = DH::findAttribute('status', $firstElement); if ($statusAttr === false) { derr('XML response has no "status" field: ' . DH::dom_to_xml($firstElement)); } if ($statusAttr != 'success') { var_dump($statusAttr); derr('API reported a failure: "' . $statusAttr . "\"with the following addition infos: " . $firstElement->nodeValue); } if (!is_null($filecontent)) { return $xmlDoc; } if (!$checkResultTag) { return $xmlDoc; } //$cursor = &searchForName('name', 'result', $xmlarr['children']); $cursor = DH::findFirstElement('result', $firstElement); if ($cursor === false) { derr('XML API response has no <result> field', $xmlDoc); } DH::makeElementAsRoot($cursor, $xmlDoc); return $xmlDoc; }