Skip to content

Commit 3bd886d

Browse files
authored
feat: 企业微信-通讯录管理,新增更新成员、更新部门、删除部门方法 (#799)
1 parent 35af33f commit 3bd886d

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed

work/addresslist/department.go

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ import (
99
const (
1010
// departmentCreateURL 创建部门
1111
departmentCreateURL = "https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=%s"
12+
// departmentUpdateURL 更新部门
13+
departmentUpdateURL = "https://qyapi.weixin.qq.com/cgi-bin/department/update?access_token=%s"
14+
// departmentDeleteURL 删除部门
15+
departmentDeleteURL = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?access_token=%s&id=%d"
1216
// departmentSimpleListURL 获取子部门ID列表
1317
departmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d"
1418
// departmentListURL 获取部门列表
1519
departmentListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s"
1620
departmentListByIDURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s&id=%d"
17-
// departmentGetURL 获取单个部门详情 https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=ACCESS_TOKEN&id=ID
21+
// departmentGetURL 获取单个部门详情
1822
departmentGetURL = "https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=%s&id=%d"
1923
)
2024

@@ -85,6 +89,49 @@ func (r *Client) DepartmentCreate(req *DepartmentCreateRequest) (*DepartmentCrea
8589
return result, err
8690
}
8791

92+
// DepartmentUpdateRequest 更新部门请求
93+
type DepartmentUpdateRequest struct {
94+
ID int `json:"id"`
95+
Name string `json:"name,omitempty"`
96+
NameEn string `json:"name_en,omitempty"`
97+
ParentID int `json:"parentid,omitempty"`
98+
Order int `json:"order,omitempty"`
99+
}
100+
101+
// DepartmentUpdate 更新部门
102+
// see https://developer.work.weixin.qq.com/document/path/90206
103+
func (r *Client) DepartmentUpdate(req *DepartmentUpdateRequest) error {
104+
var (
105+
accessToken string
106+
err error
107+
)
108+
if accessToken, err = r.GetAccessToken(); err != nil {
109+
return err
110+
}
111+
var response []byte
112+
if response, err = util.PostJSON(fmt.Sprintf(departmentUpdateURL, accessToken), req); err != nil {
113+
return err
114+
}
115+
return util.DecodeWithCommonError(response, "DepartmentUpdate")
116+
}
117+
118+
// DepartmentDelete 删除部门
119+
// @see https://developer.work.weixin.qq.com/document/path/90207
120+
func (r *Client) DepartmentDelete(departmentID int) error {
121+
var (
122+
accessToken string
123+
err error
124+
)
125+
if accessToken, err = r.GetAccessToken(); err != nil {
126+
return err
127+
}
128+
var response []byte
129+
if response, err = util.HTTPGet(fmt.Sprintf(departmentDeleteURL, accessToken, departmentID)); err != nil {
130+
return err
131+
}
132+
return util.DecodeWithCommonError(response, "DepartmentDelete")
133+
}
134+
88135
// DepartmentSimpleList 获取子部门ID列表
89136
// see https://developer.work.weixin.qq.com/document/path/95350
90137
func (r *Client) DepartmentSimpleList(departmentID int) ([]*DepartmentID, error) {

work/addresslist/user.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const (
1212
userSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist"
1313
// userCreateURL 创建成员
1414
userCreateURL = "https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=%s"
15+
// userUpdateURL 更新成员
16+
userUpdateURL = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=%s"
1517
// userGetURL 读取成员
1618
userGetURL = "https://qyapi.weixin.qq.com/cgi-bin/user/get"
1719
// userDeleteURL 删除成员
@@ -154,6 +156,51 @@ func (r *Client) UserCreate(req *UserCreateRequest) (*UserCreateResponse, error)
154156
return result, err
155157
}
156158

159+
// UserUpdateRequest 更新成员请求
160+
type UserUpdateRequest struct {
161+
UserID string `json:"userid"`
162+
NewUserID string `json:"new_userid"`
163+
Name string `json:"name"`
164+
Alias string `json:"alias"`
165+
Mobile string `json:"mobile"`
166+
Department []int `json:"department"`
167+
Order []int `json:"order"`
168+
Position string `json:"position"`
169+
Gender int `json:"gender"`
170+
Email string `json:"email"`
171+
BizMail string `json:"biz_mail"`
172+
IsLeaderInDept []int `json:"is_leader_in_dept"`
173+
DirectLeader []string `json:"direct_leader"`
174+
Enable int `json:"enable"`
175+
AvatarMediaid string `json:"avatar_mediaid"`
176+
Telephone string `json:"telephone"`
177+
Address string `json:"address"`
178+
MainDepartment int `json:"main_department"`
179+
Extattr struct {
180+
Attrs []ExtraAttr `json:"attrs"`
181+
} `json:"extattr"`
182+
ToInvite bool `json:"to_invite"`
183+
ExternalPosition string `json:"external_position"`
184+
ExternalProfile ExternalProfile `json:"external_profile"`
185+
}
186+
187+
// UserUpdate 更新成员
188+
// see https://developer.work.weixin.qq.com/document/path/90197
189+
func (r *Client) UserUpdate(req *UserUpdateRequest) error {
190+
var (
191+
accessToken string
192+
err error
193+
)
194+
if accessToken, err = r.GetAccessToken(); err != nil {
195+
return err
196+
}
197+
var response []byte
198+
if response, err = util.PostJSON(fmt.Sprintf(userUpdateURL, accessToken), req); err != nil {
199+
return err
200+
}
201+
return util.DecodeWithCommonError(response, "UserUpdate")
202+
}
203+
157204
// UserGetResponse 获取部门成员响应
158205
type UserGetResponse struct {
159206
util.CommonError

0 commit comments

Comments
 (0)