mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-11 00:02:27 +08:00
新增获取部门列表接口:https://qyapi.weixin.qq.com/cgi-bin/department/list (#698)
This commit is contained in:
@@ -9,6 +9,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
// departmentSimpleListURL 获取子部门ID列表
|
// departmentSimpleListURL 获取子部门ID列表
|
||||||
departmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d"
|
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 (
|
type (
|
||||||
@@ -23,6 +25,21 @@ type (
|
|||||||
ParentID int `json:"parentid"`
|
ParentID int `json:"parentid"`
|
||||||
Order int `json:"order"`
|
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列表
|
// DepartmentSimpleList 获取子部门ID列表
|
||||||
@@ -45,3 +62,25 @@ func (r *Client) DepartmentSimpleList(departmentID int) ([]*DepartmentID, error)
|
|||||||
}
|
}
|
||||||
return result.DepartmentID, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user