Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function _runApi($url, $parameter = array()) {
- global $maxTime;
- if ($maxTime == null)
- $maxTime = 10;
- if (isset($parameter['maxTime']))
- $maxTime = $parameter['maxTime'];
- $CI = & get_instance();
- $dtAPI = array('url' => $url);
- if (count($parameter)) {
- $logTxt = "func:_runApi| url:{$url}| param:" . http_build_query($parameter, '', '&');
- } else {
- $logTxt = "func:_runApi| url:{$url}";
- $parameter['info'] = 'no post';
- }
- //$parameter[]=array('server'=>$_SERVER);
- $dtAPI['parameter'] = json_encode($parameter);
- /**
- if (count($parameter)) {
- logCreate('API: ' . "url:{$url}| param:\n" . print_r($parameter, 1), 'debug');
- } else {
- logCreate('API: param:' . print_r(parse_url($url), 1), 'debug');
- }
- **/
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- if ($parameter != '' && count($parameter) != 0) {
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_TIMEOUT, $maxTime);
- curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($parameter, '', '&'));
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
- // logCreate('API:POST', 'info');
- } else {
- // logCreate('API:GET', 'info');
- }
- curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
- $response = curl_exec($curl);
- if (0 != curl_errno($curl)) {
- $response = new stdclass();
- $response->code = '500';
- $response->message = curl_error($curl);
- $response->maxTime = $maxTime;
- $dtAPI['response'] = json_encode($response);
- $dtAPI['error'] = 1;
- } else {
- $response0 = $response;
- $dtAPI['response'] = $response;
- $dtAPI['error'] = 0;
- $response = json_decode($response, 1);
- if (!is_array($response)) {
- $response = $response0;
- $dtAPI['error'] = 1;
- } else {
- $dtAPI['error'] = 0;
- }
- }
- curl_close($curl);
- if (!isset($response0))
- $response0 = '?';
- return $response;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement