public static function run($method, $params = []) { self::$defaultParam = ['method' => $method, 'module' => 'API', 'token_auth' => STAT_API_TOKEN, 'format' => 'JSON', 'expanded ' => true, 'idSite' => 1, 'filter_offset' => \yii::$app->request->get('filter_offset', 0), 'filter_limit' => \yii::$app->request->get('filter_limit', 50)]; $params['formatDate'] = isset($params['formatDate']) ? $params['formatDate'] : null; if ($params['formatDate'] !== false) { self::formatDate(); } unset($params['formatDate']); $params = array_merge(self::$defaultParam, $params); $params = array_filter($params); $curl = new Curl(); $curl->setJsonDecoder(function ($response) { $json_obj = json_decode($response, true); if (!($json_obj === null)) { $response = $json_obj; } return $response; }); $curl->get(STAT_API_URL, $params); $curl->close(); if ($curl->error) { echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; } else { return $curl->response; } }
public function __construct($iniFile) { $this->loadBaseMods(); $this->loadIni($iniFile); $this->pdo = new lw\Pdo($this, $this->configArray['Pdo']); $this->curl = new \Curl\Curl(); //Set this option because WAMP sucks $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, false); //Set this because all the returns are expecting JSON string, and Curl updated to do it automatically. $this->curl->setJsonDecoder(function ($response) { return $response; }); $this->url = $this->configArray['Site']['url']; $this->title = $this->configArray['Site']['title']; Core::setApiKey($this->configArray['Site']['APIKEY']); }
public function run($params) { $params = array_merge(self::$default, $params); $curl = new Curl(); $curl->setJsonDecoder(function ($response) { $json_obj = json_decode($response, true); if (!($json_obj === null)) { $response = $json_obj; } return $response; }); $curl->get(self::STAT_API_URL, $params); $curl->close(); if ($curl->error) { echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; } else { return $curl->response; } }
public static function get($users, $type, $ref) { $url = 'http://' . self::$referrerType[$ref] . '.gallary.work/api/user/GetUserData'; $params = ['userName' => $users, 'userDataType' => $type, 'signKey' => self::SIGN_KEY, 'lastLoginStartTime' => '', 'lastLoginEndTime' => '', 'datatype' => 'json']; $curl = new Curl(); $curl->setJsonDecoder(function ($response) { $json_obj = json_decode($response, true); if (!($json_obj === null)) { $response = $json_obj; } return $response; }); $curl->get($url, $params); $curl->setConnectTimeout(10); $curl->close(); if ($curl->error) { return false; } else { if ($curl->response === false) { return false; } return $curl->response; } }
/** * Google Places API Web Service * Place Details * * @param string $placeId * @return array * @see https://developers.google.com/places/web-service/details */ private function placeDetails($placeId) { $curl = new Curl(); $curl->setTimeout(15); $curl->setOpt(CURLOPT_SSL_VERIFYHOST, false); $curl->setJsonDecoder(function ($string) { return json_decode($string, true); }); $curl->get(Config::get('googleplaces.api_details'), ['key' => Config::get('googleplaces.key'), 'language' => 'zh-CN', 'placeid' => $placeId]); if ($curl->error) { return ['status' => $curl->errorMessage]; } else { $response = $curl->response; foreach ($response['result']['address_components'] as $i => $item) { $response['result']['address_components'][$item['types'][0]] = $item; unset($response['result']['address_components'][$i]); } return $response; } }