| 1 | package QQ::weixin::work::oa::calendar; | ||
| 2 | |||
| 3 | =encoding utf8 | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | QQ::weixin::work::oa::calendar | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | 日历 | ||
| 12 | |||
| 13 | =cut | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use base qw(QQ::weixin::work::oa); | ||
| 17 | use Encode; | ||
| 18 | use LWP::UserAgent; | ||
| 19 | use JSON; | ||
| 20 | use utf8; | ||
| 21 | |||
| 22 | our $VERSION = '0.10'; | ||
| 23 | our @EXPORT = qw/ add update get del /; | ||
| 24 | |||
| 25 | =head1 FUNCTION | ||
| 26 | |||
| 27 | =head2 add(access_token, hash); | ||
| 28 | |||
| 29 | 创建日历 | ||
| 30 | 最后更新:2023/04/23 | ||
| 31 | |||
| 32 | =head2 SYNOPSIS | ||
| 33 | |||
| 34 | L<https://developer.work.weixin.qq.com/document/path/93647> | ||
| 35 | |||
| 36 | =head3 请求说明: | ||
| 37 | |||
| 38 | 该接口用于通过应用在企业内创建一个日历。 | ||
| 39 | |||
| 40 | =head4 请求包结构体为: | ||
| 41 | |||
| 42 | { | ||
| 43 | "calendar": { | ||
| 44 | "admins":[ | ||
| 45 | "admin1", | ||
| 46 | "admin2" | ||
| 47 | ], | ||
| 48 | "set_as_default": 1, | ||
| 49 | "summary": "test_summary", | ||
| 50 | "color": "#FF3030", | ||
| 51 | "description": "test_describe", | ||
| 52 | "shares": [{ | ||
| 53 | "userid": "userid2", | ||
| 54 | "permission": 1 | ||
| 55 | }, | ||
| 56 | { | ||
| 57 | "userid": "userid3", | ||
| 58 | "permission": 3 | ||
| 59 | } | ||
| 60 | ], | ||
| 61 | "is_public": 1, | ||
| 62 | "public_range": { | ||
| 63 | "userids": ["abel", "jack"], | ||
| 64 | "partyids": [1232, 34353] | ||
| 65 | }, | ||
| 66 | "is_corp_calendar": 1 | ||
| 67 | }, | ||
| 68 | "agentid": 1000014 | ||
| 69 | } | ||
| 70 | |||
| 71 | =head4 参数说明: | ||
| 72 | |||
| 73 | 参数 是否必须 说明 | ||
| 74 | calendar 是 日历信息 | ||
| 75 | admins 否 日历的管理员userid列表,管理员必须在通知范围成员的列表中。最多指定3人 | ||
| 76 | set_as_default 否 是否将该日历设置为access_token所对应应用的默认日历。 | ||
| 77 | 0-否;1-是。默认为0,即不设为默认日历 | ||
| 78 | 第三方应用不支持使用该参数 | ||
| 79 | summary 是 日历标题。1 ~ 128 字符 | ||
| 80 | color 是 日历在终端上显示的颜色,RGB颜色编码16进制表示,例如:"#0000FF" 表示纯蓝色 | ||
| 81 | description 否 日历描述。0 ~ 512 字符 | ||
| 82 | is_public 否 是否公共日历。0-否;1-是。注意:每个人最多可创建或订阅100个公共日历。该属性不可更新 | ||
| 83 | public_range 否 公开范围。仅当是公共日历时有效 | ||
| 84 | public_range.userids 否 公开的成员列表范围 。最多指定1000个成员 | ||
| 85 | public_range.partyids 否 公开的部门列表范围 。最多指定100个部门 | ||
| 86 | is_corp_calendar 否 是否全员日历。0-否;1-是。注意: | ||
| 87 | 1. 每个企业最多可创建20个全员日历 | ||
| 88 | 2. 全员日历也是公共日历的一种,需要指定public_range | ||
| 89 | 3. 全员日历不支持指定颜色、默认日历、只读权限 | ||
| 90 | 4. 该属性不可更新 | ||
| 91 | shares 否 日历通知范围成员列表。最多2000人 | ||
| 92 | shares.userid 是 日历通知范围成员的id | ||
| 93 | shares.permission 否 日历通知范围成员权限(不填则默认为「可查看」)。 | ||
| 94 | 1:可查看 | ||
| 95 | 3:仅查看闲忙状态 | ||
| 96 | agentid 否 授权方安装的应用agentid。仅旧的第三方多应用套件需要填此参数 | ||
| 97 | |||
| 98 | =head3 权限说明 | ||
| 99 | |||
| 100 | =head3 RETURN 返回结果 | ||
| 101 | |||
| 102 | { | ||
| 103 | "errcode": 0, | ||
| 104 | "errmsg" : "ok", | ||
| 105 | "cal_id":"wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA", | ||
| 106 | "fail_result": { | ||
| 107 | "shares":[{ | ||
| 108 | "errcode": 40001, | ||
| 109 | "errmsg": "not found", | ||
| 110 | "userid": "userid3" | ||
| 111 | }] | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | =head3 RETURN 参数说明 | ||
| 116 | |||
| 117 | 参数 说明 | ||
| 118 | errcode 错误码 | ||
| 119 | errmsg 错误码说明 | ||
| 120 | cal_id 日历ID | ||
| 121 | fail_result 无效的输入内容 | ||
| 122 | fail_result.shares 无效的日历通知范围成员列表 | ||
| 123 | shares.errcode 错误码 | ||
| 124 | shares.errmsg 错误码说明 | ||
| 125 | shares.userid 日历通知范围成员的id | ||
| 126 | |||
| 127 | =cut | ||
| 128 | |||
| 129 | sub add { | ||
| 130 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 131 | my $access_token = $_[0]; | ||
| 132 | my $json = $_[1]; | ||
| 133 | my $ua = LWP::UserAgent->new; | ||
| 134 | $ua->timeout(30); | ||
| 135 | $ua->env_proxy; | ||
| 136 | |||
| 137 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/oa/calendar/add?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 138 | if ($response->is_success) { | ||
| 139 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 140 | } | ||
| 141 | |||
| 142 | } | ||
| 143 | return 0; | ||
| 144 | } | ||
| 145 | |||
| 146 | =head2 update(access_token, hash); | ||
| 147 | |||
| 148 | 更新日历 | ||
| 149 | 最后更新:2023/08/31 | ||
| 150 | |||
| 151 | =head2 SYNOPSIS | ||
| 152 | |||
| 153 | L<https://developer.work.weixin.qq.com/document/path/97716> | ||
| 154 | |||
| 155 | =head3 请求说明: | ||
| 156 | |||
| 157 | 该接口用于修改指定日历的信息。 | ||
| 158 | |||
| 159 | 注意,更新操作是覆盖式,而不是增量式 | ||
| 160 | |||
| 161 | =head4 请求包体: | ||
| 162 | |||
| 163 | { | ||
| 164 | "skip_public_range" : 0, | ||
| 165 | "calendar": { | ||
| 166 | "cal_id": "wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA", | ||
| 167 | "admins":[ | ||
| 168 | "admin1", | ||
| 169 | "admin2" | ||
| 170 | ], | ||
| 171 | "summary": "test_summary", | ||
| 172 | "color": "#FF3030", | ||
| 173 | "description": "test_describe_1", | ||
| 174 | "shares": [{ | ||
| 175 | "userid": "userid1", | ||
| 176 | "permission": 1 | ||
| 177 | }, | ||
| 178 | { | ||
| 179 | "userid": "userid2", | ||
| 180 | "permission": 3 | ||
| 181 | } | ||
| 182 | ], | ||
| 183 | "public_range": { | ||
| 184 | "userids": ["abel", "jack"], | ||
| 185 | "partyids": [1232, 34353] | ||
| 186 | } | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | =head4 参数说明: | ||
| 191 | |||
| 192 | 参数 是否必须 说明 | ||
| 193 | skip_public_range 否 是否不更新可订阅范围。0-否;1-是。默认会为0,会更新可订阅范围 | ||
| 194 | calendar 是 日历信息 | ||
| 195 | cal_id 是 日历ID | ||
| 196 | admins 否 日历的管理员userid列表。最多指定3人 | ||
| 197 | summary 是 日历标题。1 ~ 128 字符 | ||
| 198 | color 是 日历颜色,RGB颜色编码16进制表示,例如:"#0000FF" 表示纯蓝色 | ||
| 199 | description 否 日历描述。0 ~ 512 字符 | ||
| 200 | public_range 否 公开范围。仅当是公共日历时有效 | ||
| 201 | public_range.userids 否 公开的成员列表范围 。最多指定1000个成员 | ||
| 202 | public_range.partyids 否 公开的部门列表范围 。最多指定100个部门 | ||
| 203 | shares 否 日历通知范围成员列表。最多2000人 | ||
| 204 | shares.userid 是 日历通知范围成员的id | ||
| 205 | shares.permission 否 日历通知范围成员权限(不填则默认为「可查看」)。 | ||
| 206 | 1:可查看 | ||
| 207 | 3:仅查看闲忙状态 | ||
| 208 | |||
| 209 | =head3 权限说明 | ||
| 210 | |||
| 211 | 注意, 不可更新组织者。 | ||
| 212 | |||
| 213 | =head3 RETURN 返回结果 | ||
| 214 | |||
| 215 | { | ||
| 216 | "errcode": 0, | ||
| 217 | "errmsg" : "ok", | ||
| 218 | "fail_result": { | ||
| 219 | "shares":[{ | ||
| 220 | "errcode": 40001, | ||
| 221 | "errmsg": "not found", | ||
| 222 | "userid": "userid3" | ||
| 223 | }] | ||
| 224 | } | ||
| 225 | } | ||
| 226 | |||
| 227 | =head3 RETURN 参数说明 | ||
| 228 | |||
| 229 | 参数 说明 | ||
| 230 | errcode 错误码 | ||
| 231 | errmsg 错误码说明 | ||
| 232 | fail_result 无效的输入内容 | ||
| 233 | fail_result.shares 无效的日历通知范围成员列表 | ||
| 234 | shares.errcode 错误码 | ||
| 235 | shares.errmsg 错误码说明 | ||
| 236 | shares.userid 日历通知范围成员的id | ||
| 237 | |||
| 238 | =cut | ||
| 239 | |||
| 240 | sub update { | ||
| 241 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 242 | my $access_token = $_[0]; | ||
| 243 | my $json = $_[1]; | ||
| 244 | my $ua = LWP::UserAgent->new; | ||
| 245 | $ua->timeout(30); | ||
| 246 | $ua->env_proxy; | ||
| 247 | |||
| 248 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/oa/calendar/update?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 249 | if ($response->is_success) { | ||
| 250 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 251 | } | ||
| 252 | |||
| 253 | } | ||
| 254 | return 0; | ||
| 255 | } | ||
| 256 | |||
| 257 | =head2 get(access_token, hash); | ||
| 258 | |||
| 259 | 获取日历详情 | ||
| 260 | 最后更新:2023/04/11 | ||
| 261 | |||
| 262 | =head2 SYNOPSIS | ||
| 263 | |||
| 264 | L<https://developer.work.weixin.qq.com/document/path/97717> | ||
| 265 | |||
| 266 | =head3 请求说明: | ||
| 267 | |||
| 268 | 该接口用于获取应用在企业内创建的日历信息。 | ||
| 269 | |||
| 270 | =head4 请求包结构体为: | ||
| 271 | |||
| 272 | { | ||
| 273 | "cal_id_list": ["wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA"] | ||
| 274 | } | ||
| 275 | |||
| 276 | =head4 参数说明: | ||
| 277 | |||
| 278 | 参数 必须 说明 | ||
| 279 | access_token 是 调用接口凭证 | ||
| 280 | cal_id_list 是 日历ID列表,调用创建日历接口后获得。一次最多可获取1000条 | ||
| 281 | |||
| 282 | =head3 权限说明 | ||
| 283 | |||
| 284 | =head3 RETURN 返回结果 | ||
| 285 | |||
| 286 | { | ||
| 287 | "errcode": 0, | ||
| 288 | "errmsg": "ok", | ||
| 289 | "calendar_list": [{ | ||
| 290 | "cal_id": "wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA", | ||
| 291 | "adminis":[ | ||
| 292 | "admin1", | ||
| 293 | "admin2", | ||
| 294 | ], | ||
| 295 | "summary": "test_summary", | ||
| 296 | "color": "#FF3030", | ||
| 297 | "description": "test_describe_1", | ||
| 298 | "shares": [{ | ||
| 299 | "userid": "userid2", | ||
| 300 | "permission": 1 | ||
| 301 | }, | ||
| 302 | { | ||
| 303 | "userid": "userid1", | ||
| 304 | "permission": 3 | ||
| 305 | } | ||
| 306 | ], | ||
| 307 | "is_public": 1, | ||
| 308 | "public_range": { | ||
| 309 | "userids": ["abel", "jack"], | ||
| 310 | "partyids": [1232, 34353] | ||
| 311 | }, | ||
| 312 | "is_corp_calendar": 1 | ||
| 313 | }] | ||
| 314 | } | ||
| 315 | |||
| 316 | =head3 RETURN 参数说明 | ||
| 317 | |||
| 318 | 参数 说明 | ||
| 319 | errcode 错误码 | ||
| 320 | errmsg 错误码说明 | ||
| 321 | calendar_list 日历列表 | ||
| 322 | cal_id 日历ID | ||
| 323 | admins 日历的管理员userid列表 | ||
| 324 | summary 日历标题。1 ~ 128 字符 | ||
| 325 | color 日历颜色,RGB颜色编码16进制表示,例如:"#0000FF" 表示纯蓝色 | ||
| 326 | description 日历描述。0 ~ 512 字符 | ||
| 327 | is_public 是否公共日历。0-否;1-是 | ||
| 328 | public_range 公开范围。仅当是公共日历时有效 | ||
| 329 | public_range.userids 公开的成员列表范围 | ||
| 330 | public_range.partyids 公开的部门列表范围 | ||
| 331 | is_corp_calendar 是否全员日历。0-否;1-是 | ||
| 332 | shares 日历通知范围成员列表。最多2000人 | ||
| 333 | shares.userid 日历通知范围成员的id | ||
| 334 | shares.permission 日历通知范围成员权限。 | ||
| 335 | 1:可查看 | ||
| 336 | 3:仅查看闲忙状态 | ||
| 337 | |||
| 338 | =cut | ||
| 339 | |||
| 340 | sub get { | ||
| 341 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 342 | my $access_token = $_[0]; | ||
| 343 | my $json = $_[1]; | ||
| 344 | my $ua = LWP::UserAgent->new; | ||
| 345 | $ua->timeout(30); | ||
| 346 | $ua->env_proxy; | ||
| 347 | |||
| 348 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/oa/calendar/get?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 349 | if ($response->is_success) { | ||
| 350 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 351 | } | ||
| 352 | |||
| 353 | } | ||
| 354 | return 0; | ||
| 355 | } | ||
| 356 | |||
| 357 | =head2 del(access_token, hash); | ||
| 358 | |||
| 359 | 删除日历 | ||
| 360 | 最后更新:2022/12/01 | ||
| 361 | |||
| 362 | =head2 SYNOPSIS | ||
| 363 | |||
| 364 | L<https://developer.work.weixin.qq.com/document/path/97718> | ||
| 365 | |||
| 366 | =head3 请求说明: | ||
| 367 | |||
| 368 | 该接口用于删除指定日历。 | ||
| 369 | |||
| 370 | =head4 请求包体: | ||
| 371 | |||
| 372 | { | ||
| 373 | "cal_id":"wcjgewCwAAqeJcPI1d8Pwbjt7nttzAAA" | ||
| 374 | } | ||
| 375 | |||
| 376 | =head4 参数说明: | ||
| 377 | |||
| 378 | 参数 必须 说明 | ||
| 379 | access_token 是 调用接口凭证 | ||
| 380 | cal_id 是 日历ID | ||
| 381 | |||
| 382 | =head3 权限说明 | ||
| 383 | |||
| 384 | =head3 RETURN 返回结果 | ||
| 385 | |||
| 386 | { | ||
| 387 | "errcode": 0, | ||
| 388 | "errmsg": "ok" | ||
| 389 | } | ||
| 390 | |||
| 391 | =head3 RETURN 参数说明 | ||
| 392 | |||
| 393 | 参数 说明 | ||
| 394 | errcode 错误码 | ||
| 395 | errmsg 错误码说明 | ||
| 396 | |||
| 397 | =cut | ||
| 398 | |||
| 399 | sub del { | ||
| 400 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 401 | my $access_token = $_[0]; | ||
| 402 | my $json = $_[1]; | ||
| 403 | my $ua = LWP::UserAgent->new; | ||
| 404 | $ua->timeout(30); | ||
| 405 | $ua->env_proxy; | ||
| 406 | |||
| 407 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/oa/calendar/del?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 408 | if ($response->is_success) { | ||
| 409 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 410 | } | ||
| 411 | |||
| 412 | } | ||
| 413 | return 0; | ||
| 414 | } | ||
| 415 | |||
| 416 | |||
| 417 | 1; | ||
| 418 | __END__ |