Skip to content

Commit e331d3e

Browse files
authored
Fixed #220 (#221)
1 parent 7d8e74b commit e331d3e

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/Providers/DouYin.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public function tokenFromCode($code): array
5757
]
5858
);
5959

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

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

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

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

7171
/**
@@ -109,7 +109,9 @@ protected function getUserByToken(string $token): array
109109
]
110110
);
111111

112-
return \json_decode($response->getBody(), true) ?? [];
112+
$body = \json_decode($response->getBody()->getContents(), true);
113+
114+
return $body['data'] ?? [];
113115
}
114116

115117
/**

0 commit comments

Comments
 (0)