Пример #1
0
 public function getKeyDetails()
 {
     $req = new ApiRequest();
     $req->setQueryParam('userToken', $this->userId);
     $req->run('GET', '/key/' . $this->apiKey . '/details');
     $this->cache = $req->getResult()['result'];
     return $this->cache;
 }
Пример #2
0
 /**
  * Request access_token
  * @param string $code
  * @return mixed(string|array|boolean)
  */
 public function request_access_token($code)
 {
     $requrl = '';
     $params = array();
     if ('weixin' == $this->_platform) {
         $requrl = 'https://api.weixin.qq.com/sns/oauth2/access_token';
         $params['appid'] = $this->client_id;
         $params['secret'] = $this->secret_key;
         $params['code'] = $code;
         $params['grant_type'] = 'authorization_code';
         $req = new ApiRequest(['method' => 'get', 'protocol' => 'https', 'timeout' => 60, 'timeout_connect' => 30]);
         return $req->setUrl($requrl)->setParams($params)->send()->recv(TRUE);
     }
     return '';
 }
Пример #3
0
 /**
  * @param $action String the action to call
  * @throws InvalidRequestError
  * @throws ResourceNotFoundException
  * @throws ServiceException
  * @throws UnauthorizedException
  * @return mixed
  */
 public static function delete($action)
 {
     $signedRequest = ApiRequest::sign_request("DELETE", $action);
     $client = new GuzzleHttp\Client();
     $res = $client->request('DELETE', Itwapp::$apiBase . $signedRequest, ['exceptions' => false]);
     return ApiRequest::parse_result($res);
 }
Пример #4
0
 /**
  * Returns silo status and last api request date
  *
  * @return array
  **/
 function get_status($silo_id)
 {
     App::import('model', 'ApiRequest');
     $api_request = new ApiRequest();
     $api_status = array();
     $result = $api_request->find(array("silo_id" => $silo_id), array("created"), "created DESC");
     if (!$result) {
         $api_status["is_online"] = false;
         $api_status["last_request"] = null;
     } else {
         $last_request = strtotime($result["ApiRequest"]["created"]);
         $api_status["is_online"] = $last_request - strtotime("- 15 minutes") > 0 ? true : false;
         $api_status["last_request"] = $result["ApiRequest"]["created"];
     }
     return $api_status;
 }
Пример #5
0
 protected function __construct()
 {
     if (!self::$_inited) {
         ApiRequest::init(array('api' => array('host' => STRegistry::getAPIHost(), 'port' => STRegistry::getAPIPort(), 'ssl' => STRegistry::isSSLEnabled(), 'version' => STRegistry::getAPIVersion(), 'userAgent' => STRegistry::getAPIUserAgent(), 'content-type' => STRegistry::getAPIContentType()), 'debug' => false, 'connector' => 'ApiConnectorCURL'));
         self::$_inited = true;
     }
 }
 public function logout($cltrid = false)
 {
     $json = ApiRequest::DELETE('/auth', $cltrid ?: ApiRequest::defaultClientTransactionID(), $this->getAuthToken());
     $this->_sessionData['login'] = null;
     $this->_sessionData['token'] = null;
     $this->_sessionData['created'] = 0;
     $this->_sessionData['expires'] = 0;
     return $json;
 }
Пример #7
0
 /**
  * testGeneral
  *
  * @return void
  */
 public function testGeneral()
 {
     $data = ['username' => 'TESTusername', 'password' => 'TESTpassword', 'client_id' => 'TESTclient_id', 'client_secret' => 'TESTclient_secret', 'scope' => 'TESTscope'];
     $unit = new ApiRequest();
     $unit->setUsername($data['username']);
     $unit->setPassword($data['password']);
     $unit->setClientId($data['client_id']);
     $unit->setClientSecret($data['client_secret']);
     $unit->setScope($data['scope']);
     $requestData = $unit->getRequestParameters();
     $this->assertEquals($data['username'], $requestData['username']);
     $this->assertEquals($data['password'], $requestData['password']);
     $this->assertEquals($data['client_id'], $requestData['client_id']);
     $this->assertEquals($data['client_secret'], $requestData['client_secret']);
     $this->assertEquals($data['scope'], $requestData['scope']);
     $response = $unit->getResponse([]);
     $this->assertInstanceOf('\\Reliv\\AxosoftApi\\V5\\UsernamePasswordGrant\\ApiResponse', $response);
     $response = $unit->getResponse(['error' => true]);
     $this->assertInstanceOf('\\Reliv\\AxosoftApi\\Model\\GenericApiError', $response);
 }
 public function __construct($Config)
 {
     parent::__construct($Config);
 }
