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

feat: add GetUserIDByEmail #168

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apis.md.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

# 部门管理

Expand Down
32 changes: 32 additions & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions user_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Loading