ThreeScaleClient::authorize_with_user_key PHP 메소드

authorize_with_user_key() 공개 메소드

Authorize an application.
또한 보기: ThreeScaleAuthorizeResponse (which is derived from ThreeScaleResponse) and contains additional information about the usage status.
또한 보기: ThreeScaleResponse
또한 보기: ThreeScaleAuthorizeResponse
public authorize_with_user_key ( $userKey, $serviceId = null, $usage = null ) : ThreeScaleResponse
$userKey user key.
$serviceId service id, only required in the case of multiple services
리턴 ThreeScaleResponse object containing additional authorization information. If both provider key and application id are valid, the returned object is actually
    public function authorize_with_user_key($userKey, $serviceId = null, $usage = null)
    {
        $url = "http://" . $this->getHost() . "/transactions/authorize.xml";
        $params = array('provider_key' => $this->getProviderKey(), 'user_key' => $userKey);
        if ($serviceId) {
            $params['service_id'] = $serviceId;
        }
        if ($usage) {
            $params['usage'] = $usage;
        }
        $httpResponse = $this->httpClient->get($url, $params);
        if (self::isHttpSuccess($httpResponse)) {
            return $this->buildAuthorizeResponse($httpResponse->body);
        } else {
            return $this->processError($httpResponse);
        }
    }

Usage Example

<?php

require_once 'lib/ThreeScaleClient.php';
$client = new ThreeScaleClient("YOUR_PROVIDER_KEY");
$response = $client->authorize_with_user_key($_GET["user_key"]);
function speech_app_list()
{
    //normally this info would be pulled from a database.
    //build JSON array
    //report against metric
    global $client;
    $client->report(array(array('user_key' => $_GET["user_key"], 'usage' => array('speech' => 1))));
    $app_list = array(array("id" => 1, "name" => "Web Demo"), array("id" => 2, "name" => "Audio Countdown"), array("id" => 3, "name" => "The Tab Key"), array("id" => 4, "name" => "Music Sleep Timer"));
    return $app_list;
}
function enroll_app_list()
{
    //normally this info would be pulled from a database.
    //build JSON array
    //report against metric
    global $client;
    $client->report(array(array('user_key' => $_GET["user_key"], 'usage' => array('enroll' => 1))));
    $app_list = array(array("id" => 1, "name" => "Enroll abc"), array("id" => 2, "name" => "Enroll efg"), array("id" => 3, "name" => "Enroll mnp"), array("id" => 4, "name" => "Enroll xyz"));
    return $app_list;
}
if ($response->isSuccess()) {
    $possible_url = array("speech_list", "enroll_list");
    $value = "An error has occurred";
    if (isset($_GET["action"]) && in_array($_GET["action"], $possible_url)) {
        switch ($_GET["action"]) {
            case "speech_list":