mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-07 06:02:26 +08:00
企业微信-通讯录管理 (#601)
This commit is contained in:
17
work/addresslist/client.go
Normal file
17
work/addresslist/client.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package addresslist
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/v2/work/context"
|
||||
)
|
||||
|
||||
// Client 通讯录管理接口实例
|
||||
type Client struct {
|
||||
*context.Context
|
||||
}
|
||||
|
||||
// NewClient 初始化实例
|
||||
func NewClient(ctx *context.Context) *Client {
|
||||
return &Client{
|
||||
ctx,
|
||||
}
|
||||
}
|
||||
47
work/addresslist/department.go
Normal file
47
work/addresslist/department.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package addresslist
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// DepartmentSimpleListURL 获取子部门ID列表
|
||||
DepartmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d"
|
||||
)
|
||||
|
||||
type (
|
||||
// DepartmentSimpleListResponse 获取子部门ID列表响应
|
||||
DepartmentSimpleListResponse struct {
|
||||
util.CommonError
|
||||
DepartmentID []*DepartmentID `json:"department_id"`
|
||||
}
|
||||
// DepartmentID 子部门ID
|
||||
DepartmentID struct {
|
||||
ID int `json:"id"`
|
||||
ParentID int `json:"parentid"`
|
||||
Order int `json:"order"`
|
||||
}
|
||||
)
|
||||
|
||||
// DepartmentSimpleList 获取子部门ID列表
|
||||
// see https://developer.work.weixin.qq.com/document/path/95350
|
||||
func (r *Client) DepartmentSimpleList(departmentID int) ([]*DepartmentID, 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(DepartmentSimpleListURL, accessToken, departmentID)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &DepartmentSimpleListResponse{}
|
||||
if err = util.DecodeWithError(response, result, "DepartmentSimpleList"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.DepartmentID, nil
|
||||
}
|
||||
49
work/addresslist/user.go
Normal file
49
work/addresslist/user.go
Normal file
@@ -0,0 +1,49 @@
|
||||
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
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package work
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/v2/credential"
|
||||
"github.com/silenceper/wechat/v2/work/addresslist"
|
||||
"github.com/silenceper/wechat/v2/work/config"
|
||||
"github.com/silenceper/wechat/v2/work/context"
|
||||
"github.com/silenceper/wechat/v2/work/externalcontact"
|
||||
@@ -49,3 +50,8 @@ func (wk *Work) GetKF() (*kf.Client, error) {
|
||||
func (wk *Work) GetExternalContact() *externalcontact.Client {
|
||||
return externalcontact.NewClient(wk.ctx)
|
||||
}
|
||||
|
||||
// GetAddressList get address_list
|
||||
func (wk *Work) GetAddressList() *addresslist.Client {
|
||||
return addresslist.NewClient(wk.ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user