| 1 | package QQ::weixin::work::tag; | ||
| 2 | |||
| 3 | =encoding utf8 | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | QQ::weixin::work::tag | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | 通讯录管理->标签管理 | ||
| 12 | |||
| 13 | =cut | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use base qw(QQ::weixin::work); | ||
| 17 | use Encode; | ||
| 18 | use LWP::UserAgent; | ||
| 19 | use JSON; | ||
| 20 | use utf8; | ||
| 21 | |||
| 22 | our $VERSION = '0.10'; | ||
| 23 | our @EXPORT = qw/ create update delete get addtagusers deltagusers list /; | ||
| 24 | |||
| 25 | =head1 FUNCTION | ||
| 26 | |||
| 27 | =head2 create(access_token, hash); | ||
| 28 | |||
| 29 | 创建标签 | ||
| 30 | 最后更新:2020/06/08 | ||
| 31 | |||
| 32 | =head2 SYNOPSIS | ||
| 33 | |||
| 34 | L<https://developer.work.weixin.qq.com/document/path/90210> | ||
| 35 | |||
| 36 | =head3 请求说明: | ||
| 37 | |||
| 38 | =head4 请求包结构体为: | ||
| 39 | |||
| 40 | { | ||
| 41 | "tagname": "UI", | ||
| 42 | "tagid": 12 | ||
| 43 | } | ||
| 44 | |||
| 45 | =head4 参数说明: | ||
| 46 | |||
| 47 | 参数 必须 说明 | ||
| 48 | access_token 是 调用接口凭证 | ||
| 49 | tagname 是 标签名称,长度限制为32个字以内(汉字或英文字母),标签名不可与其他标签重名。 | ||
| 50 | tagid 否 标签id,非负整型,指定此参数时新增的标签会生成对应的标签id,不指定时则以目前最大的id自增。 | ||
| 51 | |||
| 52 | =head4 权限说明 | ||
| 53 | |||
| 54 | 创建的标签属于该应用,只有该应用才可以增删成员。 | ||
| 55 | |||
| 56 | 注意,标签总数不能超过3000个。 | ||
| 57 | |||
| 58 | =head3 RETURN 返回结果 | ||
| 59 | |||
| 60 | { | ||
| 61 | "errcode": 0, | ||
| 62 | "errmsg": "created", | ||
| 63 | "tagid": 12 | ||
| 64 | } | ||
| 65 | |||
| 66 | =head4 RETURN 参数说明 | ||
| 67 | |||
| 68 | 参数 说明 | ||
| 69 | errcode 返回码 | ||
| 70 | errmsg 对返回码的文本描述内容 | ||
| 71 | tagid 标签id | ||
| 72 | |||
| 73 | =cut | ||
| 74 | |||
| 75 | sub create { | ||
| 76 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 77 | my $access_token = $_[0]; | ||
| 78 | my $json = $_[1]; | ||
| 79 | my $ua = LWP::UserAgent->new; | ||
| 80 | $ua->timeout(30); | ||
| 81 | $ua->env_proxy; | ||
| 82 | |||
| 83 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/tag/create?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 84 | if ($response->is_success) { | ||
| 85 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 86 | } | ||
| 87 | |||
| 88 | } | ||
| 89 | return 0; | ||
| 90 | } | ||
| 91 | |||
| 92 | =head2 update(access_token, hash); | ||
| 93 | |||
| 94 | 更新标签名字 | ||
| 95 | 最后更新:2020/04/02 | ||
| 96 | |||
| 97 | =head2 SYNOPSIS | ||
| 98 | |||
| 99 | L<https://developer.work.weixin.qq.com/document/path/90211> | ||
| 100 | |||
| 101 | =head3 请求说明: | ||
| 102 | |||
| 103 | =head4 请求包结构体为: | ||
| 104 | |||
| 105 | { | ||
| 106 | "tagid": 12, | ||
| 107 | "tagname": "UI design" | ||
| 108 | } | ||
| 109 | |||
| 110 | =head4 参数说明: | ||
| 111 | |||
| 112 | 参数 必须 说明 | ||
| 113 | access_token 是 调用接口凭证 | ||
| 114 | tagid 是 标签ID | ||
| 115 | tagname 是 标签名称,长度限制为32个字(汉字或英文字母),标签不可与其他标签重名。 | ||
| 116 | |||
| 117 | =head4 权限说明 | ||
| 118 | |||
| 119 | 调用者必须是指定标签的创建者。 | ||
| 120 | |||
| 121 | =head3 RETURN 返回结果 | ||
| 122 | |||
| 123 | { | ||
| 124 | "errcode": 0, | ||
| 125 | "errmsg": "updated" | ||
| 126 | } | ||
| 127 | |||
| 128 | =head4 RETURN 参数说明 | ||
| 129 | |||
| 130 | 参数 说明 | ||
| 131 | errcode 返回码 | ||
| 132 | errmsg 对返回码的文本描述内容 | ||
| 133 | |||
| 134 | =cut | ||
| 135 | |||
| 136 | sub update { | ||
| 137 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 138 | my $access_token = $_[0]; | ||
| 139 | my $json = $_[1]; | ||
| 140 | my $ua = LWP::UserAgent->new; | ||
| 141 | $ua->timeout(30); | ||
| 142 | $ua->env_proxy; | ||
| 143 | |||
| 144 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/tag/update?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 145 | if ($response->is_success) { | ||
| 146 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 147 | } | ||
| 148 | |||
| 149 | } | ||
| 150 | return 0; | ||
| 151 | } | ||
| 152 | |||
| 153 | =head2 delete(access_token, tagid); | ||
| 154 | |||
| 155 | 删除标签 | ||
| 156 | 最后更新:2020/04/02 | ||
| 157 | |||
| 158 | =head2 SYNOPSIS | ||
| 159 | |||
| 160 | L<https://developer.work.weixin.qq.com/document/path/90212> | ||
| 161 | |||
| 162 | =head3 请求说明: | ||
| 163 | |||
| 164 | =head4 参数说明: | ||
| 165 | |||
| 166 | 参数 必须 说明 | ||
| 167 | access_token 是 调用接口凭证 | ||
| 168 | tagid 是 标签ID | ||
| 169 | |||
| 170 | =head4 权限说明 | ||
| 171 | |||
| 172 | 调用者必须是指定标签的创建者。 | ||
| 173 | |||
| 174 | =head3 RETURN 返回结果 | ||
| 175 | |||
| 176 | { | ||
| 177 | "errcode": 0, | ||
| 178 | "errmsg": "deleted" | ||
| 179 | } | ||
| 180 | |||
| 181 | =head4 RETURN 参数说明 | ||
| 182 | |||
| 183 | 参数 说明 | ||
| 184 | errcode 返回码 | ||
| 185 | errmsg 对返回码的文本描述内容 | ||
| 186 | |||
| 187 | =cut | ||
| 188 | |||
| 189 | sub delete { | ||
| 190 | if ( @_ && $_[0] && $_[1] ) { | ||
| 191 | my $access_token = $_[0]; | ||
| 192 | my $tagid = $_[1]; | ||
| 193 | my $ua = LWP::UserAgent->new; | ||
| 194 | $ua->timeout(30); | ||
| 195 | $ua->env_proxy; | ||
| 196 | |||
| 197 | my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/tag/delete?access_token=$access_token&tagid=$tagid"); | ||
| 198 | if ($response->is_success) { | ||
| 199 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 200 | } | ||
| 201 | |||
| 202 | } | ||
| 203 | return 0; | ||
| 204 | } | ||
| 205 | |||
| 206 | =head2 get(access_token, tagid); | ||
| 207 | |||
| 208 | 获取标签成员 | ||
| 209 | 最后更新:2021/08/11 | ||
| 210 | |||
| 211 | =head2 SYNOPSIS | ||
| 212 | |||
| 213 | L<https://developer.work.weixin.qq.com/document/path/90213> | ||
| 214 | |||
| 215 | =head3 请求说明: | ||
| 216 | |||
| 217 | =head4 参数说明: | ||
| 218 | |||
| 219 | 参数 必须 说明 | ||
| 220 | access_token 是 调用接口凭证 | ||
| 221 | tagid 是 标签ID | ||
| 222 | |||
| 223 | =head4 权限说明: | ||
| 224 | |||
| 225 | 无限制,但返回列表仅包含应用可见范围的成员;第三方可获取自己创建的标签及应用可见范围内的标签详情 | ||
| 226 | |||
| 227 | =head3 RETURN 返回结果 | ||
| 228 | |||
| 229 | { | ||
| 230 | "errcode": 0, | ||
| 231 | "errmsg": "ok", | ||
| 232 | "tagname": "乒乓球协会", | ||
| 233 | "userlist": [ | ||
| 234 | { | ||
| 235 | "userid": "zhangsan", | ||
| 236 | "name": "李四" | ||
| 237 | } | ||
| 238 | ], | ||
| 239 | "partylist": [2] | ||
| 240 | } | ||
| 241 | |||
| 242 | =head4 RETURN 参数说明 | ||
| 243 | |||
| 244 | 参数 说明 | ||
| 245 | errcode 返回码 | ||
| 246 | errmsg 对返回码的文本描述内容 | ||
| 247 | tagname 标签名 | ||
| 248 | userlist 标签中包含的成员列表 | ||
| 249 | userid 成员帐号 | ||
| 250 | name 成员名称,代开发自建应用需要管理员授权才返回该字段;此字段从2019年12月30日起,对新创建第三方应用不再返回,2020年6月30日起,对所有历史第三方应用不再返回,后续第三方仅通讯录应用可获取,第三方页面需要通过通讯录展示组件来展示名字 | ||
| 251 | partylist 标签中包含的部门id列表 | ||
| 252 | |||
| 253 | =cut | ||
| 254 | |||
| 255 | sub get { | ||
| 256 | if ( @_ && $_[0] && $_[1] ) { | ||
| 257 | my $access_token = $_[0]; | ||
| 258 | my $tagid = $_[1]; | ||
| 259 | my $ua = LWP::UserAgent->new; | ||
| 260 | $ua->timeout(30); | ||
| 261 | $ua->env_proxy; | ||
| 262 | |||
| 263 | my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/tag/get?access_token=$access_token&tagid=$tagid"); | ||
| 264 | if ($response->is_success) { | ||
| 265 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 266 | } | ||
| 267 | |||
| 268 | } | ||
| 269 | return 0; | ||
| 270 | } | ||
| 271 | |||
| 272 | =head2 addtagusers(access_token, hash); | ||
| 273 | |||
| 274 | 增加标签成员 | ||
| 275 | 最后更新:2020/12/07 | ||
| 276 | |||
| 277 | =head2 SYNOPSIS | ||
| 278 | |||
| 279 | L<https://developer.work.weixin.qq.com/document/path/90214> | ||
| 280 | |||
| 281 | =head3 请求说明: | ||
| 282 | |||
| 283 | =head4 请求包结构体为: | ||
| 284 | |||
| 285 | { | ||
| 286 | "tagid": 12, | ||
| 287 | "userlist":[ "user1","user2"], | ||
| 288 | "partylist": [4] | ||
| 289 | } | ||
| 290 | |||
| 291 | =head4 参数说明: | ||
| 292 | |||
| 293 | 参数 必须 说明 | ||
| 294 | access_token 是 调用接口凭证 | ||
| 295 | tagid 是 标签ID | ||
| 296 | userlist 否 企业成员ID列表,注意:userlist、partylist不能同时为空,单次请求长度不超过1000 | ||
| 297 | partylist 否 企业部门ID列表,注意:userlist、partylist不能同时为空,单次请求长度不超过100 | ||
| 298 | |||
| 299 | =head4 权限说明: | ||
| 300 | |||
| 301 | 调用者必须是指定标签的创建者;成员属于应用的可见范围。 | ||
| 302 | |||
| 303 | 注意,每个标签下部门、人员总数不能超过3万个。 | ||
| 304 | |||
| 305 | =head3 RETURN 返回结果 | ||
| 306 | |||
| 307 | a)正确时返回 | ||
| 308 | |||
| 309 | { | ||
| 310 | "errcode": 0, | ||
| 311 | "errmsg": "ok" | ||
| 312 | } | ||
| 313 | |||
| 314 | b)若部分userid、partylist非法,则返回 | ||
| 315 | |||
| 316 | { | ||
| 317 | "errcode": 0, | ||
| 318 | "errmsg": "ok", | ||
| 319 | "invalidlist":"usr1|usr2|usr", | ||
| 320 | "invalidparty":[2,4] | ||
| 321 | } | ||
| 322 | |||
| 323 | c)当包含userid、partylist全部非法时返回 | ||
| 324 | |||
| 325 | { | ||
| 326 | "errcode": 40070, | ||
| 327 | "errmsg": "all list invalid" | ||
| 328 | } | ||
| 329 | |||
| 330 | =head4 RETURN 参数说明 | ||
| 331 | |||
| 332 | 参数 说明 | ||
| 333 | errcode 返回码 | ||
| 334 | errmsg 对返回码的文本描述内容 | ||
| 335 | invalidlist 非法的成员帐号列表 | ||
| 336 | invalidparty 非法的部门id列表 | ||
| 337 | |||
| 338 | =cut | ||
| 339 | |||
| 340 | sub addtagusers { | ||
| 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/tag/addtagusers?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 deltagusers(access_token, hash); | ||
| 358 | |||
| 359 | 删除标签成员 | ||
| 360 | 最后更新:2020/04/02 | ||
| 361 | |||
| 362 | =head2 SYNOPSIS | ||
| 363 | |||
| 364 | L<https://developer.work.weixin.qq.com/document/path/90215> | ||
| 365 | |||
| 366 | =head3 请求说明: | ||
| 367 | |||
| 368 | =head4 请求包结构体为: | ||
| 369 | |||
| 370 | { | ||
| 371 | "tagid": 12, | ||
| 372 | "userlist":[ "user1","user2"], | ||
| 373 | "partylist": [2,4] | ||
| 374 | } | ||
| 375 | |||
| 376 | =head4 参数说明: | ||
| 377 | |||
| 378 | 参数 必须 说明 | ||
| 379 | access_token 是 调用接口凭证 | ||
| 380 | tagid 是 标签ID | ||
| 381 | userlist 否 企业成员ID列表,注意:userlist、partylist不能同时为空,单次请求长度不超过1000 | ||
| 382 | partylist 否 企业部门ID列表,注意:userlist、partylist不能同时为空,单次请求长度不超过100 | ||
| 383 | |||
| 384 | =head4 权限说明: | ||
| 385 | |||
| 386 | 调用者必须是指定标签的创建者;成员属于应用的可见范围。 | ||
| 387 | |||
| 388 | =head3 RETURN 返回结果 | ||
| 389 | |||
| 390 | a)正确时返回 | ||
| 391 | |||
| 392 | { | ||
| 393 | "errcode": 0, | ||
| 394 | "errmsg": "deleted" | ||
| 395 | } | ||
| 396 | |||
| 397 | b)若部分userid、partylist非法,则返回 | ||
| 398 | |||
| 399 | { | ||
| 400 | "errcode": 0, | ||
| 401 | "errmsg": "deleted", | ||
| 402 | "invalidlist":"usr1|usr2|usr", | ||
| 403 | "invalidparty":[2,4] | ||
| 404 | } | ||
| 405 | |||
| 406 | c)当包含userid、partylist全部非法时返回 | ||
| 407 | |||
| 408 | { | ||
| 409 | "errcode": 40031, | ||
| 410 | "errmsg": "all list invalid" | ||
| 411 | } | ||
| 412 | |||
| 413 | =head4 RETURN 参数说明 | ||
| 414 | |||
| 415 | 参数 说明 | ||
| 416 | errcode 返回码 | ||
| 417 | errmsg 对返回码的文本描述内容 | ||
| 418 | invalidlist 非法的成员帐号列表 | ||
| 419 | invalidparty 非法的部门id列表 | ||
| 420 | |||
| 421 | =cut | ||
| 422 | |||
| 423 | sub deltagusers { | ||
| 424 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 425 | my $access_token = $_[0]; | ||
| 426 | my $json = $_[1]; | ||
| 427 | my $ua = LWP::UserAgent->new; | ||
| 428 | $ua->timeout(30); | ||
| 429 | $ua->env_proxy; | ||
| 430 | |||
| 431 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 432 | if ($response->is_success) { | ||
| 433 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 434 | } | ||
| 435 | |||
| 436 | } | ||
| 437 | return 0; | ||
| 438 | } | ||
| 439 | |||
| 440 | =head2 list(access_token); | ||
| 441 | |||
| 442 | 获取标签列表 | ||
| 443 | 最后更新:2018/03/13 | ||
| 444 | |||
| 445 | =head2 SYNOPSIS | ||
| 446 | |||
| 447 | L<https://developer.work.weixin.qq.com/document/path/90216> | ||
| 448 | |||
| 449 | =head3 请求说明: | ||
| 450 | |||
| 451 | =head4 参数说明: | ||
| 452 | |||
| 453 | 参数 必须 说明 | ||
| 454 | access_token 是 调用接口凭证 | ||
| 455 | |||
| 456 | =head4 权限说明: | ||
| 457 | |||
| 458 | 自建应用或通讯同步助手可以获取所有标签列表;第三方应用仅可获取自己创建的标签。 | ||
| 459 | |||
| 460 | =head3 RETURN 返回结果 | ||
| 461 | |||
| 462 | { | ||
| 463 | "errcode": 0, | ||
| 464 | "errmsg": "ok", | ||
| 465 | "taglist":[ | ||
| 466 | {"tagid":1,"tagname":"a"}, | ||
| 467 | {"tagid":2,"tagname":"b"} | ||
| 468 | ] | ||
| 469 | } | ||
| 470 | |||
| 471 | =head4 RETURN 参数说明 | ||
| 472 | 参数 说明 | ||
| 473 | errcode 返回码 | ||
| 474 | errmsg 对返回码的文本描述内容 | ||
| 475 | taglist 标签列表 | ||
| 476 | tagid 标签id | ||
| 477 | tagname 标签名 | ||
| 478 | |||
| 479 | =cut | ||
| 480 | |||
| 481 | sub list { | ||
| 482 | if ( @_ && $_[0] ) { | ||
| 483 | my $access_token = $_[0]; | ||
| 484 | my $ua = LWP::UserAgent->new; | ||
| 485 | $ua->timeout(30); | ||
| 486 | $ua->env_proxy; | ||
| 487 | |||
| 488 | my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/tag/list?access_token=$access_token"); | ||
| 489 | if ($response->is_success) { | ||
| 490 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 491 | } | ||
| 492 | |||
| 493 | } | ||
| 494 | return 0; | ||
| 495 | } | ||
| 496 | |||
| 497 | |||
| 498 | 1; | ||
| 499 | __END__ |