protected function getData($url, $session_var = '', $cache = false)
 {
     if (!$cache || !isset($_SESSION[$session_var])) {
         // get events
         $curl = new Curl\Curl();
         $curl->setHeader($this->config['auth_header_name'], $_SESSION['AUTH_TOKEN']);
         $curl->setHeader("Content-Type", "application/json");
         $curl->get($this->config['rest_api_url'] . $url);
         if (!$curl->error) {
             $result = json_decode($curl->raw_response, true);
             if (is_array($result)) {
                 $this->logger->debug("Retrieve data from { {$url} } : ", $result);
             } else {
                 $this->logger->debug("Retrieve data from { {$url} } : " . $result);
             }
             $_SESSION[$session_var] = $result;
             return $result;
         } else {
             return null;
         }
     } else {
         $this->logger->debug("Get from cache { {$url} } : ", $_SESSION[$session_var]);
     }
     return $_SESSION[$session_var];
 }
Пример #2
0
 private function tempGetContent($url)
 {
     $curl = new \Curl\Curl();
     $curl->get($url);
     $content = $curl->response;
     if (empty($content)) {
         return '';
     }
     $dom = new \DOMDocument('1.0', 'utf-8');
     libxml_use_internal_errors(true);
     $dom->loadHTML($content);
     libxml_clear_errors();
     $dom->preserveWhiteSpace = false;
     // remove redundant white spaces
     $body = $dom->getElementsByTagName('body');
     $bodyContent = null;
     if ($body && $body->length > 0) {
         // remove scripts
         while (($r = $dom->getElementsByTagName('script')) && $r->length) {
             $r->item(0)->parentNode->removeChild($r->item(0));
         }
         $domBody = $body->item(0);
         $bodyContent = $dom->saveXML($domBody);
         //$bodyContent = $this->dom->saveHTML($this->domBody); // argument not allowed on 5.3.5 or less, see: http://www.php.net/manual/de/domdocument.savehtml.php
     }
     return $bodyContent;
 }
Пример #3
0
 public function get($path)
 {
     $curl = new \Curl\Curl();
     $this->getToken();
     $curl->setHeader('Authorization', 'Bearer ' . $this->token);
     $curl->get($this->baseUrl . $path);
     dd($curl->response);
     if ($curl->error) {
         return $curl->error_code;
     } else {
         $response = json_decode($curl->response);
         return $response;
     }
 }
 public function getCurl($endpoint, $data = array())
 {
     $URL = env(env('API_ENV'));
     $curl = new \Curl\Curl();
     $curl->setUserAgent('twh.22523085;BaseCamp Software;');
     $curl->setopt(CURLOPT_SSL_VERIFYPEER, FALSE);
     $data += array('output' => 'json', 'token' => $this->token);
     $curl->get($URL . $endpoint, $data);
     if ($curl->error) {
         die("Error:" . $curl->error_code);
     } else {
         $json = json_decode($curl->response);
         return $json;
     }
 }
Пример #5
0
 /**
  * 得到模糊坐标
  */
 public function getPoint($area, $address, $key)
 {
     //百度地图接口:http://api.map.baidu.com/geocoder/v2/address=地址&output=输出格式类型&key=用户密钥&city=城市名
     //需要4个参数:address详细地址,output格式,ak接口密匙,city城市名
     //地区转换
     //        $areaModel = AreaModel::find($area);
     //        $areaname = $areaModel ? $areaModel->cityname : '';
     $cityModel = new AreaModel();
     $areaname = $area ? $cityModel->getAreaName($area) : '';
     //请求接口,返回数据
     $apiUrl = 'http://api.map.baidu.com/geocoder/v2/';
     $curl = new \Curl\Curl();
     $curl->setHeader('X-Authorization', $key);
     $curl->get($apiUrl, array('address' => $address, 'output' => 'json', 'ak' => $key, 'city' => $areaname));
     $response = json_decode($curl->response);
     $response = \App\Tools::objectToArray($response);
     if ($response['status'] != 0) {
         if ($response['status'] == 1) {
             echo "<script>alert('地址有误或百度地图服务器内部有变!');history.go(-1);</script>";
             exit;
         } elseif ($response['status'] == 2) {
             echo "<script>alert('地区或地址有误!');history.go(-1);</script>";
             exit;
         } elseif ($response['status'] == 3) {
             echo "<script>alert('权限校验失败!');history.go(-1);</script>";
             exit;
         } elseif ($response['status'] == 4) {
             echo "<script>alert('配额校验失败!');history.go(-1);</script>";
             exit;
         } elseif ($response['status'] == 5) {
             echo "<script>alert('百度地图密匙错误!');history.go(-1);</script>";
             exit;
         } elseif ($response['status'] == 101) {
             echo "<script>alert('服务禁用!');history.go(-1);</script>";
             exit;
         } elseif ($response['status'] == 102) {
             echo "<script>alert('百度地图密匙权限不足!');history.go(-1);</script>";
             exit;
         } elseif ($response['status'] == "2xx") {
             echo "<script>alert('无权限!');history.go(-1);</script>";
             exit;
         } elseif ($response['status'] == "3xx") {
             echo "<script>alert('配额错误!');history.go(-1);</script>";
             exit;
         }
     }
     return $response['result']['location'];
 }
