/** * This command echoes what you have entered as the message. * @param string $message the message to be echoed. */ public function actionIndex() { foreach (self::$ticks as $tick) { //Pide la ultima de todas $curl = new curl\Curl(); $response = json_decode($curl->get('https://cex.io/api/trade_history/' . $tick), true); $lastCex = $response[0]['tid']; $lastSaved = -1; do { if ($lastSaved == -1) { $lastTid = new Query(); $lastTid = $lastTid->select('max(tid) as tid')->from('trades')->where(['tick' => $tick])->one(); $lastTid = $lastTid['tid']; if (!is_null($lastTid)) { $since = $lastTid + 1; } else { $since = 1; } } else { $since = $lastSaved + 1; } $response = json_decode($curl->get('https://cex.io/api/trade_history/' . $tick . '/?since=' . $since), true); $index = count($response); $nine = $index - 1; echo 'Since:' . $since . ', Res:' . $response[$nine]['tid'] . '\\r\\n'; if ($response[$nine]['tid'] < $since) { if ($since - $response[$nine]['tid'] < 1000) { $index = $nine - ($since - $response[$nine]['tid']); } else { $since += $since - $response[$nine]['tid']; $response = json_decode($curl->get('https://cex.io/api/trade_history/' . $tick . '/?since=' . $since), true); } } while ($index) { $trade = $response[--$index]; $tradeModel = new Trades(); $tradeModel->tick = $tick; $tradeModel->type = $trade['type']; $tradeModel->date = $trade['date']; $tradeModel->amount = $trade['amount']; $tradeModel->price = $trade['price']; $tradeModel->tid = $trade['tid']; if ($tradeModel->save() && $tradeModel->tid > $lastSaved) { $lastSaved = $tradeModel->tid; } else { var_dump($tradeModel->errors); } unset($tradeModel); } } while ($lastSaved < $lastCex); } }
public function actionSay() { $url = 'http://yii.com/users'; $curl = new Curl(); $rs = $curl->get($url); p($rs); p($curl); exit; // exit; // $curl->head( 'http://yii.com/users' ); /*$curl->setOption( CURLOPT_POSTFIELDS, http_build_query(array( ) )); $rs = $curl->post($url); p($rs); $options = $curl->setOption(CURLOPT_POSTFIELDS, 'category_name')->get($url); p($options);*/ }
private function get($params) { $request = $this->uri . '?' . $this->createRequest($params); $curl = new Curl(); // var_dump($request);die; return $curl->get($request); }
public function actionGettax() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; //Init curl $curl = new curl\Curl(); //get http://example.com/ $response = $curl->get('https://invoice.zoho.com/api/v3/settings/taxes?authtoken=90545fa01029567ccd0ad3447cbf843c'); return $response; }
/** * Returned IP address of visitor if successful. * @return string|false */ public function getIp() { $curl = new Curl(); if ($curl->get(self::URL_API . 'jsonip')) { if (empty($curl->response['ip'])) { return false; } return $curl->response['ip']; } return false; }
/** * cURL GET example */ public function actionZipinfo() { //Init curl $curl = new curl\Curl(); //get http://example.com/ $response = $curl->get('http://gomashup.com/json.php?fds=geo/usa/zipcode/01001'); preg_replace('/[^a-zA-Z0-9_ %\\[\\]\\.\\(\\)%)(]/s', '', $response); $convertedResponse = str_replace("(", "", $response); $convertedResponse = str_replace(")", "", $convertedResponse); $jsonDecode = json_decode($convertedResponse); print_r($jsonDecode->result[0]->Longitude); exit; }
/** * This command echoes what you have entered as the message. * @param string $message the message to be echoed. */ public function actionIndex() { foreach (self::$ticks as $tick) { $curl = new curl\Curl(); //get http://example.com/ $response = json_decode($curl->get('https://cex.io/api/order_book/' . $tick . '/?depth=10'), true); $orderbook = new Orderbook(); $orderbook->oid = $response['id']; $orderbook->tick = $tick; $orderbook->timestamp = $response['timestamp']; $orderbook->bids = json_encode($response['bids']); $orderbook->asks = json_encode($response['asks']); $orderbook->pair = $response['pair']; $orderbook->save(); } }
/** * Look up item using UPC code and return * * @return array of item properties */ public function getItemByUPC($upcCode) { // search upcdatabase and pre-populate fields // if not found, only populate barcode field value $upcDBUrl = Yii::$app->params['apiUrl'] . '/json/' . Yii::$app->params['apiKey'] . '/' . $upcCode; $curl = new curl\Curl(); $upcResponse = $curl->get($upcDBUrl); if ($curl->responseCode) { $upcWine = BaseJson::decode($upcResponse, TRUE); if ($upcWine['valid'] == 'true') { return $upcWine; } } else { \Yii::info('Error accessing upcdatabase.log: ' . $curl->responseCode, Logger::LEVEL_ERROR); } return NULL; }
/** * Expands an URL * @param string $url URL to be expanded * @return string|boolean The expanded URL if the longUrl is set in the response, FALSE otherwise. * @throws Exception if the request fails */ public function expand($url) { $curl = new curl\Curl(); $resp = $curl->get($this->apiEndpoint . 'shortUrl=' . $url); if ($curl->responseCode !== 200) { if ($resp = json_decode($curl->response)) { throw new Exception(sprintf('Error: %s - Response: %s', $resp->error->message, $curl->response), $resp->error->code); } else { throw new Exception('Unknown Error. Response: ' . $curl->response, $curl->responseCode); } } else { $resp = json_decode($resp); if (!empty($resp->longUrl)) { return $resp->longUrl; } } return false; }
public static function get_curl($url, $params) { $url .= '?' . http_build_query($params); $curl = new Curl(); // var_dump($url);die; $curl->setOption('CURLOPT_COOKIESESSION', true); return $curl->get($url); // return \Yii::$app->getResponse()->redirect($url); // var_dump($url);die; // $myCurl = curl_init($url); // // curl_setopt_array($myCurl, array( // CURLOPT_URL => $url, // CURLOPT_RETURNTRANSFER => true, // CURLOPT_HEADER=>false // )); // $response = curl_exec($myCurl); // curl_close($myCurl); // return $response; }
public function executeCommand($commandType, $entity, $source, $params = [], $protocol = 'http://') { if (!class_exists('\\linslin\\yii2\\curl\\Curl')) { throw new Exception('linslin\\yii2\\curl\\Curl is needed.'); } $curl = new curl\Curl(); $url = $protocol . $this->endpoint . strtolower($source); $queryString = ['apiKey=' . $this->apiKey]; foreach ($params['GET'] as $key => $param) { if (!empty($param)) { $queryString[] = "{$key}=" . urlencode($param); } } $queryString = implode('&', $queryString); $url .= '?' . $queryString; Yii::trace($url, __METHOD__); if (!empty($params['POST'])) { $raw_response = $curl->setOption(CURLOPT_POSTFIELDS, json_encode(array_filter($params['POST'])))->post($url); } else { $raw_response = $curl->get($url); } if ($raw_response !== false) { $response = json_decode($raw_response, true); if ($response['Status']['Code'] !== 0) { throw new Exception('Code: ' . $response['Status']['Code'] . '. ' . $response['Status']['Message']); } switch ($commandType) { case 'COUNT': return ArrayHelper::getValue($response, $this->count_path); case 'ALL': return $response[$entity]; case 'ONE': return $response[$entity]; case 'SAVE': return $response; } } else { throw new Exception('Request Error with the following url: ' . $url); } }
public function actionGeo() { $model = new models\GeoForm(); $model->street = '1600 Amphitheatre Pkwy'; $model->city = 'Mountain View'; $model->state = 'CA'; $model->zipcode = '94043'; $model->country = 'USA'; $googleGeo = new \stdClass(); $mapQuest = new \stdClass(); $bingMap = new \stdClass(); $returnArray = []; $allDataArray = []; if ($model->load(Yii::$app->request->post())) { $curl = new Curl(); //Start google operation $googleGeo->googleApiKey = 'AIzaSyB_BgHnfwBhEQVpy9l0y8OBYXvJamzTR9E'; $googleGeo->queryString = str_replace(" ", "+", $model->street . ',' . $model->city . ',' . $model->state . ' ' . $model->zipcode . ',' . $model->country); $googleGeo->queryUrl = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . $googleGeo->queryString . '&key=' . $googleGeo->googleApiKey; $googleGeo->response = json_decode($curl->get($googleGeo->queryUrl)); $returnArray['latLon']['google'] = $googleGeo->response->results ? $googleGeo->response->results[0]->geometry->location : false; $allDataArray['google'] = $googleGeo->response; // var_dump($googleGeo->response->results[0]->geometry); //MapQuest operation $mapQuest->apiKey = 'Fmjtd%7Cluurn10b21%2C72%3Do5-9wyah4'; $mapQuest->queryString = str_replace(" ", "%20", 'street=' . $model->street . '&city=' . $model->city . '&state=' . $model->state . '&postalcode=' . $model->zipcode . '&country=' . $model->country); $mapQuest->queryUrl = 'http://www.mapquestapi.com/geocoding/v1/address?key=' . $mapQuest->apiKey . '&' . $mapQuest->queryString; $mapQuest->response = json_decode($curl->get($mapQuest->queryUrl)); $returnArray['latLon']['mapQuest'] = $googleGeo->response->results ? $mapQuest->response->results[0]->locations[0]->latLng : false; $allDataArray['mapQuest'] = $mapQuest->response; //Microsoft logic $bingMap->apiKey = 'AjC1HSirwHxS3uUD7es9zOd3D3mMuQPjpVmtyOy2YgYOlfonUOkKXZOPc_q0wQFp'; $bingMap->queryUrl = str_replace(" ", "%20", 'http://dev.virtualearth.net/REST/v1/Locations?CountryRegion=' . $model->country . '&adminDistrict=' . $model->state . '&locality=' . $model->city . '&postalCode=' . $model->zipcode . '&addressLine=' . $model->street . '&key=' . $bingMap->apiKey); $bingMap->response = json_decode($curl->get($bingMap->queryUrl)); $returnArray['latLon']['bingMap'] = $bingMap->response->resourceSets ? $bingMap->response->resourceSets[0]->resources[0]->point->coordinates : false; $allDataArray['bingMap'] = $bingMap->response; } return $this->render('geo', ['model' => $model, 'data' => $returnArray, 'allData' => $allDataArray]); }
/** * Performs an http query to catering server. * * @param string $url * @return array */ private function send($url) { $response = ['status_code' => self::CURL_EXCEPTION, 'content' => null]; $curl = new Curl(); try { $content = $curl->get($url); $response['status_code'] = $curl->responseCode; if ($curl->responseCode === 200) { $response['content'] = $content; } } catch (Exception $e) { error_log($e->getMessage()); } return $response; }
public function actionCheckver() { $curl = new curl\Curl(); $ver = $curl->get("http://utehn.plkhealth.go.th/dhdc/version/version.txt"); return $ver; }
public static function fetchData($url, $apiKey = null, $timeout = 30) { $curl = new curl\Curl(); $headers = []; if ($apiKey !== null) { $headers[] = 'X-Api-Key: ' . addslashes($apiKey) . ''; } $curl->setOption(CURLOPT_CONNECTTIMEOUT, $timeout); $curl->setOption(CURLOPT_TIMEOUT, $timeout); $curl->setOption(CURLOPT_HTTPHEADER, $headers); try { $response = $curl->get($url, false); } catch (\Exception $e) { $response = null; } if (empty($response) || !is_array($response)) { return ['data' => false, 'error' => true, 'responseCode' => (int) $curl->responseCode]; } return ['data' => $response, 'error' => false, 'responseCode' => (int) $curl->responseCode]; }
/** * @param $url * @throws HttpException */ public function checkUrl($url) { $curl = new curl\Curl(); $curl->setOption(CURLOPT_SSL_VERIFYHOST, false); $curl->setOption(CURLOPT_FOLLOWLOCATION, true); $curl->setOption(CURLOPT_RETURNTRANSFER, true); $curl->setOption(CURLOPT_AUTOREFERER, true); $curl->setOption(CURLOPT_CONNECTTIMEOUT, 10); $curl->setOption(CURLOPT_TIMEOUT, 10); $curl->setOption(CURLOPT_MAXREDIRS, 10); $curl->setOption(CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36'); $curl->get($url); if ($curl->responseCode != 200) { throw new HttpException(400, 'Something is wrong with your URL. Status code: ' . $curl->responseCode); } }
public function get($url) { $curl = new curl\Curl(); return $curl->get($url); }
public function sendSms() { $result = ""; $user = Yii::$app->user->identity; if ($this->id_user != $user->id) { return false; } if ($this->sms == 1) { $url = 'https://pbc.pbsol.ru:1443/pbc.php'; $curl = new curl\Curl(); $curl->setOption(CURLOPT_SSL_VERIFYPEER, false); $phone = $this->user->phone; switch (strlen($phone)) { case 12: $phone = substr($phone, 1); break; case 11: $phone = "7" . substr($phone, 1); break; case 10: $phone = "7" . substr($phone, 0); break; default: $result = "200"; break; } $msg = "Yasv " . $this->id; $params = ['product' => 'sms_yasv', 'password' => 'Acn752Mnt', 'phone' => $phone, 'price' => '1000', 'msg' => $msg]; $url .= '?' . http_build_query($params); $result = $curl->get($url); if ($result != "100") { $this->sms = 2; $this->save(); } } else { $result = false; } return $result; }