當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HttpClient::getResponse方法代碼示例

本文整理匯總了PHP中HttpClient::getResponse方法的典型用法代碼示例。如果您正苦於以下問題:PHP HttpClient::getResponse方法的具體用法?PHP HttpClient::getResponse怎麽用?PHP HttpClient::getResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在HttpClient的用法示例。


在下文中一共展示了HttpClient::getResponse方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: download

 /**
  * download a media
  * @param string $filename - file for downloading to
  * @param string $mediaId - mediaId of file
  * @param bool $https(optional default true) - if downloading video-type file, 
  *		set $https to false for http request
  * @return int - filesize of the media or string - json for error message(if error)
  */
 public function download($filename, $mediaId, $https = true)
 {
     if ($https) {
         $client = new HttpClient("https://api.weixin.qq.com/cgi-bin/media/get?access_token={$this->access_token}&media_id={$mediaId}");
     } else {
         $client = new HttpClient("http://api.weixin.qq.com/cgi-bin/media/get?access_token={$this->access_token}&media_id={$mediaId}");
     }
     $client->get();
     if ($client->getState() == 200) {
         if (!is_null(json_decode($client->getResponse()))) {
             //data of json format(error here)
             return $client->getResponse();
         } else {
             file_put_contents($filename, $client->getResponse());
             return filesize($filename);
         }
     } else {
         return false;
     }
 }
開發者ID:jianhua1982,項目名稱:wlight,代碼行數:28,代碼來源:media.php

示例2: callApiEndpoint

 /**
  * call an api endpoint. automatically adds needed authorization headers with access token or parameters
  *
  * @param string $endpoint
  * @param string $method default 'GET'
  * @param array $uriParameters optional
  * @param mixed $postBody optional, can be string or array
  * @param array $additionalHeaders
  * @return string
  */
 public function callApiEndpoint($endpoint, $method = 'GET', array $uriParameters = array(), $postBody = null, array $additionalHeaders = array())
 {
     $token = $this->_dataStore->retrieveAccessToken();
     //check if token is invalid
     if ($token->getLifeTime() && $token->getLifeTime() < time()) {
         $token = $this->refreshAccessToken($token);
     }
     $parameters = null;
     $authorizationMethod = $this->_configuration->getAuthorizationMethod();
     switch ($authorizationMethod) {
         case Service\Configuration::AUTHORIZATION_METHOD_HEADER:
             $additionalHeaders = array_merge(array('Authorization: OAuth ' . $token->getAccessToken()), $additionalHeaders);
             break;
         case Service\Configuration::AUTHORIZATION_METHOD_ALTERNATIVE:
             if ($method !== 'GET') {
                 if (is_array($postBody)) {
                     $postBody['oauth_token'] = $token->getAccessToken();
                 } else {
                     $postBody .= '&oauth_token=' . urlencode($token->getAccessToken());
                 }
             } else {
                 $uriParameters['oauth_token'] = $token->getAccessToken();
             }
             break;
         default:
             throw new Exception("Invalid authorization method specified");
             break;
     }
     if ($method !== 'GET') {
         if (is_array($postBody)) {
             $parameters = http_build_query($postBody);
         } else {
             $parameters = $postBody;
         }
     }
     if (!empty($uriParameters)) {
         $endpoint .= (strpos($endpoint, '?') !== false ? '&' : '?') . http_build_query($uriParameters);
     }
     $http = new HttpClient($endpoint, $method, $parameters, $additionalHeaders);
     $http->execute();
     return $http->getResponse();
 }
開發者ID:vznet,項目名稱:oauth_2.0_client_php,代碼行數:52,代碼來源:Service.php


注:本文中的HttpClient::getResponse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。