easyWechat 5.x 复写代码 获取企业微信授权用户敏感信息
复写
(new SocialiteManager($config))->extend('wework', function ($config) {return new \App\Extend\EasyWechat\Work\WeWork($config);});
创建的 \App\Extend\EasyWechat\Work\WeWork
是我们需要复写的类
<?phpnamespace App\Extend\EasyWechat\Work;use Overtrue\Socialite\Contracts;
use Overtrue\Socialite\Contracts\UserInterface;
use Overtrue\Socialite\Exceptions\AuthorizeFailedException;class WeWork extends \Overtrue\Socialite\Providers\WeWork
{public function userFromCode(string $code): UserInterface{$token = $this->getApiAccessToken();$user = $this->getUser($token, $code);if ($this->detailed) {$detail = $this->getUserByUserTicket($user['user_ticket']);$user = $this->getUserById($user['UserId']);$user = array_merge($detail, $user);}return $this->mapUserToObject($user)->setProvider($this)->setRaw($user);}/*** @throws AuthorizeFailedException*/protected function getUserByUserTicket(string $userTicket): array{$responseInstance = $this->getHttpClient()->post($this->baseUrl . 'cgi-bin/auth/getuserdetail', ['query' => [Contracts\RFC6749_ABNF_ACCESS_TOKEN => $this->getApiAccessToken(),],'json' => ['user_ticket' => $userTicket],]);$response = $this->fromJsonBody($responseInstance);if (($response['errcode'] ?? 1) > 0 || empty($response['userid'])) {throw new AuthorizeFailedException((string)$responseInstance->getBody(), $response);}return $response;}
}
原来的代码只支持获取用户的基本信息,通过改写,支持把这两块数据合并