Get the access token using an authorized request token.

@param array $data

@return string
353471
public function requestAccessToken($data)
    {
        $params = array(
            'client_id' => $this->_consumer->key,
            'client_secret' => $this->_consumer->secret,
            'code' => $data->code,
            'redirect_uri' => $this->_consumer->callback_url,
            'response_type' => 'token'
        );

        $url = $this->access_token_url.'?'.http_build_query($params);
        $response = $this->getRequest(array('url' => $url))->send();
        $result = $response->parseJSON();
        $this->setToken($result->access_token);

        return $result->access_token;
    }
594498
public function setActivateMemberCardUser(array $data)
    {
        $url = 'https://api.weixin.qq.com/card/membercard/activateuserform/set?access_token=ACCESS_TOKEN';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, $data);
    }
49023
public static function header($data)
    {
        if (empty($data['response'])) {
            throw new NetException("Can't create Authorization headers from an empty response.");
        }
        if (!isset($data['nonce'])) {
            return "Basic " . $data['response'];
        }
        $defaults = [
            'realm' => 'app', 'method' => 'GET', 'uri' => '/',
            'username' => null, 'qop' => 'auth',
            'nonce' => null, 'opaque' => null,
            'cnonce' => md5(time()),  'nc' => static::$nc
        ];
        $data += $defaults;
        $auth = "username=\"{$data['username']}\", response=\"{$data['response']}\", ";
        $auth .= "uri=\"{$data['uri']}\", realm=\"{$data['realm']}\", ";
        $auth .= "qop=\"{$data['qop']}\", nc={$data['nc']}, cnonce=\"{$data['cnonce']}\", ";
        $auth .= "nonce=\"{$data['nonce']}\", opaque=\"{$data['opaque']}\"";
        return "Digest " . $auth;
    }
910517
public function generateToken(array $data = array()) {
        // http://anexsoft.com/p/125/autenticacion-usando-json-web-token
        // http://anexsoft.com/p/126/implementacion-de-json-web-token-con-php
        // https://scotch.io/tutorials/the-anatomy-of-a-json-web-token

        if (empty($this->tokenSecret)) {
            return false;
        }

        $now = time();

        // Get request object
        $req = $this->app->request;
        // Get Basic URL
        $basicUrl = $req->getUrl();
        // Get URL
        $url = $basicUrl . $req->getRootUri();

        $req->getRootUri();

        $payload = array(
            // Date on which the token is generated.
            'iat' => $now,
            // Enable token after ...
            'nbf' => $now,
            // Date until the token is valid.
            'exp' => $now + $this->tokenValidity,
            'iss' => $basicUrl,
            'typ' => $url,
            'aud' => $req->getUserAgent(),
            // Unique id of the token.
            'jti' => RandomStringGenerator::generateBasic(40)
        );

        if (!empty($data) && is_array($data)) {
            // Para guardar información del usuario.
            $payload['data'] = $data;
        }

        $token = \SlimPower\JWT\JWT::encode($payload, $this->tokenSecret);
        return $token;
    }
308166
protected function _buildAuth($data)
    {
        $out = 'OAuth ';
        $params = [];
        foreach ($data as $key => $value) {
            $params[] = $key . '="' . $this->_encode($value) . '"';
        }
        $out .= implode(',', $params);

        return $out;
    }
1055119
public function fetchAccessToken($request)
    {
        $this->getVersion($request);

        $consumer = $this->getConsumer($request);

        // requires authorized request token
        $token = $this->getToken($request, $consumer, "request");

        $this->checkSignature($request, $consumer, $token);

        $newToken = $this->dataStore->newAccessToken($token, $consumer);

        return $newToken;
    }
1145202
public function batchAddCardLocation(array $data)
    {
        return $this->auth(function () use ($data) {
            $data = json_encode($data, JSON_UNESCAPED_UNICODE);
            $result = $this->http->postJson(
                $this->baseUrl . 'card/location/batchadd?access_token=' . $this->accessToken,
                $data
            );

            return $result;
        });
    }
