Skip to content

Commit

Permalink
新增获取部门列表接口:https://qyapi.weixin.qq.com/cgi-bin/department/list (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
just5325 committed Jul 15, 2023
1 parent 45ad2ab commit c84eb7b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions work/addresslist/department.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
const (
// departmentSimpleListURL 获取子部门ID列表
departmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d"
// departmentListURL 获取部门列表
departmentListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s"
)

type (
Expand All @@ -23,6 +25,21 @@ type (
ParentID int `json:"parentid"`
Order int `json:"order"`
}

// DepartmentListResponse 获取部门列表响应
DepartmentListResponse struct {
util.CommonError
Department []*Department `json:"department"`
}
// Department 部门列表数据
Department struct {
ID int `json:"id"` // 创建的部门id
Name string `json:"name"` // 部门名称
NameEn string `json:"name_en"` // 英文名称
DepartmentLeader []string `json:"department_leader"` // 部门负责人的UserID
ParentID int `json:"parentid"` // 父部门id。根部门为1
Order int `json:"order"` // 在父部门中的次序值。order值大的排序靠前
}
)

// DepartmentSimpleList 获取子部门ID列表
Expand All @@ -45,3 +62,25 @@ func (r *Client) DepartmentSimpleList(departmentID int) ([]*DepartmentID, error)
}
return result.DepartmentID, nil
}

// DepartmentList 获取部门列表
// @desc https://developer.work.weixin.qq.com/document/path/90208
func (r *Client) DepartmentList() ([]*Department, error) {
// 获取accessToken
accessToken, err := r.GetAccessToken()
if err != nil {
return nil, err
}
// 发起http请求
response, err := util.HTTPGet(fmt.Sprintf(departmentListURL, accessToken))
if err != nil {
return nil, err
}
// 按照结构体解析返回值
result := &DepartmentListResponse{}
if err = util.DecodeWithError(response, result, "DepartmentList"); err != nil {
return nil, err
}
// 返回数据
return result.Department, err
}

0 comments on commit c84eb7b

Please sign in to comment.