setOpt() 공개 메소드

Set Opt
public setOpt ( $option, $value ) : boolean
$option
$value
리턴 boolean
예제 #1
1
파일: home.php 프로젝트: sherdog/wnd
 /**
  * PAGE: index
  * This method handles what happens when you move to http://yourproject/home/index (which is the default page btw)
  */
 public function index()
 {
     $redirected = false;
     //check if there is an error
     if ($_GET['error'] != '') {
         //load error page!
         die("<h1>Whoops, something went wrong, you can refresh to see if it fixes it otherwise check back later.</h1>");
     }
     if (isset($_GET['appSource'])) {
         $redirected = true;
         $appSource = (int) $_GET['appSource'];
     }
     if (!$redirected) {
         if (isset($_GET['id']) && $_GET['id'] != "") {
             $extraParameters['id'] = $_GET['id'];
         }
         if (isset($_GET['fbSource'])) {
             $extraParameters['appSource'] = $_GET['appSource'];
         }
         if (isset($_GET['traffic_source']) && $_GET['traffic_source'] != '') {
             $extraParameters['traffic_source'] = $_GET['traffic_source'];
         }
     }
     $signedRequest = null;
     if (isset($_POST['signed_request'])) {
         $signedRequest = self::parseSignedRequest($_POST['signed_request']);
     }
     Log::add('Signed request: ' . $signedRequest);
     //check if user_id
     if ($signedRequest === null) {
         //we need to get one!
         $url = Config::get('facebook.appurl') . "?" . http_build_query($_GET);
         header("location: " . $url);
         exit;
     }
     if (!isset($signedRequest['user_id']) || $signedRequest['user_id'] == '') {
         $redirectUrl = self::buildUrl($extraParameters);
         $oAuthUrl = "https://www.facebook.com/dialog/oauth?";
         $oAuthUrl .= http_build_query(array_filter(array('client_id' => Config::Get('facebook.appid'), 'redirect_uri' => self::buildUrl($extraParameters), 'scope' => 'user_friends,email')));
         die("<script>top.location.href = '" . $oAuthUrl . "';</script>");
     }
     $fbCurlReq = new Curl();
     $fbCurlReq->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $fbCurlReq->get('https://graph.facebook.com/me?access_token=' . $signedRequest['oauth_token']);
     if ($fbCurlReq->error) {
         Log::add('Error fb user profile ' . $fbCurlReq->error_code . ': ' . $fbCurlReq->error_message);
     } else {
         $dataArray = $fbCurlReq->response;
     }
     Log::add('dataArray = ' . print_r($dataArray, true));
     //check too see if this is a post :)
     $game = new Game();
     $game->loadGame((array) $dataArray, 'facebook', $extraParameters);
 }
예제 #2
0
 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);
 }
예제 #3
0
 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;
         }
     }
 }
예제 #4
0
 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;
         }
     }
 }
예제 #5
0
 /**
  * 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;
 }
예제 #6
0
 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;
 }
예제 #7
0
 public function appointmentsTimeline()
 {
     $curl = new Curl();
     $curl->setHeader("X-Parse-Application-Id", "yPPe3Uv46pKNnrTc7I6xArFHi8EQ8cdz4Kw3JGkX");
     $curl->setHeader("X-Parse-REST-API-Key", "7PJB1F4g8aFSv5f8e0gSMwi9Ghv2AeAkTW0O50pe");
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $curl->setOpt(CURLOPT_RETURNTRANSFER, true);
     $curl->get('http://52.24.133.167/stripe/index.php/api/v1/history/appointments');
     return $curl->response;
 }
예제 #8
0
 /**
  * Api constructor.
  *
  * @param string $apiKey API Key
  * @param string $environment API environment
  */
 public function __construct($apiKey, $environment)
 {
     ArgValidator::assert($apiKey, ['string', 'notEmpty']);
     ArgValidator::assert($environment, ['string', 'notEmpty']);
     $this->curl = new Curl();
     $this->curl->setOpt(CURLOPT_RETURNTRANSFER, true);
     $this->curl->setUserAgent('Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0');
     $this->apiUrl = $this->getApiUrl($environment);
     $this->apiKey = $apiKey;
 }
예제 #9
0
 public function getRemoteHtml()
 {
     $curl = new Curl();
     $curl->setOpt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1');
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $curl->get($this->url);
     $this->getDate = date('Y-m-d H:i:s');
     if ($curl->error) {
         return 'Error: ' . $curl->error_code . ': ' . $curl->error_message;
     } else {
         return $curl->response;
     }
 }
예제 #10
0
 public function __construct($login, $hash, $subdomain, ICookieContainer $cookieContainer)
 {
     $this->_login = $login;
     $this->_hash = $hash;
     $this->_subdomain = $subdomain;
     $this->cookieContainer = $cookieContainer;
     $this->_curl = new Curl();
     $this->_curl->setUserAgent('amoCRM-API-client/1.0');
     $this->_curl->setHeader('Content-Type', 'application/json');
     $this->_curl->setOpt(CURLOPT_HEADER, false);
     $this->_curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
     $this->_curl->setOpt(CURLOPT_SSL_VERIFYHOST, 0);
     $this->auth();
 }
예제 #11
0
 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']);
 }
예제 #12
0
파일: Scrape.php 프로젝트: vNative/vnative
 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;
 }
예제 #13
0
파일: Fetcher.php 프로젝트: arall/cmsdiff
 /**
  * Get remote file hash.
  *
  * @param string $path
  *
  * @return string
  */
 public function fetch($path, $force = false)
 {
     $url = $this->url . $path;
     // Cached?
     if ($force || !isset($this->cache[$path])) {
         $curl = new Curl();
         $curl->setOpt(CURLOPT_RETURNTRANSFER, true);
         $curl->setOpt(CURLOPT_AUTOREFERER, true);
         $curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
         $curl->get($url);
         if ($curl->error) {
             return false;
         }
         $this->cache[$path] = md5($curl->response);
     }
     return $this->cache[$path];
 }
 public function scrape($locale = 'en-us', $user_agent = false, $proxy = false)
 {
     $curl = new Curl();
     $curl->setHeader('Accept-Language', $locale);
     $curl->setopt(CURLOPT_SSL_VERIFYPEER, FALSE);
     if ($user_agent) {
         $curl->setOpt(CURLOPT_USERAGENT, $user_agent);
     }
     if ($proxy) {
         $curl->setOpt(CURLOPT_PROXY, $proxy);
         //            $curl->setOpt(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
     }
     $curl->get($this->trends_url);
     if ($curl->error) {
         throw new FailedRetrieveTrendsException('Error #' . $curl->error_code . ': ' . $curl->error_message);
     }
     $this->parseTrendsFromResponse($curl->response);
 }
 public function query($dmName, $force = false)
 {
     //'https://whois.cnnic.net.cn/WhoisServlet?queryType=Domain&domain=teqhost.cn';
     $curl = new Curl();
     $curl->setReferer($this->refererUrl);
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $Punycode = new Punycode();
     $page = $curl->get($this->url, array('domain' => $Punycode->encode($dmName), 'queryType' => 'Domain'));
     return $this->parse($page);
 }
예제 #16
0
 /**
  * 可传入自定义设置后的Curl\Curl实例
  *
  * @param  Curl\Curl  $curl
  * @return void
  */
 public function __construct(Curl $curl = null)
 {
     if (is_null($curl)) {
         $curl = new Curl();
         $curl->setUserAgent(self::USER_AGENT);
         //抓取跳转后的页面
         $curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
     }
     $this->client = $curl;
 }
예제 #17
0
 /**
  * Make the call
  *
  * @author Koen Blokland Visser
  *
  * @param $hash
  * @param $callId
  *
  * @return array
  */
 public function __construct($hash, $callId)
 {
     $curl = new Curl();
     $curl->setHeader('Content-Type', 'application/json');
     $curl->setHeader('Accept', 'application/json');
     $curl->setHeader('Hash', $hash);
     $curl->setOpt(CURLOPT_RETURNTRANSFER, true);
     $curl->get('https://api.voipgrid.nl/api/clicktodial/' . $callId . '/');
     /** @var array $response */
     $this->response = json_decode($curl->response, true);
 }
 protected function get_image_data($image_url)
 {
     $curl = new Curl();
     $curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
     // typically you will want to follow redirects
     if ($this->user_agent) {
         $curl->setUserAgent($this->user_agent);
         // the default WordPress user agent may be rejected by certain servers
     }
     $response = $curl->get($image_url);
     return $response;
 }
 /**
  * @return boolean
  */
 public function execute()
 {
     $this->curl = new Curl();
     $this->curl->setOpt(CURLOPT_ENCODING, 'gzip');
     $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $this->curl->setOpt(CURLOPT_HTTPHEADER, array('Accept: application/xml'));
     $this->prepareRequest();
     if (!$this->xmlRequest) {
         $this->lastError = new Exception('Request XML is not defined.');
         return false;
     }
     if (!isset(static::$API_METHOD) || !static::$API_METHOD) {
         $this->lastError = new Exception('API method is not defined.');
         return false;
     }
     $url = rtrim(static::ENDPOINT, '/') . '/' . static::ENDPOINT_VERSION . '/' . static::$API_METHOD;
     $data = array();
     if (static::$HTTP_METHOD === EANFacade::HTTP_METHOD_POST) {
         $data['xml'] = XMLUtils::SXEasXML($this->xmlRequest);
         $url .= '?' . Utils::httpBuildQuery3986($this->params);
     } else {
         $data = array_merge($this->params, array('xml' => XMLUtils::SXEasXML($this->xmlRequest)));
     }
     if (static::$HTTP_METHOD === EANFacade::HTTP_METHOD_GET) {
         $this->curl->get($url, $data);
         $this->curl->close();
     } else {
         if (static::$HTTP_METHOD === EANFacade::HTTP_METHOD_POST) {
             $this->curl->post($url, $data);
             $this->curl->close();
         } else {
             $this->lastError = new Exception('Invalid method for API call.');
             return false;
         }
     }
     if ($this->curl->error) {
         $this->lastError = new Exception($this->curl->errorMessage);
         return false;
     }
     try {
         if ($this->curl->response instanceof SimpleXMLElement) {
             $this->xmlResponse = $this->curl->response;
         } else {
             $this->xmlResponse = new SimpleXMLElement($this->curl->response);
         }
     } catch (Exception $e) {
         $this->lastError = $e;
         return false;
     }
     $this->lastError = null;
     $this->prepareResponse();
     return true;
 }
예제 #20
0
파일: Swugpa.php 프로젝트: mohuishou/swugpa
 /**
  * @author mohuishou<*****@*****.**>
  * @return array
  */
 public function loginJwc()
 {
     $this->_curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
     $this->_curl->setOpt(CURLOPT_ENCODING, 'gzip');
     $this->_curl->setCookieFile(__DIR__ . '/../cookie/college-' . $this->_uid . '.cookie');
     $this->_curl->get($this->_url_login_jwc);
     if ($this->_curl->error) {
         echo 'Error: ' . $this->_curl->errorCode . ': ' . $this->_curl->errorMessage;
     } else {
         $this->_jwc_cookie = $this->_curl->getResponseCookies();
         return $this->_jwc_cookie;
     }
 }
예제 #21
0
 public function getusersummary($begin_date, $end_date)
 {
     $api = 'https://api.weixin.qq.com/datacube/getusersummary';
     $url_query = '?access_token=' . $this->getToken()->getToken();
     $data = array('begin_date' => $begin_date, 'end_date' => $end_date);
     $curl = new Curl();
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
     $curl->setOpt(CURLOPT_SSL_VERIFYHOST, FALSE);
     $curl->post($api . $url_query, json_encode($data));
     if ($curl->error) {
         echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
     } else {
         if (isset($curl->response->errcode)) {
             switch ($curl->response->errcode) {
                 case '40001':
                     die($curl->response->errmsg);
                     break;
                 case '40002':
                     die($curl->response->errmsg);
                     break;
                 case '40003 ':
                     die($curl->response->errmsg);
                     break;
                 case '40013':
                     die($curl->response->errmsg);
                     break;
                 case '40125':
                     die($curl->response->errmsg);
                     break;
                 default:
                     print_r($curl->response);
                     die;
                     break;
             }
         } else {
             return $curl->response;
         }
     }
 }