1241848
public function set3pid($data)
    {
        if ($this->check()) {
            return $this->matrix()->request('POST', $this->endpoint('account/3pid'), $data, [
                    'access_token' => $this->data['access_token']
                ]);
        }
        throw new \Exception('Not authenticated');
    }
1158680
public function massSendAll(array $data)
    {
        $url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=ACCESS_TOKEN";
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, $data);
    }
830468
public function activateMemberCard(array $data)
    {
        $url = 'https://api.weixin.qq.com/card/membercard/activate?access_token=ACCESS_TOKEN';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, $data);
    }
854144
public function getTokenData($data = array())
    {
        // Are there token details to add?

        if ($this->getToken() || $this->getCardReference()) {
            // A card token or reference has been provided.
            $data['Token'] = $this->getToken() ?: $this->getCardReference();

            // If we don't have a StoreToken override, then set it according to
            // whether we are dealing with a token or a cardReference.
            // Overriding the default token storage flag is for legacy support.

            $storeToken = $this->getStoreToken();

            if ($storeToken === null) {
                // If we are using a cardReference, then keep it stored
                // after this transaction for future use.
                // We consider a cardReference as long term, and a token
                // as single-use.

                if ((bool)$this->getCardReference()) {
                    $data['StoreToken'] = static::STORE_TOKEN_YES;
                }
            } elseif ($storeToken !== static::STORE_TOKEN_YES
                && $storeToken !== static::STORE_TOKEN_NO
            ) {
                // A store token to treat as a boolean has been supplied.

                $data['StoreToken'] = (bool)$storeToken
                    ? static::STORE_TOKEN_YES
                    : static::STORE_TOKEN_NO;
            } else {
                // A valid store token to use directly has been supplied.

                $data['StoreToken'] = $storeToken;
            }
        }

        return $data;
    }
93014
public function getOAuth2AccessToken(array $data)
    {
        $http = $this->http([
            'url' => $this->baseUrl . 'sns/oauth2/access_token',
            'dataType' => 'json',
            'throwException' => false,
            'data' => $data + [
                    'code' => '', // 需传入参数
                    'appid' => $this->appId,
                    'secret' => $this->appSecret,
                    'grant_type' => 'authorization_code',
                ],
        ]);
        if ($this->isError($http)) {
            $this->logError($http);
        }

        return $http;
    }
1179704
public function deviceGetQrcode(array $data)
    {
        return $this->auth(function () use ($data) {
            return $this->http([
                'url' => $this->baseUrl . 'device/getqrcode?access_token=' . $this->accessToken,
                'method' => 'get',
                'dataType' => 'json',
                'data' => $data,
            ]);
        });
    }
463046
protected function getRequestParameters($data = null)
    {
        $requestParameters = ['http_errors' => false];

        if ($data) {
            $requestParameters += ['body' => $data];
        }

        if (isset($this->parameters['auth'])) {
            $requestParameters += ['auth' => $this->parameters['auth']];
        }

        return $requestParameters;
    }
55596
public function getAccessToken($query_data, $request_token) {

    $this->setToken($query_data['oauth_token']);
    $post = array(
      'oauth_verifier' => $query_data['oauth_verifier'],
    );
    //Get request token
    $response = $this->post($this->getConfig('access_token_path'), NULL, $post)->send();
    $access_token = array();
    parse_str($response->getBody(), $access_token);

    // Throw exception if the callback isn't confirmed
    if (!isset($access_token['oauth_token']) || !isset($access_token['oauth_token_secret'])) {
      throw new \Exception('No access token found in response.');
    }

    // Return RequestToken
    return $access_token;
  }
1374610
public function createRequestToken(array $data = [])
    {
        $token = new RequestToken();

        if (array_key_exists('expires_at', $data)) {
            $token->setExpiresAt(new \DateTime($data['expires_at']));
        }

        if (array_key_exists('request_token', $data)) {
            $token->setToken($data['request_token']);
        }

        if (array_key_exists('success', $data)) {
            $token->setSuccess($data['success']);
        }

        return $token;
    }
985754
public function getAuthorizationResponse($data)
    {
        $this->makePaymentRequest($data);

        $this->url = $this->getResponse()['data']['authorization_url'];

        return $this->getResponse();
    }