Skip to content

Commit

Permalink
feat: add GetUserIDByEmail
Browse files Browse the repository at this point in the history
  • Loading branch information
kanzihuang committed Jul 18, 2023
1 parent 1d2c205 commit 5ead293
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
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

0 comments on commit 5ead293

Please sign in to comment.