예제 #22
0
 /**
  * Apply cURL options
  */
 private function applyCurlOptions($authMethod)
 {
     $this->curl->reset();
     $this->curl->setUserAgent('Shopello-PHP API Client/1.0');
     $this->curl->setOpt(CURLOPT_ENCODING, 'gzip');
     $this->curl->setOpt(CURLOPT_HEADER, false);
     $this->curl->setOpt(CURLOPT_NOBODY, false);
     $this->curl->setOpt(CURLOPT_CONNECTTIMEOUT, 3);
     $this->curl->setOpt(CURLOPT_TIMEOUT, 300);
     $this->setAuthMethod($authMethod);
     foreach ($this->curlOptions as $key => $value) {
         $this->curl->setOpt($key, $value);
     }
 }
예제 #23
0
 public function sendTopic($topic, $param)
 {
     $this->validate($topic, $param);
     $data = array('to' => $topic, 'data' => $param);
     $curl = new Curl();
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $curl->setHeader('Content-Type', 'application/json');
     $curl->setHeader('Authorization', "key={$this->key}");
     $curl->post($this->gcm_link, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
     if ($curl->error) {
         throw new \Exception("Curl Post Error : " . $curl->error_message);
     }
     return $curl->response;
 }
예제 #24
0
 public function parse()
 {
     $curl = new Curl();
     foreach ($this->origins as $origin) {
         foreach ($this->queries as $query) {
             shuffle($this->userAgents);
             $curl->reset();
             $curl->setUserAgent($this->userAgents[0]);
             $curl->setOpt(CURLOPT_RETURNTRANSFER, true);
             $curl->get($origin, [self::QUERY_GET_PARAM => $query]);
             var_dump($curl->response);
         }
     }
 }
예제 #25
0
function getYouTubePlaylist($playlist_id)
{
    // this is using my (bobby's) google api key
    $google_api_uri = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,contentDetails&maxResults=10&fields=items&key=AIzaSyCzaoEN0B1W0-c7uhZl5xGUI2tG3suwJvI&playlistId=';
    $curl = new Curl();
    $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
    $curl->get($google_api_uri . $playlist_id);
    /**
     *    Returns JSON object, { items: [ { ... } ] }
     */
    $playlist_data = json_decode(json_encode($curl->response), 1);
    if (!empty($playlist_data['items'])) {
        return $playlist_data['items'];
    } else {
        return [];
    }
}
예제 #26
0
 public function make($content = null)
 {
     $params = $this->getRequestParams($content);
     $data = $this->getRequestData($content);
     $request = new Curl();
     if (isset($this->headers)) {
         $request->setOpt(CURLOPT_HTTPHEADER, $this->headers);
     }
     if (isset($params)) {
         $params = "?" . http_build_query($params);
     } else {
         $params = "";
     }
     $url = $this->path . $params;
     $response = $request->post($url, $data);
     return $this->output($response);
 }
예제 #27
0
 public function __construct()
 {
     $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET);
     //OBTAIN THE STARRED PROJECTS
     $curl = new Curl();
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $curl->get(URL_GITHUB);
     if ($curl->error) {
         echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
     } else {
         $existe = false;
         do {
             //PROCESS A BEAUTY STRING
             $random = array_rand($curl->response);
             $name = $curl->response[$random]->name;
             $description = $curl->response[$random]->description;
             $cutdescription = strlen($description) > 70 ? substr($description, 0, 60) . '...' : $description;
             $home_url = $curl->response[$random]->html_url;
             //PUBLISH YET?
             if ($this->connectDB()) {
                 $query = $this->conn->prepare('SELECT id_twitter FROM bot_github WHERE nombre LIKE :nombre;');
                 $query->bindParam(':nombre', $name, PDO::PARAM_STR);
                 $query->execute();
                 $result_row = $query->fetchObject();
                 if (isset($result_row->id_twitter)) {
                     $existe = true;
                 }
             }
         } while ($existe);
         $tweet = $name . ': ' . $cutdescription . ' ' . $home_url;
         //TWEET
         $return = $twitter->post('statuses/update', array('status' => $tweet));
         if ($this->connectDB()) {
             //SAVE THE TWEET
             $query = $this->conn->prepare('INSERT INTO bot_github (nombre, id_twitter) VALUES (:nombre, :id_twitter)');
             $query->bindParam(':nombre', $name, PDO::PARAM_STR);
             $query->bindParam(':id_twitter', $return->id, PDO::PARAM_STR);
             $query->execute();
         }
         echo '<pre>';
         print_r($return);
         echo '</pre>';
     }
 }
