/** * docomoの対話APIを叩いてレスポンスを貰ってくる * * @param string $apikey docomoAPIキー * @param string $context 会話のコンテキストID(API仕様参照) * @param string $mode 会話のモード(API仕様参照 * @param string $nickname 会話している人間側の名前 * @param string $text 人間側の入力テキスト * @return stdClass レスポンスのJSONをデコードしたオブジェクト * @throws \Exception サーバとの通信に失敗した場合 */ private function getData($apikey, $context, $mode, $nickname, $text) { $userData = ['utt' => (string) $text, 'context' => (string) $context, 'nickname' => (string) $nickname, 'mode' => (string) $mode]; $url = sprintf('https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?APIKEY=%s', rawurlencode($apikey)); Log::info("docomo対話APIを呼び出します"); Log::info("URL: " . $url); Log::info("パラメータ:"); Log::info($userData); $curl = new Curl(); $curl->setHeader('Content-Type', 'application/json; charset=UTF-8'); $ret = $curl->post($url, json_encode($userData)); if ($curl->error) { Log::error(sprintf("docomo対話APIの呼び出しに失敗しました: %d: %s", $curl->error_code, $curl->error_message)); throw new \Exception('docomo dialogue error: ' . $curl->error_code . ': ' . $curl->error_message); } Log::info("docomoからのデータ:"); Log::info($ret); if (is_object($ret) && isset($ret->utt)) { if ($ret->utt == '') { Log::warning(" docomo 指示文章が空です"); } else { Log::success(" docomo 指示文章: " . $ret->utt); } return $ret; } Log::error("docomoから受け取ったデータが期待した形式ではありません:"); Log::error($ret); throw new \Exception('Received an unexpected data from docomo server'); }
/** * * https://developer.priceminister.com/blog/fr/documentation/product-data/product-listing-secure * * @return mixed */ public function callWebservice() { $urlToCall = 'https://ws.priceminister.com/listing_ssl_ws'; $curl = new Curl(); $curl->get($urlToCall, ['action' => 'listing', 'login' => $this->credentials['login'], 'pwd' => $this->credentials['password'], 'version' => '2015-07-05', 'scope' => 'PRICING', 'kw' => $this->searchTerm, 'refs' => '', 'nbproductsperpage' => 20, 'pagenumber' => 1]); return $curl->response; }
protected function getAccessToken() { $url_query = '?grant_type=' . $this->grant_type; $url_query .= '&appid=' . $this->appid; $url_query .= '&secret=' . $this->secret; $curl = new Curl(); $curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE); $curl->setOpt(CURLOPT_SSL_VERIFYHOST, FALSE); $curl->get($this->token_api . $url_query); if ($curl->error) { echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; } else { if (isset($curl->response->errcode)) { switch ($curl->response->errcode) { case '40002': die($curl->response->errmsg); break; case '40013': die($curl->response->errmsg); break; case '40125': die($curl->response->errmsg); break; default: throw new TokenExpiredException("未知错误"); break; } } else { return $curl->response; } } }
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; } }
/** * Create user cache. * * @param string $user Twitter screen name * @return bool If successful true * @throws CacheException Any errors */ public function create($user) { try { $path = config("cache.path") . "/{$user}"; $json_file = "{$path}/data.json"; if (!$this->exists($user)) { mkdir($path); } if (!file_exists($json_file)) { touch($json_file); } $response = $this->twistOAuth->get("users/show", ["id" => $user]); $image_url = str_replace("_normal", "", $response->profile_image_url_https); $info = new SplFileInfo($image_url); $curl = new Curl(); $curl->setUserAgent(SaveTweet::APP_NAME . "/" . SaveTweet::APP_VERSION . " with PHP/" . PHP_VERSION); $curl->download($image_url, "{$path}/icon.{$info->getExtension()}"); $curl->close(); $data = ["name" => $response->name, "screen_name" => $response->screen_name, "id" => $response->id_str, "icon" => config("cache.http_path") . "/{$response->id_str}/icon.{$info->getExtension()}", "org_icon" => $image_url, "update_at" => time()]; $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); (new SplFileObject($json_file, "w"))->fwrite($json); return true; } catch (RuntimeException $e) { $this->_catch($e); } }
public function send($url, $method, array $parameters = [], array $postParameters = [], array $header = [], $content = '') { $this->curl->setOpt(CURLOPT_RETURNTRANSFER, true); $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, false); $method = strtolower($method); $finalUrl = strpos($url, '//') !== false ? $url : $this->url . $url; if (!empty($this->authorization) && empty($header['Authorization'])) { $authClass = 'Bennsel\\WindowsAzureCurl\\Service\\Authorization\\' . $this->authorization; $class = new $authClass($this->settings); $header['Authorization'] = $class->getAuthorizationString($url, $method, $parameters, $header); } if ($content && is_object($content) && method_exists($content, 'toArray')) { $parameters = $content->toArray(); } foreach ($header as $key => $value) { $this->curl->setHeader($key, $value); } $orgHeader = $header; $r = $this->curl->{$method}($finalUrl, $parameters ?: $postParameters); if ($this->curl->http_status_code == 301) { $this->url = $this->curl->response_headers['Location']; return $this->send($url, $method, $parameters, $postParameters, $orgHeader, $content); } return ResponseModelMapping::create($url, $r); }
/** * @param string $apiKey * @param string $apiSecret * @param int $subAccountId * * @return AccountResponse */ public static function deleteSubAccount($apiKey, $apiSecret, $subAccountId) { $apiEndpoint = sprintf('%s/subaccounts/%s', self::API_URL, $subAccountId); $curl = new Curl(); $curl->delete($apiEndpoint, json_encode(['api_key' => $apiKey, 'api_secret' => $apiSecret])); return self::parseResponse($curl); }
/** * HTTP GET wrapper for Curl. * For requests with additional query parameters. * * @param string $url URL to GET request to. * @return mixed Response data. */ public function getWithParams($url) { $curl = new Curl(); $curl->get($this->endpoint . $url . '&api_token=' . $this->token); $curl->close(); return json_decode($curl->response); }
static function trigger($channel, $event, $data) { WebpushPHP::validate(); $curl = new Curl(); $response = $curl->post(WebpushPHP::$apipath . '/trigger', ['token' => WebpushPHP::$token, 'secret' => WebpushPHP::$secret, 'channel' => $channel, 'event' => $event, 'data' => json_encode($data)]); return $response; }
public function deleteBounce($email) { $param = ['api_user' => $this->apiUser, 'api_key' => $this->apiKey, 'email' => $email]; $curl = new Curl(); $response = $curl->get(self::API_BOUNCES_DELETE, $param); return $response; }
/** * * @param string $query * @return * @throw */ public function sendSparqlUpdateQuery($query) { // TODO extend Accept headers to further formats $this->client->setHeader("Accept", "application/sparql-results+json"); $this->client->setHeader("Content-Type", "application/sparql-update"); return $this->client->get($this->url, array("query" => $query)); }
private function getTrackingInformation() { $curl = new Curl(); $curl->get(self::BPOST_API_ENDPOINT . 'items?itemIdentifier=' . $this->getItemNumber()); if ($curl->error) { throw new Exception('CURL error while fetching tracking information: ' . $curl->errorCode . ': ' . $curl->errorMessage); } // Curl library already decoded the JSON (cool!) $response = $curl->response[0]; // Decode sender $rawSender = $response->sender; $this->sender = new SenderReceiver($rawSender->countryCode, $rawSender->municipality, $rawSender->postcode); // Decode receiver $rawReceiver = $response->receiver; $this->receiver = new SenderReceiver($rawReceiver->countryCode, $rawReceiver->municipality, $rawReceiver->postcode, $rawReceiver->name); // Some other stuff $this->weight = (int) $response->weightInGrams; $this->customerReference = $response->customerReference; $this->requestedDeliveryMethod = $response->requestedDeliveryMethod; // Decode events $rawEvents = $response->events; foreach ($rawEvents as $rawEvent) { $lang = self::LANGUAGE; $eventDescription = $this->translateKey($rawEvent->key); $statusUpdate = new StatusUpdate($rawEvent->date, $rawEvent->time, $eventDescription, $rawEvent->location->{$lang}); array_push($this->statusUpdates, $statusUpdate); } }
protected function _processTask() { try { $curl = new Curl(); $curl->setUserAgent('got/Tarth'); if ($this->includeTarthHeader) { $curl->setHeader(\Tarth\Tool\Task::HEADER_ALLERIA_CRC, \Tarth\Tool\Task::getTarthHeader($this)); } if (isset($this->header)) { foreach ($this->header as $key => $value) { $curl->setHeader($key, $value); } } call_user_func_array(array($curl, strtolower($this->method)), array($this->url, $this->data)); if ($curl->error) { return false; } else { //响应码大于300为请求失败 return $curl->httpStatusCode < 300; //接口返回为json格式,返回值中有code为0 //return $curl->response->code == 0; } } catch (Exception $e) { } }
public static function getWeChatIp() { $api = 'https://api.weixin.qq.com/cgi-bin/getcallbackip'; $url_query = '?access_token=' . self::$token->getToken(); $curl = new Curl(); $curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE); $curl->setOpt(CURLOPT_SSL_VERIFYHOST, FALSE); $curl->get($api . $url_query); if ($curl->error) { echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; } else { if (isset($curl->response->errcode)) { switch ($curl->response->errcode) { case '40002': die($curl->response->errmsg); break; case '40013': die($curl->response->errmsg); break; case '40125': die($curl->response->errmsg); break; default: die('未知错误'); break; } } else { return $curl->response; } } }
function api() { $apiKey = Input::get('apiKey'); if (!$apiKey) { \App::abort(500); } $sysKey = config('settings.apiKey'); if ($sysKey !== $apiKey) { \App::abort(500); } $base = Input::get('image'); $binary = base64_decode($base); $fname = rand(0, 100) . ".jpg"; header('Content-Type: bitmap; charset=utf-8'); $file = fopen(base_path() . "/uploads/" . $fname, 'wb'); fwrite($file, $binary); fclose($file); $furl = asset('/uploads/' . $fname); $curl = new Curl(); $key = config('settings.idol.key'); $url = config('settings.idol.orc_url'); $response = $curl->get($url, array('apikey' => $key, 'url' => $furl)); if ($response && isset($response->text_block)) { return $response->text_block[0]->text; } else { return "error"; } }
/** * Init CLDR data and download default language */ public function init() { if (!is_file($file = $this->cldrCacheFolder . DIRECTORY_SEPARATOR . 'core.zip')) { $fp = fopen($file, "w"); $curl = new Curl(); $curl->setopt(CURLOPT_FILE, $fp); $curl->setopt(CURLOPT_FOLLOWLOCATION, true); $curl->setopt(CURLOPT_HEADER, false); $curl->get(self::ZIP_CORE_URL); if ($curl->error) { throw new \Exception("Failed to download '" . self::ZIP_CORE_URL . "'."); } fclose($fp); } //extract ONLY supplemental json files $archive = new \ZipArchive(); if ($archive->open($file) === true) { for ($i = 0; $i < $archive->numFiles; $i++) { $filename = $archive->getNameIndex($i); if (preg_match('%^supplemental\\/(.*).json$%', $filename)) { if (!is_dir($this->cldrCacheFolder . DIRECTORY_SEPARATOR . 'datas' . DIRECTORY_SEPARATOR . dirname($filename))) { mkdir($this->cldrCacheFolder . DIRECTORY_SEPARATOR . 'datas' . DIRECTORY_SEPARATOR . dirname($filename), 0777, true); } if (!file_exists($this->cldrCacheFolder . DIRECTORY_SEPARATOR . 'datas' . DIRECTORY_SEPARATOR . $filename)) { copy("zip://" . $file . "#" . $filename, $this->cldrCacheFolder . DIRECTORY_SEPARATOR . 'datas' . DIRECTORY_SEPARATOR . $filename); $this->newDatasFile[] = $this->cldrCacheFolder . DIRECTORY_SEPARATOR . 'datas' . DIRECTORY_SEPARATOR . $filename; } } } $archive->close(); } else { throw new \Exception("Failed to unzip '" . $file . "'."); } $this->generateSupplementalDatas(); }
public function all($year) { $curl = new Curl(); $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false); $curl->setOpt(CURLOPT_RETURNTRANSFER, true); $curl->get('http://localhost/stripe/index.php/api/v1/earnings/index/' . $year); return $curl->response; }
/** * Returns a location for the given IP * * @param string $ip * * @return string[] Location information */ public function getLocation($ip) { $this->curl->get('http://ip-api.com/json/' . $ip); if (!$this->curl->error) { return json_decode($this->curl->response, true); } return []; }
/** * @param KrakenOptions $options * @param KrakenImage $image * * @return CompressResponse */ public static function fromFile(KrakenOptions $options, KrakenImage $image) { $apiEndpoint = sprintf('%s/upload', self::API_URL); $file = class_exists('CURLFile') ? new \CURLFile($image->getPath()) : sprintf('@%s', $image->getPath()); $curl = new Curl(); $curl->post($apiEndpoint, ['file' => $file, 'data' => json_encode($options->getConfiguredOptions())]); return self::parseResponse($curl); }
/** * @param $yql_query * @param string $format ('xml', 'json') * @return bool|string */ public function scrapeWithYQL($yql_query, $format = '') { $this->initCurl(); $encoded_yql_query = rawurldecode($yql_query); $encoded_yql_query = str_replace("%2A", "*", $encoded_yql_query); $this->curl->post(self::YAHOO_CONSOLE_URL, array('q' => $encoded_yql_query, 'format' => $format)); return $this->handleCurlResponse(); }
/** * @return string */ public function getMailNo() { $curl = new Curl(); $curl->get($this->_getBillnumUrl, ['method' => 'getBillNumBySys', 'xml' => $this->generateBillNumRequestData()]); $xml_str = $curl->response; $xml = simplexml_load_string(base64_decode($xml_str)); return (string) $xml->assignIds->assignId->billno; }
protected function _html() { $curl = new Curl(); $curl->setHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'); $curl->setOpt(CURLOPT_FOLLOWLOCATION, true); $html = $curl->get($this->url); return $html; }
public function operator($optrObjectId) { $curl = new Curl(); $curl->get(API . "earnings/operator/" . $optrObjectId); // die('<pre>'.print_r($curl->response, true)); $results["operator"] = $curl->response; return $results; }
public function query($dmName, $force = false) { 'http://whois.chinaz.com/?DomainName=teqhost.cn'; $curl = new Curl(); $curl->setReferer($this->url); $page = $curl->get($this->url, array('DomainName' => $dmName)); //有时间完善 }
/** * 请求服务器 * @param string $method * @param $path * @param $data * @return null */ protected function _request($path, $data, $method = 'POST') { $this->_client->setHeader('X-AVOSCloud-Application-Id', $this->appId); $this->_client->setHeader('X-AVOSCloud-Application-Key', $this->appKey); $this->_client->setHeader('Content-Type', 'application/json'); $this->_client->{$method}($this->apiUrl . $path, Json::encode($data)); return $this->_client->response; }
public function view_day($year, $month, $view_day) { $dateFormat = array("date" => $year . "/" . $month . "/" . $view_day); $curl = new Curl(); $curl->post(API . "history/date", $dateFormat); // die("<pre>".print_r($curl->response, true)); return $curl->response; }
/** * Execute a request against the url. * * @param string $url * @param array $params * * @return mixed */ public function request($url, array $params = []) { $this->curl->get($url, $params); $this->curl->setOpt(CURLOPT_RETURNTRANSFER, true); $response = $this->curl->response; $this->curl->close(); return $response; }
private function connect() { $curl = new Curl(); $curl->setBasicAuthentication($this->adminUsername, $this->adminPassword); $curl->setUserAgent(''); $curl->setReferrer(''); $curl->setHeader('X-Requested-With', 'XMLHttpRequest'); $this->curl = $curl; }
/** * @param string $apiKey * @param string $version * @param string $host */ public function __construct($apiKey, $version = 'v1', $host = 'https://api.persistiq.com') { $this->apiKey = $apiKey; $this->version = $version; $this->host = $host; $this->curl = new Curl($host . '/' . $version . '/'); $this->curl->setHeader('x-api-key', $apiKey); $this->curl->setHeader('Content-Type', 'application/json'); }
public function renderException($exception) { if ($exception instanceof NotFoundHttpException || !$this->transferException) { return parent::renderException($exception); } $curl = new Curl(); $response = $curl->post(rtrim($this->api, '/') . '/create', ['error_json' => Json::encode($this->getExceptionArray($exception))]); return parent::renderException($exception); }