当前位置: 首页>>代码示例>>PHP>>正文


PHP Api类代码示例

本文整理汇总了PHP中Api的典型用法代码示例。如果您正苦于以下问题:PHP Api类的具体用法?PHP Api怎么用?PHP Api使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Api类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 public function run()
 {
     $reqId = (int) $this->httpRequest->postData('id');
     $reqsData = json_decode($this->httpRequest->postData('data'), true);
     if (json_last_error() !== JSON_ERROR_NONE) {
         //Try with stripslashes()
         $reqsData = json_decode(stripslashes($this->httpRequest->postData('data')), true);
         if (json_last_error() !== JSON_ERROR_NONE) {
             $errMsg = '#' . json_last_error();
             if (function_exists('json_last_error_msg')) {
                 $errMsg .= ' ' . json_last_error_msg();
             }
             throw new \RuntimeException('Malformed JSON-encoded request (' . $errMsg . ')', 400);
         }
     }
     $responses = array();
     foreach ($reqsData as $requestData) {
         $apiCall = new Api();
         $apiCall->emulate($requestData, $this->httpRequest);
         $apiCall->run();
         $responses[] = $apiCall->httpResponse()->content();
     }
     $resp = new ApiGroupResponse();
     $resp->setResponses($responses);
     $resp->setId($reqId);
     $this->httpResponse->addHeader('Content-Type: application/json');
     if ($resp->cacheable()) {
         $this->httpResponse->setCacheable();
     }
     $this->httpResponse->setContent($resp);
 }
开发者ID:Rudi9719,项目名称:stein-syn,代码行数:31,代码来源:ApiGroup.class.php

示例2: run

 public function run()
 {
     if (!$this->_canRun) {
         return;
     }
     $channelId = $this->_getChannel();
     $option['oldest'] = $this->_getMessageInterval();
     $api = new Api();
     //Get the latest 100 messages in the past minute
     $data = array_merge($option, array('channel' => $channelId, 'inclusive' => 1.0));
     $result = $api->getChannelMessages($data);
     if (!$result->ok || empty($result->messages)) {
         return;
     }
     //Apply filters
     $filteredMessages = $api->filterMessages($result->messages, $this->_wordTriggers, $this->_excludedUsers);
     if (count($filteredMessages)) {
         $userList = new SlackUserCollection();
         $selectedUsers = array();
         foreach ($filteredMessages as $msg) {
             $member = $userList->getMemberById($msg->user);
             $selectedUsers[$member->id] = $userList->getName($member);
         }
         $userStr = implode(', ', $selectedUsers);
         $message = "hey " . $userStr . " " . $this->_getMessage();
         $data = array('channel' => $channelId, 'text' => $message, 'username' => $this->_user, 'parse' => 'full', 'link_names' => 1);
         if ($this->_userIcon) {
             $data['icon_url'] = $this->_userIcon;
         }
         $this->_postMessage($data);
     }
 }
开发者ID:heyqule,项目名称:slackbot,代码行数:32,代码来源:ThatFamily.php

示例3: testCreateUrl

 public function testCreateUrl()
 {
     $expectedUrl = "http://test.webpay.com/foo/csob.do?MERCHANTNUMBER=1234&OPERATION=CREATE_ORDER&ORDERNUMBER=1234&AMOUNT=980&CURRENCY=978&DEPOSITFLAG=0&URL=http%3A%2F%2Ffoo.bar&DIGEST=Y%2BEFNoZgv0N%2B06PkOXe7v6lg4jilLcYKhWA9NDZgh2Y51vRf0Tt5N8KbPqHsWaNXUoDZ598OJgqC5NeG7km%2FiNh29uyQvYQuXaFEjA77QVWUZz6MgrI2VZU7XObyhC%2FETJ5UruAcxgpUAwCnAnWSz374%2BPzkfuS1OHxQEK4UFEam3kns06fbyR2mloa4a6xduiRt9j%2Buy6YXGoe%2FycxrOUfUPug79XZRjF7gmUgAnIvCIUcqD%2BT2mlUmG7BtzuD2pCTyV3RV47lHhO5gLGBN1VFBDm%2BNO6zqM4WTkz9ZtJmsjbzTWX3MEmQgHiiJ9mDd%2FgWY1ipWFWz%2F7TQeZEwctg%3D%3D";
     $request = new PaymentRequest(1234, 9.800000000000001, PaymentRequest::EUR, 0, 'http://foo.bar');
     $api = new Api(1234, 'http://test.webpay.com/foo/csob.do', new Signer(__DIR__ . '/keys/test_key.pem', 'changeit', __DIR__ . '/keys/test_cert.pem'));
     $this->assertEquals($expectedUrl, $api->createPaymentRequestUrl($request));
 }