예제 #28
0
 private function _call($method, $name, $parameters = array())
 {
     $urlParameters = array();
     $curl = new Curl();
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $curl->setHeader('Authorization', 'Bearer ' . $this->accessToken);
     $curl->setHeader('Accept', $this->outputFormat);
     if ($this->outputFormat === self::OUTPUT_FORMAT_JSONP) {
         $urlParameters['callback'] = $this->jsonpFunctionName;
     }
     if ($method === 'get') {
         $curl->get(self::HOST . $name . '/?' . http_build_query($urlParameters), $parameters);
     } else {
         $curl->post(self::HOST . $name . '/?' . http_build_query($urlParameters), $parameters);
     }
     if ($curl->error) {
         echo 'Error: ' . $curl->error_code . ': ' . $curl->error_message;
     } else {
         echo $curl->raw_response;
     }
 }
예제 #29
0
 /**
  * 登录
  *
  * @param $user
  * @param $pwd
  * @param $refresh_token
  */
 public function login($user = null, $pwd = null, $refresh_token = null)
 {
     $request = array('client_id' => $this->oauth_client_id, 'client_secret' => $this->oauth_client_secret);
     if ($user != null && $pwd != null) {
         $request = array_merge($request, array('username' => $user, 'password' => $pwd, 'grant_type' => 'password'));
     } elseif ($refresh_token != null || $this->refresh_token != null) {
         $request = array_merge($request, array('grant_type' => 'refresh_token', 'refresh_token' => $refresh_token || $this->refresh_token));
     } else {
         throw new Exception('login params error.');
     }
     $curl = new Curl();
     $curl->setOpt(CURLOPT_CONNECTTIMEOUT, 10);
     $curl->setHeader('Authorization', $this->headers['Authorization']);
     $curl->post($this->oauth_url, $request);
     $result = $curl->response;
     $curl->close();
     if (isset($result->has_error)) {
         throw new Exception('Login error: ' . $result->errors->system->message);
     }
     $this->setAuthorizationResponse($result->response);
     $this->setAccessToken($result->response->access_token);
     $this->setRefreshToken($result->response->refresh_token);
 }
예제 #30
0
 /**
  *
  * @param $uri
  * @param $method
  * @param array $params
  * @return mixed
  */
 protected function fetch_from_url($uri, $method, $params = array())
 {
     $method = strtolower($method);
     if (!in_array($method, array('post', 'get', 'put', 'delete'))) {
         throw new Exception('HTTP Method is not allowed.');
     }
     $url = $this->api_prefix . $uri;
     foreach ($params as $key => $value) {
         if (is_bool($value)) {
             $params[$key] = $value ? 'true' : 'false';
         }
     }
     $curl = new Curl();
     $curl->setOpt(CURLOPT_CONNECTTIMEOUT, 10);
     $curl->setHeader('Host', $this->headers['Host']);
     $curl->setHeader('Authorization', $this->headers['Authorization']);
     $curl->setHeader('User-Agent', $this->headers['User-Agent']);
     $curl->{$method}($url, $params);
     $result = $curl->response;
     $curl->close();
     $array = json_decode(json_encode($result), true);
     return $array;
 }