From 88af78fa6515a80d36efbd0aa0245cc815ec710d Mon Sep 17 00:00:00 2001 From: Wanli Date: Tue, 18 Jul 2023 09:39:01 +0800 Subject: [PATCH] feat: add GetUserIDByEmail --- apis.md.go | 14 ++++++++++++++ docs/apis.md | 1 + models.go | 32 ++++++++++++++++++++++++++++++++ user_info.go | 15 +++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/apis.md.go b/apis.md.go index 95ebe12..77b230d 100644 --- a/apis.md.go +++ b/apis.md.go @@ -100,6 +100,20 @@ func (c *WorkwxApp) execUserIDByMobile(req reqUserIDByMobile) (respUserIDByMobil return resp, nil } +// execUserIDByEmail 邮箱获取userid +func (c *WorkwxApp) execUserIDByEmail(req reqUserIDByEmail) (respUserIDByEmail, error) { + var resp respUserIDByEmail + err := c.executeQyapiJSONPost("/cgi-bin/user/get_userid_by_email", req, &resp, true) + if err != nil { + return respUserIDByEmail{}, err + } + if bizErr := resp.TryIntoErr(); bizErr != nil { + return respUserIDByEmail{}, bizErr + } + + return resp, nil +} + // execDeptCreate 创建部门 func (c *WorkwxApp) execDeptCreate(req reqDeptCreate) (respDeptCreate, error) { var resp respDeptCreate diff --git a/docs/apis.md b/docs/apis.md index 8f84941..9e1dfe1 100644 --- a/docs/apis.md +++ b/docs/apis.md @@ -26,6 +26,7 @@ Name|Request Type|Response Type|Access Token|URL|Doc `execUserAuthSucc`|TODO|TODO|+|`GET /cgi-bin/user/authsucc`|[二次验证](https://work.weixin.qq.com/api/doc#90000/90135/90203) `execUserBatchInvite`|TODO|TODO|+|`POST /cgi-bin/batch/invite`|[邀请成员](https://work.weixin.qq.com/api/doc#90000/90135/90975) `execUserIDByMobile`|`reqUserIDByMobile`|`respUserIDByMobile`|+|`POST /cgi-bin/user/getuserid`|[手机号获取userid](https://work.weixin.qq.com/api/doc/90001/90143/91693) +`execUserIDByEmail`|`reqUserIDByEmail`|`respUserIDByEmail`|+|`POST /cgi-bin/user/get_userid_by_email`|[邮箱获取userid](https://developer.work.weixin.qq.com/document/path/95895) # 部门管理 diff --git a/models.go b/models.go index 5c9bf52..9bb14c5 100644 --- a/models.go +++ b/models.go @@ -226,6 +226,38 @@ type respUserIDByMobile struct { UserID string `json:"userid"` } +// EmailType 用户邮箱的类型 +// +// 1表示用户邮箱是企业邮箱(默认) +// 2表示用户邮箱是个人邮箱 +type EmailType int + +const ( + // EmailTypeCorporate 企业邮箱 + EmailTypeCorporate EmailType = 1 + // EmailTypePersonal 个人邮箱 + EmailTypePersonal EmailType = 2 +) + +// reqUserIDByEmail 邮箱获取 userid 请求 +type reqUserIDByEmail struct { + Email string `json:"email"` + EmailType EmailType `json:"email_type"` +} + +var _ bodyer = reqUserIDByEmail{} + +func (x reqUserIDByEmail) intoBody() ([]byte, error) { + return marshalIntoJSONBody(x) +} + +// respUserIDByEmail 邮箱获取 userid 响应 +type respUserIDByEmail struct { + respCommon + + UserID string `json:"userid"` +} + // reqDeptCreate 创建部门 type reqDeptCreate struct { DeptInfo *DeptInfo diff --git a/user_info.go b/user_info.go index d3985b8..34fa425 100644 --- a/user_info.go +++ b/user_info.go @@ -49,6 +49,21 @@ func (c *WorkwxApp) GetUserIDByMobile(mobile string) (string, error) { return resp.UserID, nil } +// GetUserIDByEmail 通过邮箱获取 userid +func (c *WorkwxApp) GetUserIDByEmail(email string, emailType EmailType) (string, error) { + if emailType == 0 { + emailType = EmailTypeCorporate + } + resp, err := c.execUserIDByEmail(reqUserIDByEmail{ + Email: email, + EmailType: emailType, + }) + if err != nil { + return "", err + } + return resp.UserID, nil +} + // GetUserInfoByCode 获取访问用户身份,根据code获取成员信息 func (c *WorkwxApp) GetUserInfoByCode(code string) (*UserIdentityInfo, error) { resp, err := c.execUserInfoGet(reqUserInfoGet{