Skip to content

Commit

Permalink
【自建应用】&【自建代开发应用】获取访问用户敏感信息 (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajiahub authored Jul 16, 2022
1 parent 92cfd99 commit ddc7cd7
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Providers/WeWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ public function userFromCode(string $code): User
$user = $this->getUser($token, $code);

if ($this->detailed) {
$userTicket = $user['user_ticket'] ?? '';
$user = $this->getUserById($user['UserId']);
if ($userTicket) {
$user += $this->getUserDetail($userTicket);
}
}

return $this->mapUserToObject($user)->setProvider($this)->setRaw($user);
Expand Down Expand Up @@ -154,6 +158,37 @@ protected function getUser(string $token, string $code): array
return $response;
}

/**
* 获取访问用户敏感信息
* see:https://developer.work.weixin.qq.com/document/path/95833
* @param string $userTicket
*
* @return array
* @throws AuthorizeFailedException
*/
protected function getUserDetail(string $userTicket): array
{
$response = $this->getHttpClient()->post(
$this->baseUrl.'/cgi-bin/user/getuserdetail',
[
'query' => [
'access_token' => $this->getApiAccessToken(),
],
'json' => [
'user_ticket' => $userTicket,
]
]
);

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

if (($response['errcode'] ?? 1) > 0 || empty($response['userid'])) {
throw new AuthorizeFailedException('Failed to get user detail:' . $response['errmsg'] ?? 'Unknown.', $response);
}

return $response;
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
Expand Down

0 comments on commit ddc7cd7

Please sign in to comment.