Пример #9
0
 /**
  * Delete host
  * 
  * @param $hostname
  * 
  * @return str json info respose
  */
 public function delete($hostname, $cltrid = false)
 {
     $json = APIRequest::DELETE(sprintf("/hosts/%s", $hostname), $cltrid ?: ApiRequest::defaultClientTransactionID(), STRegistry::Session()->getAuthToken());
     return $json;
 }
Пример #10
0
 public function isSessionTokenRequired()
 {
     return $this->requestClass->isSessionTokenRequired();
 }
Пример #11
0
 public static function getContacts($list, $contacts)
 {
     $request = new ApiRequest();
     $contactIds = array();
     if (is_array($contacts)) {
         foreach ((array) $contacts as $contact) {
             $contactIds[] = is_object($contact) ? $contact->id : $contact;
         }
     } else {
         $contactIds[] = is_object($contacts) ? $contacts->id : $contacts;
     }
     $listItems = self::handleResponse($list, $request->newGet("lists/{$list->id}/listitems/?_ids=" . implode(',', $contactIds)));
     return $listItems;
 }
Пример #12
0
 protected function login()
 {
     if (!ApiRequest::isApiRequest()) {
         $this->unrestrictedSet('lastLoginDateTime', DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
         $this->save();
     }
 }
 public function handleLoadLanguage($event)
 {
     if (!ApiRequest::isApiRequest()) {
         if (isset($_GET['lang']) && $_GET['lang'] != null) {
             Yii::app()->languageHelper->setActive($_GET['lang']);
         }
     } else {
         if ($lang = Yii::app()->apiRequest->getLanguage()) {
             Yii::app()->languageHelper->setActive($lang);
         }
     }
     Yii::app()->languageHelper->load();
 }
Пример #14
0
 public function testDeleteRequest()
 {
     $this->assertNotNull(ApiRequestTest::$interviewId);
     $res = ApiRequest::delete("/api/v1/interview/" . ApiRequestTest::$interviewId);
     $this->assertNull($res);
 }
Пример #15
0
<?php

/*
    Stand-alone script that interacts with Twitter API. It is called with an  
    XHR and does not reside in the Indexhibit context.
*/
// process XHR
// error_reporting(E_ALL);
define('SERVICE', 9999);
require 'feed.common.php';
$twitter = new ApiRequest('http://api.twitter.com/1/statuses/user_timeline.xml', array('user_id' => null, 'screen_name' => null, 'count' => 10, 'page' => 1, 'trim_user' => true, 'include_rts' => false, 'include_entities' => true), array('path' => null, 'timeout' => 3 * 3600));
// echo $twitter->buildQuery();
echo $twitter->fetchResult();
Пример #16
0
	protected static function _request($url, $input) {
		$curl = curl_init ();
		curl_setopt ( $curl, CURLOPT_URL, $url );
		curl_setopt ( $curl, CURLOPT_TIMEOUT, 3 );
		curl_setopt ( $curl, CURLOPT_CONNECTTIMEOUT, 3 );
		curl_setopt ( $curl, CURLOPT_POST, 1 );
		curl_setopt ( $curl, CURLOPT_POSTFIELDS, $input );
		$urlArr = parse_url ( $url );
		$port = empty ( $urlArr ['port'] ) ? 80 : $urlArr ['port'];
		curl_setopt ( $curl, CURLOPT_PORT, $port );
		curl_setopt ( $curl, CURLOPT_HTTPHEADER, array ('Expect:') );
		// 获取的信息以文件流的形式返回,不直接输出
		curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
		$response = curl_exec ( $curl );
		self::$_HTTP_CODE = curl_getinfo($curl, CURLINFO_HTTP_CODE);
		self::$_HTTP_INFO = curl_getinfo($curl);
		self::$_HTTP_ERROR_CODE = curl_errno($curl);
		self::$_HTTP_ERROR = curl_error($curl);
		self::$_URL = $url;
		curl_close($curl);
		return $response;
	}
Пример #17
0
<?php

/*
    Stand-alone script that interacts with Posterous API. It is called with an  
    XHR and does not reside in the Indexhibit context.
*/
// process XHR
// error_reporting(E_ALL);
define('SERVICE', 9999);
require 'feed.common.php';
$posterous = new ApiRequest('http://posterous.com/api/readposts', array('num_posts' => 10, 'page' => 1, 'site_id' => null, 'hostname' => null, 'tag' => null), array('path' => null, 'timeout' => 3600 * 24));
// echo $posterous->buildQuery();
echo $posterous->fetchResult();
Пример #18
0
 /**
  * Initializes the application component.
  * This method overrides the parent implementation by starting session,
  * performing cookie-based authentication if enabled, and updating the flash variables.
  */
 public function init()
 {
     CApplicationComponent::init();
     if (ApiRequest::isApiRequest()) {
         if (!Yii::app()->getRequest()->isOAuthRequest()) {
             if ($sessionId = Yii::app()->apiRequest->getSessionId()) {
                 Yii::app()->session->setSessionID($sessionId);
                 Yii::app()->session->open();
                 $session = Yii::app()->getSession();
                 if (Yii::app()->apiRequest->isSessionTokenRequired()) {
                     if ($session['token'] != Yii::app()->apiRequest->getSessionToken() || $session['token'] == '') {
                         Yii::app()->session->clear();
                         Yii::app()->session->destroy();
                     }
                 }
             } else {
                 Yii::app()->session->open();
                 $sessionId = Yii::app()->session->getSessionID();
                 $userPassword = Yii::app()->apiRequest->getPassword();
                 $token = ZurmoSession::createSessionToken($sessionId, $userPassword);
                 $session = Yii::app()->getSession();
                 $session['token'] = $token;
             }
         }
     } else {
         Yii::app()->getSession()->open();
         if ($this->getIsGuest() && $this->allowAutoLogin) {
             $this->restoreFromCookie();
         } elseif ($this->autoRenewCookie && $this->allowAutoLogin) {
             $this->renewCookie();
         }
     }
     if ($this->autoUpdateFlash) {
         $this->updateFlash();
     }
     $this->updateAuthStatus();
 }
Пример #19
0
 /**
  * return domain transfers hitory related to current domain owner
  * 
  * @param str $domainName
  * 
  * @return str json response
  */
 public function transfersHistory($domainName, $cltrid = false)
 {
     $json = APIRequest::GET(sprintf("/domains/%s/transfers", $domainName), $cltrid ?: ApiRequest::defaultClientTransactionID(), STRegistry::Session()->getAuthToken());
     return $json;
 }
Пример #20
0
 /**
  * this endpoint delete a specific interview.
  * @param $id string the ID of the interview to delete
  * @param $param string[]
  * @return void
  */
 public static function delete($id, $param)
 {
     if (isset($param["withApplicant"]) && $param["withApplicant"]) {
         ApiRequest::delete("/api/v1/interview/" . $id . "?withApplicant=" . $param["withApplicant"]);
     } else {
         ApiRequest::delete("/api/v1/interview/" . $id);
     }
 }
Пример #21
0
<?php

/*
    Stand-alone script that interacts with DeviantArt RSS API. It is called with an  
    XHR and does not reside in the Indexhibit context.
*/
// process XHR
// error_reporting(E_ALL);
define('SERVICE', 9999);
require 'feed.common.php';
// TODO hard coded
$da = new ApiRequest('http://backend.deviantart.com/rss.xml', array('q' => 'gallery:'), array('path' => null, 'timeout' => 6 * 3600), false);
// echo $da->buildQuery();
header('Content-Type: text/html; charset=utf-8');
echo $da->fetchResult();
Пример #22
0
 /**
  * this endpoint delete a specific applicant.
  * @param $id string the ID of the applicant to delete
  * @return bool
  */
 public static function delete($id)
 {
     $result = ApiRequest::delete("/api/v1/applicant/" . $id);
     return $result != null;
 }
Пример #23
0
 /**
  * 执行一个ApiRequest请求
  * @param  ApiRequest $request
  * @return ApiRequest $request
  */
 public function makeRequest(ApiRequest $request)
 {
     if (empty($request->url)) {
         throw new ApiRequestException('ApiRequest->url required setting');
     }
     $query_string = $request->makeQueryString($request->params);
     $cookie_string = $request->makeCookieString($request->cookies);
     $ch = curl_init();
     if ('get' == strtolower($request->method)) {
         curl_setopt($ch, CURLOPT_URL, $request->url . (FALSE === strrpos($request->url, '?') ? '?' : '&') . $query_string);
     } else {
         curl_setopt($ch, CURLOPT_URL, $request->url);
         curl_setopt($ch, CURLOPT_POST, 1);
         if (!empty($request->files)) {
             //with files to post
             //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); //for debug PUT request
             curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
             curl_setopt($ch, CURLOPT_POSTFIELDS, $request->mergeQueryParams($request->params, $request->files));
         } else {
             //no files, just ordinary variables to post
             curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($query_string)));
             curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
         }
     }
     curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, TRUE);
     //may set to FALSE to debug DNS
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $request->timeout_connect);
     curl_setopt($ch, CURLOPT_TIMEOUT, $request->timeout);
     curl_setopt($ch, CURLOPT_HEADER, FALSE);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     // check whether outfile
     $fp = NULL;
     if ('' !== $request->outfile && 'STDOUT' !== $request->outfile) {
         $dir = dirname($request->outfile);
         if (!is_dir($dir)) {
             $mode = 0755;
             mkdir($dir, $mode, TRUE);
             chmod($dir, $mode);
         }
         $fp = @fopen($request->outfile, 'w');
         if ($fp) {
             curl_setopt($ch, CURLOPT_FILE, $fp);
         }
     }
     // disable 100-continue
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
     // set ipv4 as default dns resolving
     if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
         curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
         //php 5.3+ and curl 7.10.8+ are required
     }
     if (!empty($cookie_string)) {
         curl_setopt($ch, CURLOPT_COOKIE, $cookie_string);
     }
     if ('https' == strtolower($request->protocol)) {
         curl_setopt($ch, CURLOPT_SSLVERSION, 1);
         //set to CURL_SSLVERSION_TLSv1
         if (empty($request->sslcert) && empty($request->cafile)) {
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
         } else {
             //1 to check the existence of a common name in the SSL peer certificate.
             //2 to check the existence of a common name and also verify that it matches the hostname provided
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
             if (!empty($request->sslcert)) {
                 curl_setopt($ch, CURLOPT_SSLCERT, $request->sslcert['cert_file']);
                 curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $request->sslcert['cert_passwd']);
                 curl_setopt($ch, CURLOPT_SSLCERTTYPE, $request->sslcert['cert_type']);
             }
             if (!empty($request->cafile)) {
                 //对认证证书来源的检查,FALSE表示阻止对证书的合法性的检查;1表示需要设置CURLOPT_CAINFO
                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
                 curl_setopt($ch, CURLOPT_CAINFO, $caFile);
             } else {
                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
             }
         }
     }
     $ret = curl_exec($ch);
     $err = curl_error($ch);
     $response = array('flag' => 1, 'ret' => $ret);
     if (FALSE === $ret || !empty($err)) {
         $errno = curl_errno($ch);
         $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         $response = array('flag' => 0, 'ret' => $err, 'errno' => $errno, 'httpcode' => $code);
     }
     curl_close($ch);
     if (is_resource($fp)) {
         fflush($fp);
         fclose($fp);
     }
     $request->setResponse($response);
     return $response;
 }
