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(work): add department by id #741

Merged
merged 4 commits into from
Nov 2, 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
2 changes: 2 additions & 0 deletions doc/api/work.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ host: https://qyapi.weixin.qq.com/
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 |
|:---------:|------|:----------------------------------------| ---------- | ------------------------------- |----------|
| 获取子部门ID列表 | GET | /cgi-bin/department/simplelist | YES | (r *Client) DepartmentSimpleList| MARKWANG |
| 获取部门列表 | GET | /cgi-bin/department/list | YES | (r *Client) DepartmentList| just5325, ourines |
| 获取部门成员 | GET | /cgi-bin/user/simplelist | YES | (r *Client) UserSimpleList | MARKWANG |
| 获取成员ID列表 | Post | /cgi-bin/user/list_id | YES | (r *Client) UserListId | MARKWANG |



## 素材管理
[官方文档](https://developer.work.weixin.qq.com/document/path/91054)

Expand Down
23 changes: 21 additions & 2 deletions work/addresslist/department.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ 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"
departmentListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s"
departmentListByIDURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s&id=%d"
// departmentGetURL 获取单个部门详情 https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=ACCESS_TOKEN&id=ID
departmentGetURL = "https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=%s&id=%d"
)
Expand Down Expand Up @@ -106,13 +107,31 @@ func (r *Client) DepartmentSimpleList(departmentID int) ([]*DepartmentID, error)
// DepartmentList 获取部门列表
// @desc https://developer.work.weixin.qq.com/document/path/90208
func (r *Client) DepartmentList() ([]*Department, error) {
return r.DepartmentListByID(0)
}

// DepartmentListByID 获取部门列表
//
// departmentID 部门id。获取指定部门及其下的子部门(以及子部门的子部门等等,递归)
//
// @desc https://developer.work.weixin.qq.com/document/path/90208
func (r *Client) DepartmentListByID(departmentID int) ([]*Department, error) {
var formatURL string

// 获取accessToken
accessToken, err := r.GetAccessToken()
if err != nil {
return nil, err
}

if departmentID > 0 {
formatURL = fmt.Sprintf(departmentListByIDURL, accessToken, departmentID)
} else {
formatURL = fmt.Sprintf(departmentListURL, accessToken)
}

// 发起http请求
response, err := util.HTTPGet(fmt.Sprintf(departmentListURL, accessToken))
response, err := util.HTTPGet(formatURL)
if err != nil {
return nil, err
}
Expand Down