mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 21:02:25 +08:00
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package addresslist
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/silenceper/wechat/v2/util"
|
|
)
|
|
|
|
const (
|
|
// UserSimpleListURL 获取部门成员
|
|
UserSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=%s&department_id=%d"
|
|
)
|
|
|
|
type (
|
|
// UserSimpleListResponse 获取部门成员响应
|
|
UserSimpleListResponse struct {
|
|
util.CommonError
|
|
UserList []*UserList
|
|
}
|
|
// UserList 部门成员
|
|
UserList struct {
|
|
UserID string `json:"userid"`
|
|
Name string `json:"name"`
|
|
Department []int `json:"department"`
|
|
OpenUserID string `json:"open_userid"`
|
|
}
|
|
)
|
|
|
|
// UserSimpleList 获取部门成员
|
|
// @see https://developer.work.weixin.qq.com/document/path/90200
|
|
func (r *Client) UserSimpleList(departmentID int) ([]*UserList, error) {
|
|
var (
|
|
accessToken string
|
|
err error
|
|
)
|
|
if accessToken, err = r.GetAccessToken(); err != nil {
|
|
return nil, err
|
|
}
|
|
var response []byte
|
|
if response, err = util.HTTPGet(fmt.Sprintf(UserSimpleListURL, accessToken, departmentID)); err != nil {
|
|
return nil, err
|
|
}
|
|
result := &UserSimpleListResponse{}
|
|
err = util.DecodeWithError(response, result, "UserSimpleList")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return result.UserList, nil
|
|
}
|