Пример #6
0
 public function get_time_estimates(Request $request)
 {
     $latitude = $request->input('latitude');
     $longitude = $request->input('longitude');
     $product_id = $request->input('product_id');
     $curl = new \Curl\Curl();
     $params = [];
     if ($product_id) {
         $params = ['server_token' => env('UBER_SERVER_TOKEN'), 'start_latitude' => $latitude, 'start_longitude' => $longitude, 'product_id' => $product_id];
     } else {
         $params = ['server_token' => env('UBER_SERVER_TOKEN'), 'start_latitude' => $latitude, 'start_longitude' => $longitude];
     }
     $curl->get($this->sandbox_url . 'v1/estimates/time', $params);
     $data = json_decode($curl->response);
     return \Response::json($data);
 }
Пример #7
0
 public function actionIndex()
 {
     $sites = [];
     foreach (Site::find()->all() as $site) {
         $sites[] = ['data' => $site->toArray(), 'remote' => $site->getRemote()];
     }
     $curl = new \Curl\Curl();
     $curl->get('https://packagist.org/packages/zephir/luya.json');
     $json = Json::decode($curl->response);
     foreach ($json['package']['versions'] as $version => $package) {
         if ($version == 'dev-master') {
             continue;
         }
         $this->current = $package;
         break;
     }
     return $this->renderPartial('index', ['sites' => $sites, 'currentVersion' => $this->current]);
 }
Пример #8
0
 public function tryProcess()
 {
     $result = false;
     if (!empty($this->url)) {
         $curl = new \Curl\Curl();
         $curl->get($this->url);
         if ($curl->error) {
             $this->_error = $curl->errorCode . ': ' . $curl->errorMessage;
         } else {
             $response = $curl->rawResponse;
             if (!empty($response)) {
                 $this->_data = json_decode($response);
                 $result = true;
             }
         }
     }
     return $result;
 }
Пример #9
0
 public function getRemote()
 {
     $url = Url::trailing($this->url);
     $data = Yii::$app->cache->get($url);
     if ($data === false) {
         $curl = new \Curl\Curl();
         if ($this->auth_is_enabled) {
             $curl->setBasicAuthentication($this->auth_user, $this->auth_pass);
         }
         $curl->get($url . 'admin/api-admin-remote?token=' . sha1($this->token));
         if ($curl->error) {
             $data = false;
         } else {
             $data = json_decode($curl->response, true);
         }
         Yii::$app->cache->set($url, $data, 60 * 2);
     }
     return $data;
 }
Пример #10
0
function download($url, $store_dir)
{
    $filename = get_image_filename($url, $store_dir);
    if (file_exists($filename)) {
        return;
    }
    //存在时不下载
    $curl = new Curl\Curl();
    $curl->setHeader('X-Requested-With', 'XMLHttpRequest');
    $curl->setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:40.0) Gecko/20100101 Firefox/40.0');
    $curl->setHeader('Accept-Language', 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3');
    $curl->setHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
    @mkdir($store_dir, 0755, true);
    $curl->get($url);
    $data = $curl->response;
    file_put_contents($filename, $data);
    try {
        $image = new \Eventviva\ImageResize($filename);
        $image->resizeToWidth(JS_IMG_WIDTH);
        $image->save($filename);
    } catch (Exception $e) {
    }
    return $filename;
}
Пример #11
0
<?php

session_start();
$code = $_GET['code'];
$state = $_GET['state'];
if ($state != $_SESSION['wx_state']) {
    echo 'error state';
    return;
}
if (!$code) {
    echo 'no code';
    return;
}
$appid = 'wx3602f3ba4c085c82';
$secret = 'e72b58b099303b5f99dd4f25975a6444';
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$secret}&code={$code}&grant_type=authorization_code";
require_once __DIR__ . '/Curl/autoload.php';
$curl = new \Curl\Curl();
$ret = $curl->get($url);
echo $ret;
file_put_contents('/tmp/wx_data.log', $ret, FILE_APPEND);
Пример #12
0
 public function run($method, $data = array(), $auth = false)
 {
     if ($auth) {
         $this->authenticate();
         $data['access_token'] = $this->getToken();
     }
     $data = http_build_query($data);
     $url = $this->urls['link'] . $method . '?' . $data;
     $curl = new Curl\Curl();
     $resp = $curl->get($url);
     return $resp;
 }
