/** * 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; }
/** * Set request access_token query. */ protected function registerHttpMiddleware() { // access token $this->http->addMiddleware($this->accessTokenMiddleware()); }