开发者ID:sajfi,项目名称:gp-webpay-php-sdk,代码行数:7,代码来源:PaymentRequestUrlTest.php

示例4: run

 public function run()
 {
     header('Content-Type: text/xml');
     $api = new Api();
     if ($_GET['operation'] == 'searchRetrieve') {
         echo $api->searchRetrieveRequest($_GET);
     }
 }
开发者ID:onre,项目名称:finna-proxy,代码行数:8,代码来源:App.php

示例5: callHook

function callHook()
{
    global $url;
    global $default;
    global $controller;
    $queryString = array();
    if (!isset($url)) {
        $controller = $default['controller'];
        $action = $default['action'];
    } else {
        $url = routeURL($url);
        $urlArray = array();
        $urlArray = explode("/", $url);
        $urlArray = array_filter($urlArray);
        $controller = $urlArray[0];
        array_shift($urlArray);
        if (isset($urlArray[0])) {
            $action = $urlArray[0];
            array_shift($urlArray);
        } else {
            $action = 'index';
            // Default Action
        }
        $queryString = $urlArray;
    }
    $controllerName = ucfirst($controller) . 'Controller';
    // Check to see if the controller exists
    if (!file_exists('../application/controllers/' . $controllerName . '.php')) {
        if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json') {
            // Serve up some JSON
            $dispatch = new Api();
            $dispatch->response('Endpoint not found', 404);
        } else {
            // Serve up some HTML
            $dispatch = new ErrorController();
            call_user_func_array(array($dispatch, 'notFound'), []);
            exit;
        }
    }
    $dispatch = new $controllerName($controller, $action);
    if ((int) method_exists($controllerName, $action)) {
        call_user_func_array(array($dispatch, "beforeAction"), $queryString);
        call_user_func_array(array($dispatch, $action), $queryString);
        call_user_func_array(array($dispatch, "afterAction"), $queryString);
    } else {
        // We should check the Accept header type to server up the correct 404
        if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json') {
            // Serve up some JSON
            $dispatch = new Api();
            $dispatch->response('Endpoint not found', 404);
        } else {
            // Serve up some HTML
            $dispatch = new ErrorController();
            call_user_func_array(array($dispatch, 'notFound'), []);
            exit;
        }
    }
}
开发者ID:rorystandley,项目名称:php-mvc,代码行数:58,代码来源:application.php

示例6: _postMessage

 protected function _postMessage($data)
 {
     if (Setting::DEV_TEST) {
         echo "Posting: {$data['text']} to {$data['channel']} by {$data['username']} \n";
     } else {
         $api = new Api();
         $api->postMessage($data);
     }
 }
开发者ID:heyqule,项目名称:slackbot,代码行数:9,代码来源:ThatBot.php

示例7: buildRequestParaToString

 /**
  * 生成要请求给支付宝的参数数组
  * @param $para_temp 请求前的参数数组
  * @return 要请求的参数数组字符串
  */
 function buildRequestParaToString($para_temp)
 {
     //待请求参数数组
     $para = $this->buildRequestPara($para_temp);
     $api = new Api();
     //把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码
     $request_data = $api->createLinkstringUrlencode($para);
     return $request_data;
 }
开发者ID:ljimmy,项目名称:pay,代码行数:14,代码来源:BaseRequest.php