Пример #13
0
 static function check_latest()
 {
     echo "####: Initiating cURL request<br>";
     $curl = new Curl\Curl();
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $curl->get(upgrader::$base_url . 'news/latest.php');
     if ($curl->error) {
         echo '&nbsp;&nbsp;Error: ' . $curl->error_code . ': ' . $curl->error_message;
     } else {
         $arr = explode("|", $curl->response);
         echo "1.3> Response: <br>" . "Raw: " . $curl->response . '<br>' . "Latest version is " . $arr[0] . "<br>" . "File to be downloaded to cache dir: " . $arr[1] . "<br>";
         // unset($_SESSION['codo_file_to_download']);
         // var_dump($_SESSION);
         $_SESSION['codo_file_to_download'] = trim($arr[1]);
         $_SESSION['codo_file_to_download_hash'] = trim($arr[2]);
         // $_SESSION['542d2e3195cfeA_loggedin_avatar']=22;
         upgrader::$latest_version = $arr[0];
         if (upgrader::is_required()) {
             echo "1.4> Initiating Download phase 2.0...<hr>";
         } else {
             echo "&nbsp;&nbsp;&nbsp;&nbsp; You are using the latest version :)";
         }
     }
 }
Пример #14
0
<?php

include 'init.php';
if (!isset($argv[1])) {
    die('You need to specify sleeping time as the first argument!');
}
sleep($argv[1]);
writeLog('info', 'Checking');
$curl = new Curl\Curl();
$curl->setOpt(CURLOPT_TIMEOUT, 5000);
$curl->setHeader('Cookie', $config['cookie']);
$curl->setHeader('Upgrade-Insecure-Requests', '1');
$curl->get('http://sms.tsu.ge/sms/Students/StudIndCxrili.aspx');
if ($curl->error) {
    writeLog('info', 'Error');
    writeLog('error', $curl->error_message);
    die($curl->error_message);
}
file_put_contents(__DIR__ . '/lastResponse.txt', $curl->response);
if (strpos($curl->response, $config['loggedInText']) == false) {
    writeLog('error', 'Cookie issue');
    die('Cookie -ით შესვლა ვერ მოხერხდა' . PHP_EOL);
}
if (strpos($curl->response, $config['succussText']) !== false) {
    writeLog('info', 'Opened');
    writeLastResult('on');
    die('გაიხსნა!' . PHP_EOL);
}
writeLog('info', 'Closed');
writeLastResult('off');
echo 'ჯერ არ არის გახსნილი!' . PHP_EOL;
/**
 * @param string $title Title of the building
 * @param string $street Street name with house number
 * @param string $zip Zip code
 * @param string $city City of the location
 * @return array Array with first element the longitude and second the latitude, if available.
 */
function getLongLatForAddress($title, $street, $zip, $city)
{
    if (empty($street) || empty($zip) || empty($city)) {
        return array('', '');
    }
    // try to find a building entry in our cache which has the given address
    $entry = R::findOne('buildinggeometry', ' street = ? AND zip = ? AND city = ? ', array($street, $zip, $city));
    // if entry is not already in our cache
    if (null == $entry) {
        $entry = R::dispense('buildinggeometry');
        $entry->title = $title;
        $entry->street = $street;
        $entry->zip = $zip;
        $entry->city = $city;
        $entry->lng = "";
        $entry->lat = "";
    }
    // if long and lat is not set, try to get it from google
    if ('' == $entry->long && '' == $entry->lat) {
        $curl = new Curl\Curl();
        // ask google for geometry information for a given address
        $curl->get('http://maps.googleapis.com/maps/api/geocode/json', array('address' => $street . ' ' . $zip . ' ' . $city));
        // store JSON result
        $latLongInformation = json_decode(json_encode($curl->response), true);
        if (isset($latLongInformation['results'][0]['geometry']['location']['lat']) && isset($latLongInformation['results'][0]['geometry']['location']['lng'])) {
            $entry->lng = $latLongInformation['results'][0]['geometry']['location']['lng'];
            $entry->lat = $latLongInformation['results'][0]['geometry']['location']['lat'];
            R::store($entry);
        } else {
            echo PHP_EOL . PHP_EOL . $title;
            echo PHP_EOL . $street . ' ' . $zip . ' ' . $city;
            echo PHP_EOL . 'no lat OR long';
            $entry->lng = '';
            $entry->lat = '';
        }
    }
    return array($entry->lng, $entry->lat);
}