Пример #24
0
 /**
  * 微信接口通用调用函数
  * 
  * @param string $uri_path URI path
  * @param array $params 对应请求参数
  * @param string $method http请求方法:GET,POST
  * @param string $type API地址类型,对应self::$apiUrlPrefix的key部分:api_cgi,api_sns,open_conn
  * @param string $outfile 下载地址
  * @return mixed JSON Array or string
  */
 public function apiCall($uri_path, $params = array(), $method = 'get', $type = 'api_cgi', $outfile = '')
 {
     if (!in_array($type, array_keys(self::$apiUrlPrefix))) {
         return false;
     }
     $method = strtolower($method);
     if (!in_array($method, array('get', 'post'))) {
         return false;
     }
     if (empty($uri_path)) {
         return false;
     }
     if ($method == 'post' && is_array($params)) {
         $params = json_encode($params, JSON_UNESCAPED_UNICODE);
     }
     $requrl = self::$apiUrlPrefix[$type] . $uri_path;
     $apiConfig = ['method' => $method, 'protocol' => 'https', 'timeout' => 60, 'timeout_connect' => 30];
     if ('' !== $outfile) {
         $apiConfig['outfile'] = $outfile;
     }
     $req = new ApiRequest($apiConfig);
     return $req->setUrl($requrl)->setParams($params)->send()->recv(TRUE);
 }