示例8: getRelatedFromApi

 public static function getRelatedFromApi(Api $api)
 {
     $ret = array();
     $pm = new PolicyManager();
     $am = new AuthManager();
     $allPolicies = $pm->getAllPolicies(true);
     $relatedPolicies = array();
     $policyPropsArr = array();
     $allAuths = $am->getAllAuths(true);
     $relatedAuthIds = array();
     $relatedAuths = array();
     $authPropsArr = array();
     foreach ($allPolicies as $policy) {
         /**
          * @var Policy $policy
          */
         $apiIds = $policy->getApiIds();
         foreach ($apiIds as $apiId) {
             if ($apiId === $api->getId()) {
                 $relatedPolicies[] = $policy;
             }
         }
     }
     foreach ($relatedPolicies as $policy) {
         $props = $policy->getProperties();
         if (!empty($props)) {
             $policyPropsArr[$policy->getId()] = array_keys($props);
         }
         foreach ($policy->getAuthIds() as $authBucket) {
             if ($authBucket && $authBucket->getAuthIds()) {
                 $relatedAuthIds = array_unique(array_merge($relatedAuthIds, $authBucket->getAuthIds()));
             }
         }
     }
     foreach ($allAuths as $auth) {
         /**
          * @var $auth Auth
          */
         if (in_array($auth->getId(), $relatedAuthIds)) {
             $relatedAuths[] = $auth;
         }
     }
     foreach ($relatedAuths as $auth) {
         $props = $auth->getProperties();
         if (!empty($props)) {
             $authPropsArr[$auth->getId()] = array_keys($props);
         }
     }
     if (!empty($policyPropsArr)) {
         $ret["policy"] = $policyPropsArr;
     }
     if (!empty($authPropsArr)) {
         $ret["auth"] = $authPropsArr;
     }
     return json_encode($ret);
 }
开发者ID:kyroskoh,项目名称:apigrove,代码行数:56,代码来源:JsonPropertyPrinter.php

示例9: fire

 protected function fire(InputInterface $input, OutputInterface $output)
 {
     foreach (['username', 'file', 'num'] as $option) {
         if (is_null($input->getOption($option))) {
             throw new Exception("Missing argument: {$option}");
         }
     }
     $username = $input->getOption('username');
     $relationships = $this->getRelationships($username);
     $api = new Api($username);
     $md5 = md5_file(app_path($input->getOption('file')));
     $toFollow = load($input->getOption('file'));
     $num = (int) $input->getOption('num');
     $state = $this->getState($username, $md5);
     $initialPosition = $state->position;
     $this->info("Follow: from account {$username}\t File: {$md5}");
     $this->info(sprintf("Starting from position: {$initialPosition}\t Out of: %s", count($toFollow)));
     $this->info(sprintf("Number to follow: %s", $num));
     $this->info(sprintf("Relationships update for %s: %s", $username, date(DATE_RFC822, $relationships->time->sec)));
     $this->info('-----');
     $n = 0;
     $position = $initialPosition;
     while ($n < $num) {
         if ($position >= count($toFollow)) {
             $this->error('File is over');
             break;
         }
         list($userId, $userSrc) = $toFollow[$position];
         if (in_array($userId, $relationships->followings)) {
             $this->line("Skipped {$userId}\tAlready following");
         } elseif (in_array($userId, $relationships->followers)) {
             $this->line("Skipped {$userId}\tAlready a follower");
         } else {
             if ($input->getOption('force')) {
                 $response = $api->follow($userId);
                 $response = json_decode($response->response);
                 $this->line(sprintf("Followed {$userId} \tsrc: {$userSrc} \t Username: %s", $response->screen_name));
             } else {
                 $this->line("Follow {$userId} \tsrc: {$userSrc}");
             }
             // Store to archive
             $follow = array('username' => $username, 'md5' => $md5, 'time' => new MongoDate(), 'src' => $userSrc, 'userId' => $userId);
             if (isset($response)) {
                 $follow['response'] = $response;
             }
             $this->db->follows->insert($follow);
             // Clean stuff
             unset($response);
             // Increment $n
             $n++;
         }
         // @todo: don't follow previously followed people
         $position++;
     }
     $this->saveState($username, $md5, $position);
 }
