Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

企业微信获取用户详情 #284

Open
SuperPx-CN opened this issue Dec 25, 2024 · 4 comments
Open

企业微信获取用户详情 #284

SuperPx-CN opened this issue Dec 25, 2024 · 4 comments

Comments

@SuperPx-CN
Copy link
Contributor

SuperPx-CN commented Dec 25, 2024

public function userFromCode(string $code): Contracts\UserInterface
{
        $token = $this->getApiAccessToken();
        $user = $this->getUser($token, $code);

        if ($this->detailed) {
            $user = $this->getUserById($user['UserId']);
        }

        return $this->mapUserToObject($user)->setProvider($this)->setRaw($user);
}

开启 detailed 时,会通过 getUserById 方法获取详细信息:

    protected function getUserById(string $userId): array
    {
        $responseInstance = $this->getHttpClient()->post($this->baseUrl.'/cgi-bin/user/get', [
            'query' => [
                Contracts\RFC6749_ABNF_ACCESS_TOKEN => $this->getApiAccessToken(),
                'userid' => $userId,
            ],
        ]);

        $response = $this->fromJsonBody($responseInstance);

        if (($response['errcode'] ?? 1) > 0 || empty($response['userid'])) {
            throw new Exceptions\AuthorizeFailedException((string) $responseInstance->getBody(), $response);
        }

        return $response;
    }

getUserById 方法是通过 企业微信·企业内部开发·服务端API·通讯录管理·读取成员 接口实现的。但是在最新版本的企业微信API中,该接口已经不再返回 头像、性别、手机、邮箱、企业邮箱、员工个人二维码、地址 字段(https://developer.work.weixin.qq.com/document/path/90196)

@SuperPx-CN
Copy link
Contributor Author

SuperPx-CN commented Dec 25, 2024

测试了一下,按官方文档(https://developer.work.weixin.qq.com/document/path/95833),通过 user_ticket 获取访问用户敏感信息 时,确实返回了头像和手机号,但是没有返回姓名

{
   "errcode": 0,
   "errmsg": "ok",
   "userid":"lisi",
   "gender":"1",
   "avatar":"http://shp.qpic.cn/bizmp/xxxxxxxxxxx/0",
   "qr_code":"https://open.work.weixin.qq.com/wwopen/userQRCode?vcode=vcfc13b01dfs78e981c",
   "mobile": "13800000000",
   "email": "[email protected]",
   "biz_mail":"[email protected]",
   "address": "广州市海珠区新港中路"
}
···

@overtrue
Copy link
Owner

问题是什么?

@SuperPx-CN
Copy link
Contributor Author

SuperPx-CN commented Dec 25, 2024

问题是什么?

WeWork 企业微信获取用户详细信息的方式和企业微信文档中所述不一致。
导致 userFromCode 方法没有办法获取访问用户的头像、性别、手机、邮箱、企业邮箱、员工个人二维码、地址 字段。

@overtrue
Copy link
Owner

所以是让我去企业微信那边改他们接口么?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants