示例#1
0
 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;
 }
function rnPost($url, $data)
{
    $curl = new mycurl($url);
    $curl->setPost($data);
    $curl->createCurl();
    return $curl;
}
示例#3
0
    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);
                }
            }
        }
    }
示例#4
0
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;
}
 /**
  * @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;
 }
示例#6
0
 protected function get_data_curl($entityID, $termID, $FYFQ, $specialFormat)
 {
     //first we attempt to get the data from the session
     //if no data is stored in the session, we get data from API
     $cacheKey = $this->get_cache_key($entityID, $termID, $FYFQ, $specialFormat);
     $use_cache = FALSE;
     if ($this->config->item('use_cache') === TRUE) {
         $use_cache = TRUE;
         $from_session = true;
         $result = $this->session->userdata($cacheKey);
     }
     if (empty($result)) {
         $url = API_URL . API_GET_DATA_SERVICE;
         $user = API_AUTH__USER;
         $pass = API_AUTH_PASSE;
         //var_dump($data);
         $this->benchmark->mark('Api_model-curl_start');
         $_mycurl = new mycurl($url, $user, $pass);
         $_mycurl->setPost($cacheKey);
         $_mycurl->createCurl();
         $result = (string) $_mycurl;
         $result = json_decode($result, true);
         $this->benchmark->mark('Api_model-curl_end');
         log_message('debug', 'Api_model-curl: ' . $this->benchmark->elapsed_time('Api_model-curl_start', 'Api_model-curl_end'));
         //log_message('debug', 'Api_model-curl: json_decode: ' . print_r($result, true));
         $from_session = false;
     }
     /* don't cache */
     if ($use_cache === TRUE && !$from_session && !empty($result)) {
         $this->session->set_userdata($cacheKey, $result);
     }
     /* */
     //var_dump($result);
     return $result;
 }