Skip to content

Commit

Permalink
Fixed #220 (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenxuanxin authored May 27, 2021
1 parent 7d8e74b commit e331d3e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Providers/DouYin.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public function tokenFromCode($code): array
]
);

$response = \json_decode($response->getBody()->getContents(), true) ?? [];
$body = \json_decode($response->getBody()->getContents(), true) ?? [];

if (empty($response['data'])) {
throw new AuthorizeFailedException('Invalid token response', $response);
if (empty($body['data']) || $body['data']['error_code'] != 0) {
throw new AuthorizeFailedException('Invalid token response', $body);
}

$this->withOpenId($response['data']['openid']);
$this->withOpenId($body['data']['open_id']);

return $this->normalizeAccessTokenResponse($response['data']);
return $this->normalizeAccessTokenResponse($body['data']);
}

/**
Expand Down Expand Up @@ -109,7 +109,9 @@ protected function getUserByToken(string $token): array
]
);

return \json_decode($response->getBody(), true) ?? [];
$body = \json_decode($response->getBody()->getContents(), true);

return $body['data'] ?? [];
}

/**
Expand Down

0 comments on commit e331d3e

Please sign in to comment.