From c84eb7b550e15bd647b344be8ec20c72ba2f92d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E7=BF=A0=E5=88=9A?= <532508307@qq.com> Date: Sat, 15 Jul 2023 23:56:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=EF=BC=9Ahttps://q?= =?UTF-8?q?yapi.weixin.qq.com/cgi-bin/department/list=20(#698)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- work/addresslist/department.go | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/work/addresslist/department.go b/work/addresslist/department.go index cf23946..91b0f3d 100644 --- a/work/addresslist/department.go +++ b/work/addresslist/department.go @@ -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 ( @@ -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列表 @@ -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 +}