Esempio n. 1
0
 public function __construct(array $config)
 {
     parent::__construct();
     $this['config'] = function () use($config) {
         return new Config($config);
     };
     //init api url
     $this->api = self::BASE_URL . '/' . $this['config']['enterpriseId'] . '/' . $this['config']['appId'] . '/';
     $this->registerCoreProviders();
     $this->registerProviders();
     $this->initializeLogger();
     Log::debug('Configuration:', ['config' => $this['config']]);
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 /**
  * Parse response.
  *
  * @param ResponseInterface $response
  *
  * @throws EasemobException
  * @throws \light\Easemob\Exception\HttpException
  *
  * @return mixed
  */
 protected function parseResponse(ResponseInterface $response)
 {
     $statusCode = $response->getStatusCode();
     if (200 !== $statusCode) {
         //通用false代表此次请求失败,并没有成功
         Log::error('Got an error reponse:', ['__class__' => get_called_class(), 'code' => $statusCode, 'responseBody' => (string) $response->getBody()]);
         return false;
     }
     $result = $this->http->parseJSON($response);
     Log::debug('Parse response body result:', ['response' => $result]);
     if (isset($result['error'])) {
         Log::error('Got an error from server:', ['__class__' => get_called_class(), 'error' => $result]);
         throw new EasemobException($result['error_description']);
     }
     return $result;
 }