Ejemplo n.º 1
0
 /**
  * Internal fetch token logic.
  *
  * @throws HttpException
  * @throws \light\Easemob\Exception\HttpException
  *
  * @return array
  */
 protected function getTokenFromServer()
 {
     $this->http->clearMiddlewares();
     $response = $this->http->post('token', ['grant_type' => 'client_credentials', 'client_id' => $this->clientId, 'client_secret' => $this->clientSecret]);
     Log::debug('Get access token response', ['response' => (string) $response->getBody()]);
     $token = $this->http->parseJSON((string) $response->getBody());
     if (!isset($token['access_token'])) {
         throw new HttpException('Request AccessToken fail.' . json_encode($token, JSON_UNESCAPED_UNICODE));
     }
     return $token;
 }
Ejemplo n.º 2
0
 /**
  * Set request access_token query.
  */
 protected function registerHttpMiddleware()
 {
     // access token
     $this->http->addMiddleware($this->accessTokenMiddleware());
 }