@@ -9,12 +9,16 @@ import (
9
9
const (
10
10
// departmentCreateURL 创建部门
11
11
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"
12
16
// departmentSimpleListURL 获取子部门ID列表
13
17
departmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d"
14
18
// departmentListURL 获取部门列表
15
19
departmentListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s"
16
20
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 获取单个部门详情
18
22
departmentGetURL = "https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=%s&id=%d"
19
23
)
20
24
@@ -85,6 +89,49 @@ func (r *Client) DepartmentCreate(req *DepartmentCreateRequest) (*DepartmentCrea
85
89
return result , err
86
90
}
87
91
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
+
88
135
// DepartmentSimpleList 获取子部门ID列表
89
136
// see https://developer.work.weixin.qq.com/document/path/95350
90
137
func (r * Client ) DepartmentSimpleList (departmentID int ) ([]* DepartmentID , error ) {
0 commit comments