authorize() public method

Authorize an application.
See also: ThreeScaleAuthorizeResponse (which is derived from ThreeScaleResponse) and contains additional information about the usage status.
See also: ThreeScaleResponse
See also: ThreeScaleAuthorizeResponse
public authorize ( $appId, $appKey = null, $serviceId = null, $usage = null ) : ThreeScaleResponse
$appId application id.
$appKey secret application key.
$serviceId service id, only required in the case of multiple services
return ThreeScaleResponse object containing additional authorization information. If both provider key and application id are valid, the returned object is actually
示例#1
0
if (isset($Params['appid'])) {
    $appid = $Params['appid'];
} else {
    $appid = "";
}
if (isset($Params['appkey'])) {
    $appkey = $Params['appkey'];
} else {
    $appkey = "";
}
$client = new ThreeScaleClient($three_scale_provider_key);
//echo "appid: " . $appid . "<br />";
//echo "appkey: " . $appkey . "<br />";
if ($appid != '' && $appkey != '') {
    // Auth the application
    $response = $client->authorize($appid, $appkey);
    $Plan = $response->getPlan();
    $Plan = str_replace(" (custom)", "", $Plan);
    //echo $Plan . "<br />";
    $usageReports = $response->getUsageReports();
    $usageReport = $usageReports[0];
    $Exceeded = $usageReport->isExceeded();
    if ($response->isSuccess()) {
        $usageReports = $response->getUsageReports();
        //echo "Success:";
        //echo "  Plan: " .          $response->getPlan();
        //echo "  Usage reports: " . var_export($usageReports, true);
        if ($Plan == "Internal" || $Plan == "Platform") {
            include "methods/platform.php";
            include "methods/utility.php";
        } elseif ($Plan == "Personal") {
<?php

require dirname(__FILE__) . '/../lib/ThreeScaleClient.php';
// Put your provider key here:
$provider_key = "aaa";
// Put some app_ids here (you can test it with the one from test contract):
$app_id_one = "bbb";
$app_id_two = "ccc";
// Put a app key corresponding to the first app_id here (you can leave it empty, if
// the app has no keys defined.)
$app_key_one = "";
$client = new ThreeScaleClient($provider_key);
// Auth the application
$response = $client->authorize($app_id_one, $app_key_one);
// Check the response type
if ($response->isSuccess()) {
    // All fine, proceeed & pull the usage reports
    $usageReports = $response->getUsageReports();
    echo "Success:";
    echo "  Plan: " . $response->getPlan();
    echo "  Usage reports: " . var_export($usageReports, true);
} else {
    // Something's wrong with this app.
    echo "Error: " . $response->getErrorMessage();
}
// Report some usages
$response = $client->report(array(array('app_id' => $app_id_one, 'usage' => array('hits' => 1)), array('app_id' => $app_id_two, 'usage' => array('hits' => 1))));