1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-04 12:52:27 +08:00

feat: 企业微信-通讯录管理,新增更新成员、更新部门、删除部门方法 (#799)

This commit is contained in:
markwang
2024-12-20 14:34:48 +08:00
committed by GitHub
parent 35af33f0bc
commit 3bd886d7f2
2 changed files with 95 additions and 1 deletions

View File

@@ -9,12 +9,16 @@ import (
const ( const (
// departmentCreateURL 创建部门 // departmentCreateURL 创建部门
departmentCreateURL = "https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=%s" departmentCreateURL = "https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=%s"
// departmentUpdateURL 更新部门
departmentUpdateURL = "https://qyapi.weixin.qq.com/cgi-bin/department/update?access_token=%s"
// departmentDeleteURL 删除部门
departmentDeleteURL = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?access_token=%s&id=%d"
// departmentSimpleListURL 获取子部门ID列表 // departmentSimpleListURL 获取子部门ID列表
departmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d" departmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d"
// departmentListURL 获取部门列表 // 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" 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 获取单个部门详情
departmentGetURL = "https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=%s&id=%d" departmentGetURL = "https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=%s&id=%d"
) )
@@ -85,6 +89,49 @@ func (r *Client) DepartmentCreate(req *DepartmentCreateRequest) (*DepartmentCrea
return result, err return result, err
} }
// DepartmentUpdateRequest 更新部门请求
type DepartmentUpdateRequest struct {
ID int `json:"id"`
Name string `json:"name,omitempty"`
NameEn string `json:"name_en,omitempty"`
ParentID int `json:"parentid,omitempty"`
Order int `json:"order,omitempty"`
}
// DepartmentUpdate 更新部门
// see https://developer.work.weixin.qq.com/document/path/90206
func (r *Client) DepartmentUpdate(req *DepartmentUpdateRequest) error {
var (
accessToken string
err error
)
if accessToken, err = r.GetAccessToken(); err != nil {
return err
}
var response []byte
if response, err = util.PostJSON(fmt.Sprintf(departmentUpdateURL, accessToken), req); err != nil {
return err
}
return util.DecodeWithCommonError(response, "DepartmentUpdate")
}
// DepartmentDelete 删除部门
// @see https://developer.work.weixin.qq.com/document/path/90207
func (r *Client) DepartmentDelete(departmentID int) error {
var (
accessToken string
err error
)
if accessToken, err = r.GetAccessToken(); err != nil {
return err
}
var response []byte
if response, err = util.HTTPGet(fmt.Sprintf(departmentDeleteURL, accessToken, departmentID)); err != nil {
return err
}
return util.DecodeWithCommonError(response, "DepartmentDelete")
}
// DepartmentSimpleList 获取子部门ID列表 // DepartmentSimpleList 获取子部门ID列表
// see https://developer.work.weixin.qq.com/document/path/95350 // see https://developer.work.weixin.qq.com/document/path/95350
func (r *Client) DepartmentSimpleList(departmentID int) ([]*DepartmentID, error) { func (r *Client) DepartmentSimpleList(departmentID int) ([]*DepartmentID, error) {

View File

@@ -12,6 +12,8 @@ const (
userSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist" userSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist"
// userCreateURL 创建成员 // userCreateURL 创建成员
userCreateURL = "https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=%s" userCreateURL = "https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=%s"
// userUpdateURL 更新成员
userUpdateURL = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=%s"
// userGetURL 读取成员 // userGetURL 读取成员
userGetURL = "https://qyapi.weixin.qq.com/cgi-bin/user/get" userGetURL = "https://qyapi.weixin.qq.com/cgi-bin/user/get"
// userDeleteURL 删除成员 // userDeleteURL 删除成员
@@ -154,6 +156,51 @@ func (r *Client) UserCreate(req *UserCreateRequest) (*UserCreateResponse, error)
return result, err return result, err
} }
// UserUpdateRequest 更新成员请求
type UserUpdateRequest struct {
UserID string `json:"userid"`
NewUserID string `json:"new_userid"`
Name string `json:"name"`
Alias string `json:"alias"`
Mobile string `json:"mobile"`
Department []int `json:"department"`
Order []int `json:"order"`
Position string `json:"position"`
Gender int `json:"gender"`
Email string `json:"email"`
BizMail string `json:"biz_mail"`
IsLeaderInDept []int `json:"is_leader_in_dept"`
DirectLeader []string `json:"direct_leader"`
Enable int `json:"enable"`
AvatarMediaid string `json:"avatar_mediaid"`
Telephone string `json:"telephone"`
Address string `json:"address"`
MainDepartment int `json:"main_department"`
Extattr struct {
Attrs []ExtraAttr `json:"attrs"`
} `json:"extattr"`
ToInvite bool `json:"to_invite"`
ExternalPosition string `json:"external_position"`
ExternalProfile ExternalProfile `json:"external_profile"`
}
// UserUpdate 更新成员
// see https://developer.work.weixin.qq.com/document/path/90197
func (r *Client) UserUpdate(req *UserUpdateRequest) error {
var (
accessToken string
err error
)
if accessToken, err = r.GetAccessToken(); err != nil {
return err
}
var response []byte
if response, err = util.PostJSON(fmt.Sprintf(userUpdateURL, accessToken), req); err != nil {
return err
}
return util.DecodeWithCommonError(response, "UserUpdate")
}
// UserGetResponse 获取部门成员响应 // UserGetResponse 获取部门成员响应
type UserGetResponse struct { type UserGetResponse struct {
util.CommonError util.CommonError