diff --git a/work/addresslist/department.go b/work/addresslist/department.go index b2feca0bf..5f65d660b 100644 --- a/work/addresslist/department.go +++ b/work/addresslist/department.go @@ -9,12 +9,16 @@ import ( const ( // departmentCreateURL 创建部门 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 = "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" 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" ) @@ -85,6 +89,49 @@ func (r *Client) DepartmentCreate(req *DepartmentCreateRequest) (*DepartmentCrea 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列表 // see https://developer.work.weixin.qq.com/document/path/95350 func (r *Client) DepartmentSimpleList(departmentID int) ([]*DepartmentID, error) { diff --git a/work/addresslist/user.go b/work/addresslist/user.go index 61bb14612..b8092f7f7 100644 --- a/work/addresslist/user.go +++ b/work/addresslist/user.go @@ -12,6 +12,8 @@ const ( userSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist" // userCreateURL 创建成员 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 = "https://qyapi.weixin.qq.com/cgi-bin/user/get" // userDeleteURL 删除成员 @@ -154,6 +156,51 @@ func (r *Client) UserCreate(req *UserCreateRequest) (*UserCreateResponse, error) 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 获取部门成员响应 type UserGetResponse struct { util.CommonError