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