开发者ID:julien-c,项目名称:twitter-cli,代码行数:56,代码来源:FollowCommand.php

示例10: api

 public static function api($name = null, $options = array())
 {
     Lib::load('api');
     if (empty($name)) {
         $api = new Api();
         $api->config($options);
         return $api;
     }
     return Api::getInstance($name, $options);
 }
开发者ID:jasonrey,项目名称:project-test-report,代码行数:10,代码来源:lib.php

示例11: make_api

 public static function make_api()
 {
     $api = new Api('Cohen', 'hello_world', 'A demo function.');
     $api->add_property('user_name', 'Your Name');
     $api->set_path('cohen.php');
     $apis = array();
     $apis[] = $api;
     $results = array('classname' => 'Cohen', 'apis' => $apis);
     return $results;
 }
开发者ID:jackycgq,项目名称:cohenbible,代码行数:10,代码来源:cohen.php

示例12: run

 public static function run()
 {
     Bootstrap::setup();
     $app = new App();
     if (Util::has_request_param("action")) {
         $api = new Api($app);
         $api->apply();
     } else {
         define("FALLBACK", $app->get_fallback());
         normalized_require_once("page");
     }
 }
开发者ID:WebPassions,项目名称:local,代码行数:12,代码来源:class-bootstrap.php

示例13: testPaymentHasErrorInVerifyPaymentResponse

 /**
  * @expectedException \AdamStipak\Webpay\PaymentResponseException
  */
 public function testPaymentHasErrorInVerifyPaymentResponse()
 {
     $merchantNumber = 123456789;
     $params = ['OPERATION' => 'operation', 'ORDERNUMBER' => 'ordernumber', 'MERORDERNUMBER' => 'merordernum', 'PRCODE' => 1, 'SRCODE' => 2, 'RESULTTEXT' => 'resulttext'];
     $signer = new Signer(__DIR__ . '/keys/test_key.pem', 'changeit', __DIR__ . '/keys/test_cert.pem');
     $digest = $signer->sign($params);
     $params['MERCHANTNUMBER'] = $merchantNumber;
     $digest1 = $signer->sign($params);
     $response = new PaymentResponse($params['OPERATION'], $params['ORDERNUMBER'], $params['MERORDERNUMBER'], $params['PRCODE'], $params['SRCODE'], $params['RESULTTEXT'], $digest, $digest1);
     $api = new Api($merchantNumber, 'http://foo.bar', $signer);
     $api->verifyPaymentResponse($response);
 }
开发者ID:sajfi,项目名称:gp-webpay-php-sdk,代码行数:15,代码来源:ApiTest.php

示例14: fromDeploymentUuid

 public static function fromDeploymentUuid($uuid, $cachePath = '/tmp')
 {
     $sessionBuilder = function ($expt) {
         return new CookieSession($expt->uuid);
     };
     $api = new Api($uuid, '//api.mynaweb.com/');
     $loader = function ($deploymentUuid) use($api) {
         return json_encode($api->getDeployment());
     };
     $cache = new FileCache($cachePath, $loader);
     return new CachingClient($uuid, $sessionBuilder, $cache);
 }
开发者ID:myna,项目名称:myna-php,代码行数:12,代码来源:CachingClient.php

示例15: load

 protected function load()
 {
     $result = $this->api->get($this->method, array_merge($this->params, array('limit' => $this->limit, 'offset' => $this->offset)))->getResult();
     $this->meta = $result['_meta'] ?: array('limit' => $this->limit, 'offset' => $this->offset, 'count' => 0);
     $this->results = $result['results']->getArrayCopy() ?: array();
     if ($this->meta['limit'] < $this->limit) {
         $this->limit = $this->meta['limit'];
     }
     if (empty($this->results)) {
         $this->finished = true;
     }
 }
开发者ID:mzf,项目名称:admitad-php-api,代码行数:12,代码来源:Iterator.php


注:本文中的Api类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。