| 1 | package QQ::exmail::user; | ||
| 2 | |||
| 3 | =encoding utf8 | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | QQ::exmail::user | ||
| 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 simplelist list batchcheck /; | ||
| 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#10014> | ||
| 34 | |||
| 35 | =head3 请求说明: | ||
| 36 | |||
| 37 | =head4 请求包结构体为: | ||
| 38 | |||
| 39 | { | ||
| 40 | "userid": "zhangsan@gzdev.com", | ||
| 41 | "name": "张三", | ||
| 42 | "department": [1, 2], | ||
| 43 | "position": "产品经理", | ||
| 44 | "mobile": "15913215XXX", | ||
| 45 | "tel": "123456", | ||
| 46 | "extid": "01", | ||
| 47 | "gender": "1", | ||
| 48 | "slaves": ["zhangsan@gz.com", "zhangsan@bjdev.com"], | ||
| 49 | "password":"******", | ||
| 50 | "cpwd_login":0 | ||
| 51 | } | ||
| 52 | |||
| 53 | =head4 参数说明: | ||
| 54 | |||
| 55 | 参数 必须 说明 | ||
| 56 | access_token 是 调用接口凭证 | ||
| 57 | userid 是 成员UserID。企业邮帐号名,邮箱格式 | ||
| 58 | name 是 成员名称。长度为1~64个字节 | ||
| 59 | department 是 成员所属部门id列表,不超过20个 | ||
| 60 | position 否 职位信息。长度为0~64个字节 | ||
| 61 | mobile 否 手机号码 | ||
| 62 | tel 否 座机号码 | ||
| 63 | extid 否 编号 | ||
| 64 | gender 否 性别。1表示男性,2表示女性 | ||
| 65 | slaves 否 别名列表 | ||
| 66 | 1.Slaves 上限为5个 | ||
| 67 | 2.Slaves 为邮箱格式 | ||
| 68 | password 是 英文和数字 | ||
| 69 | cpwd_login 否 用户重新登录时是否重设密码, 登陆重设密码后,该标志位还原。0表示否,1表示是,缺省为0 | ||
| 70 | |||
| 71 | =head3 权限说明 | ||
| 72 | |||
| 73 | 系统应用须拥有指定部门的管理权限。 | ||
| 74 | |||
| 75 | =head3 RETURN 返回结果 | ||
| 76 | |||
| 77 | { | ||
| 78 | "errcode": 0, | ||
| 79 | "errmsg": "created" | ||
| 80 | } | ||
| 81 | |||
| 82 | =head3 RETURN 参数说明 | ||
| 83 | |||
| 84 | 参数 说明 | ||
| 85 | errcode 返回码 | ||
| 86 | errmsg 对返回码的文本描述内容 | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | sub create { | ||
| 91 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 92 | my $access_token = $_[0]; | ||
| 93 | my $json = $_[1]; | ||
| 94 | my $ua = LWP::UserAgent->new; | ||
| 95 | $ua->timeout(30); | ||
| 96 | $ua->env_proxy; | ||
| 97 | |||
| 98 | my $response = $ua->post("https://api.exmail.qq.com/cgi-bin/user/create?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 99 | if ($response->is_success) { | ||
| 100 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 101 | } | ||
| 102 | |||
| 103 | } | ||
| 104 | return 0; | ||
| 105 | } | ||
| 106 | |||
| 107 | =head2 update(access_token, hash); | ||
| 108 | |||
| 109 | 更新成员 | ||
| 110 | |||
| 111 | =head2 SYNOPSIS | ||
| 112 | |||
| 113 | L<https://exmail.qq.com/qy_mng_logic/doc#10015> | ||
| 114 | |||
| 115 | =head3 请求说明: | ||
| 116 | |||
| 117 | =head4 请求包示例如下(如果非必须的字段未指定,则不更新该字段之前的设置值): | ||
| 118 | |||
| 119 | { | ||
| 120 | "userid": " zhangsan@gzdev.com ", | ||
| 121 | "name": "张三", | ||
| 122 | "department": [1, 2], | ||
| 123 | "position": "产品经理", | ||
| 124 | "mobile": "15913215421", | ||
| 125 | "gender": "1", | ||
| 126 | "enable": 1, | ||
| 127 | "password":"******", | ||
| 128 | "cpwd_login":1 | ||
| 129 | } | ||
| 130 | |||
| 131 | =head4 参数说明: | ||
| 132 | |||
| 133 | 参数 必须 说明 | ||
| 134 | access_token 是 调用接口凭证 | ||
| 135 | userid 是 成员UserID。企业邮帐号名,邮箱格式 | ||
| 136 | name 否 成员名称。长度为0~64个字节 | ||
| 137 | department 否 成员所属部门id列表,不超过20个 | ||
| 138 | position 否 职位信息。长度为0~64个字节 | ||
| 139 | mobile 否 手机号码 | ||
| 140 | tel 否 座机号码 | ||
| 141 | extid 否 编号 | ||
| 142 | gender 否 性别。1表示男性,2表示女性 | ||
| 143 | slaves 否 别名列表 | ||
| 144 | 1.Slaves 上限为5个 | ||
| 145 | 2.Slaves 为邮箱格式 | ||
| 146 | enable 否 启用/禁用成员。1表示启用成员,0表示禁用成员 | ||
| 147 | password 否 密码 | ||
| 148 | cpwd_login 否 用户重新登录时是否重设密码, 登陆重设密码后,该标志位还原。0表示否,1表示是,缺省为0 | ||
| 149 | |||
| 150 | =head3 权限说明 | ||
| 151 | |||
| 152 | 系统应用须拥有指定部门、成员的管理权限。 | ||
| 153 | |||
| 154 | =head3 RETURN 返回结果 | ||
| 155 | |||
| 156 | { | ||
| 157 | "errcode": 0, | ||
| 158 | "errmsg": "updated" | ||
| 159 | } | ||
| 160 | |||
| 161 | =head3 RETURN 参数说明 | ||
| 162 | |||
| 163 | 参数 说明 | ||
| 164 | errcode 返回码 | ||
| 165 | errmsg 对返回码的文本描述内容 | ||
| 166 | |||
| 167 | =cut | ||
| 168 | |||
| 169 | sub update { | ||
| 170 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 171 | my $access_token = $_[0]; | ||
| 172 | my $json = $_[1]; | ||
| 173 | my $ua = LWP::UserAgent->new; | ||
| 174 | $ua->timeout(30); | ||
| 175 | $ua->env_proxy; | ||
| 176 | |||
| 177 | my $response = $ua->post("https://api.exmail.qq.com/cgi-bin/user/update?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 178 | if ($response->is_success) { | ||
| 179 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 180 | } | ||
| 181 | |||
| 182 | } | ||
| 183 | return 0; | ||
| 184 | } | ||
| 185 | |||
| 186 | =head2 delete(access_token, userid); | ||
| 187 | |||
| 188 | 删除成员 | ||
| 189 | |||
| 190 | =head2 SYNOPSIS | ||
| 191 | |||
| 192 | L<https://exmail.qq.com/qy_mng_logic/doc#10016> | ||
| 193 | |||
| 194 | =head3 请求说明: | ||
| 195 | |||
| 196 | =head4 参数说明: | ||
| 197 | |||
| 198 | 参数 必须 说明 | ||
| 199 | access_token 是 调用接口凭证 | ||
| 200 | userid 是 成员UserID。企业邮帐号名,邮箱格式 | ||
| 201 | |||
| 202 | =head3 权限说明 | ||
| 203 | |||
| 204 | 系统应用须拥有指定成员的管理权限。 | ||
| 205 | |||
| 206 | =head3 RETURN 返回结果 | ||
| 207 | |||
| 208 | { | ||
| 209 | "errcode": 0, | ||
| 210 | "errmsg": "deleted" | ||
| 211 | } | ||
| 212 | |||
| 213 | =head4 RETURN 参数说明 | ||
| 214 | |||
| 215 | 参数 说明 | ||
| 216 | errcode 返回码 | ||
| 217 | errmsg 对返回码的文本描述内容 | ||
| 218 | |||
| 219 | =cut | ||
| 220 | |||
| 221 | sub delete { | ||
| 222 | if ( @_ && $_[0] && $_[1] ) { | ||
| 223 | my $access_token = $_[0]; | ||
| 224 | my $userid = $_[1]; | ||
| 225 | my $ua = LWP::UserAgent->new; | ||
| 226 | $ua->timeout(30); | ||
| 227 | $ua->env_proxy; | ||
| 228 | |||
| 229 | my $response = $ua->get("https://api.exmail.qq.com/cgi-bin/user/delete?access_token=$access_token&userid=$userid"); | ||
| 230 | if ($response->is_success) { | ||
| 231 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 232 | } | ||
| 233 | |||
| 234 | } | ||
| 235 | return 0; | ||
| 236 | } | ||
| 237 | |||
| 238 | =head2 get(access_token, userid); | ||
| 239 | |||
| 240 | 获取成员 | ||
| 241 | |||
| 242 | =head2 SYNOPSIS | ||
| 243 | |||
| 244 | L<https://exmail.qq.com/qy_mng_logic/doc#10017> | ||
| 245 | |||
| 246 | =head3 请求说明: | ||
| 247 | |||
| 248 | =head4 参数说明: | ||
| 249 | |||
| 250 | 参数 必须 说明 | ||
| 251 | access_token 是 调用接口凭证 | ||
| 252 | userid 是 成员UserID | ||
| 253 | |||
| 254 | =head3 权限说明 | ||
| 255 | |||
| 256 | 系统应用须拥有指定成员的查看权限。 | ||
| 257 | |||
| 258 | =head3 RETURN 返回结果 | ||
| 259 | |||
| 260 | { | ||
| 261 | "errcode": 0, | ||
| 262 | "errmsg": "ok", | ||
| 263 | "userid": " zhangsan@gzdev.com ", | ||
| 264 | "name": "李四", | ||
| 265 | "department": [1, 2], | ||
| 266 | "position": "后台工程师", | ||
| 267 | "mobile": "15913215421", | ||
| 268 | "gender": "1", | ||
| 269 | "enable": 1, | ||
| 270 | "slaves":[ zhangsan@gz.com, zhangsan@bjdev.com], | ||
| 271 | "cpwd_login":0 | ||
| 272 | } | ||
| 273 | |||
| 274 | =head4 RETURN 参数说明 | ||
| 275 | |||
| 276 | 参数 说明 | ||
| 277 | errcode 返回码 | ||
| 278 | errmsg 对返回码的文本描述内容 | ||
| 279 | userid 成员UserID | ||
| 280 | name 成员名称 | ||
| 281 | department 成员所属部门id列表 | ||
| 282 | position 职位信息 | ||
| 283 | mobile 手机号码 | ||
| 284 | tel 座机号码 | ||
| 285 | extid 编号 | ||
| 286 | gender 性别。0表示未定义,1表示男性,2表示女性 | ||
| 287 | enable 启用/禁用成员。1表示启用成员,0表示禁用成员 | ||
| 288 | slaves 别名列表 | ||
| 289 | 1、Slaves上限为5个 | ||
| 290 | 2、Slaves为邮箱格式 | ||
| 291 | cpwd_login 用户重新登录时是否重设密码, 登陆重设密码后,该标志位还原。0表示否,1表示是,缺省为0 | ||
| 292 | |||
| 293 | =cut | ||
| 294 | |||
| 295 | sub get { | ||
| 296 | if ( @_ && $_[0] && $_[1] ) { | ||
| 297 | my $access_token = $_[0]; | ||
| 298 | my $userid = $_[1]; | ||
| 299 | my $ua = LWP::UserAgent->new; | ||
| 300 | $ua->timeout(30); | ||
| 301 | $ua->env_proxy; | ||
| 302 | |||
| 303 | my $response = $ua->get("https://api.exmail.qq.com/cgi-bin/user/get?access_token=$access_token&userid=$userid"); | ||
| 304 | if ($response->is_success) { | ||
| 305 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 306 | } | ||
| 307 | |||
| 308 | } | ||
| 309 | return 0; | ||
| 310 | } | ||
| 311 | |||
| 312 | =head2 simplelist(access_token, department_id, fetch_child); | ||
| 313 | |||
| 314 | 获取部门成员 | ||
| 315 | |||
| 316 | =head2 SYNOPSIS | ||
| 317 | |||
| 318 | L<https://exmail.qq.com/qy_mng_logic/doc#10018> | ||
| 319 | |||
| 320 | =head3 请求说明: | ||
| 321 | |||
| 322 | =head4 参数说明: | ||
| 323 | |||
| 324 | 参数 必须 说明 | ||
| 325 | access_token 是 调用接口凭证 | ||
| 326 | department_id 是 获取的部门id。id为1时可获取根部门下的成员 | ||
| 327 | fetch_child 否 1/0:是否递归获取子部门下面的成员 | ||
| 328 | |||
| 329 | =head3 权限说明 | ||
| 330 | |||
| 331 | 系统应用须拥有指定部门的查看权限。 | ||
| 332 | |||
| 333 | =head3 RETURN 返回结果 | ||
| 334 | |||
| 335 | { | ||
| 336 | "errcode": 0, | ||
| 337 | "errmsg": "ok", | ||
| 338 | "userlist": [ | ||
| 339 | { | ||
| 340 | "userid": "zhangsan@gzdev.com", | ||
| 341 | "name": "李四", | ||
| 342 | "t": [1, 2] | ||
| 343 | } | ||
| 344 | ] | ||
| 345 | } | ||
| 346 | |||
| 347 | =head4 RETURN 参数说明 | ||
| 348 | |||
| 349 | 参数 说明 | ||
| 350 | errcode 返回码 | ||
| 351 | errmsg 对返回码的文本描述内容 | ||
| 352 | userlist 成员列表 | ||
| 353 | userid 成员UserID | ||
| 354 | name 成员名称 | ||
| 355 | department 成员所属部门 | ||
| 356 | |||
| 357 | =cut | ||
| 358 | |||
| 359 | sub simplelist { | ||
| 360 | if ( @_ && $_[0] && $_[1] && $_[2] ) { | ||
| 361 | my $access_token = $_[0]; | ||
| 362 | my $department_id = $_[1]; | ||
| 363 | my $fetch_child = $_[2]; | ||
| 364 | my $ua = LWP::UserAgent->new; | ||
| 365 | $ua->timeout(30); | ||
| 366 | $ua->env_proxy; | ||
| 367 | |||
| 368 | my $response = $ua->get("https://api.exmail.qq.com/cgi-bin/user/simplelist?access_token=$access_token&department_id=$department_id&fetch_child=$fetch_child"); | ||
| 369 | if ($response->is_success) { | ||
| 370 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 371 | } | ||
| 372 | |||
| 373 | } | ||
| 374 | return 0; | ||
| 375 | } | ||
| 376 | |||
| 377 | =head2 list(access_token, department_id, fetch_child); | ||
| 378 | |||
| 379 | 获取部门成员(详情) | ||
| 380 | |||
| 381 | =head2 SYNOPSIS | ||
| 382 | |||
| 383 | L<https://exmail.qq.com/qy_mng_logic/doc#10019> | ||
| 384 | |||
| 385 | =head3 请求说明: | ||
| 386 | |||
| 387 | =head4 参数说明: | ||
| 388 | |||
| 389 | 参数 必须 说明 | ||
| 390 | access_token 是 调用接口凭证 | ||
| 391 | department_id 是 获取的部门id。id为1时可获取根部门下的成员 | ||
| 392 | fetch_child 否 1/0:是否递归获取子部门下面的成员 | ||
| 393 | |||
| 394 | =head3 权限说明 | ||
| 395 | |||
| 396 | 系统应用须拥有指定部门的查看权限。 | ||
| 397 | |||
| 398 | =head3 RETURN 返回结果 | ||
| 399 | |||
| 400 | { | ||
| 401 | "errcode": 0, | ||
| 402 | "errmsg": "ok", | ||
| 403 | "userlist": [ | ||
| 404 | { | ||
| 405 | "userid": "zhangsan@gzdev.com", | ||
| 406 | "name": "李四", | ||
| 407 | "department": [1, 2], | ||
| 408 | "position": "后台工程师", | ||
| 409 | "tel": "60000", | ||
| 410 | "mobile": "15913215421", | ||
| 411 | "extid": "123456789", | ||
| 412 | "gender": "1", | ||
| 413 | "enable": "1", | ||
| 414 | "slaves": ["zhangsan@gz.com", "zhangsan@bjdev.com"], | ||
| 415 | "cpwd_login": 0 | ||
| 416 | } | ||
| 417 | ] | ||
| 418 | } | ||
| 419 | |||
| 420 | =head4 RETURN 参数说明 | ||
| 421 | |||
| 422 | 参数 说明 | ||
| 423 | errcode 返回码 | ||
| 424 | errmsg 对返回码的文本描述内容 | ||
| 425 | userlist 成员列表 | ||
| 426 | userid 成员UserID。企业邮帐号名,邮箱格式 | ||
| 427 | name 成员名称 | ||
| 428 | department 成员所属部门id列表 | ||
| 429 | position 职位信息 | ||
| 430 | mobile 手机号码 | ||
| 431 | tel 座机号码 | ||
| 432 | extid 编号 | ||
| 433 | gender 性别。0表示未定义,1表示男性,2表示女性 | ||
| 434 | slaves 别名列表 | ||
| 435 | 1、Slaves上限为5个 | ||
| 436 | 2、Slaves为邮箱格式 | ||
| 437 | cpwd_login 用户重新登录时是否重设密码, 登陆重设密码后,该标志位还原。0表示否,1表示是,缺省为0。 | ||
| 438 | |||
| 439 | =cut | ||
| 440 | |||
| 441 | sub list { | ||
| 442 | if ( @_ && $_[0] && $_[1] && $_[2] ) { | ||
| 443 | my $access_token = $_[0]; | ||
| 444 | my $department_id = $_[1]; | ||
| 445 | my $fetch_child = $_[2]; | ||
| 446 | my $ua = LWP::UserAgent->new; | ||
| 447 | $ua->timeout(30); | ||
| 448 | $ua->env_proxy; | ||
| 449 | |||
| 450 | my $response = $ua->get("https://api.exmail.qq.com/cgi-bin/user/list?access_token=$access_token&department_id=$department_id&fetch_child=$fetch_child"); | ||
| 451 | if ($response->is_success) { | ||
| 452 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 453 | } | ||
| 454 | |||
| 455 | } | ||
| 456 | return 0; | ||
| 457 | } | ||
| 458 | |||
| 459 | =head2 batchcheck(access_token, hash); | ||
| 460 | |||
| 461 | 批量检查账号 | ||
| 462 | |||
| 463 | =head2 SYNOPSIS | ||
| 464 | |||
| 465 | L<https://exmail.qq.com/qy_mng_logic/doc#10020> | ||
| 466 | |||
| 467 | =head3 请求说明: | ||
| 468 | |||
| 469 | =head4 请求包结构体为: | ||
| 470 | |||
| 471 | { | ||
| 472 | "userlist": ["zhangsan@bjdev.com", "zhangsangroup@shdev.com"] | ||
| 473 | } | ||
| 474 | |||
| 475 | =head4 参数说明: | ||
| 476 | |||
| 477 | 参数 必须 说明 | ||
| 478 | access_token 是 调用接口凭证 | ||
| 479 | userlist 是 成员帐号,每次检查不得超过20个 | ||
| 480 | |||
| 481 | =head3 RETURN 返回结果 | ||
| 482 | |||
| 483 | { | ||
| 484 | "errcode": 0, | ||
| 485 | "errmsg": "ok", | ||
| 486 | "list": [ | ||
| 487 | {"user":"zhangsan@bjdev.com", "type":1}, | ||
| 488 | {"user":"zhangsangroup@shdev.com", "type":3} | ||
| 489 | ] | ||
| 490 | } | ||
| 491 | |||
| 492 | =head3 RETURN 参数说明 | ||
| 493 | |||
| 494 | 参数 说明 | ||
| 495 | errcode 返回码 | ||
| 496 | errmsg 对返回码的文本描述内容 | ||
| 497 | list 列表数据 | ||
| 498 | user 成员帐号 | ||
| 499 | type 帐号类型。-1:帐号号无效; 0:帐号名未被占用; 1:主帐号; 2:别名帐号; 3:邮件群组帐号 | ||
| 500 | |||
| 501 | =cut | ||
| 502 | |||
| 503 | sub batchcheck { | ||
| 504 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 505 | my $access_token = $_[0]; | ||
| 506 | my $json = $_[1]; | ||
| 507 | my $ua = LWP::UserAgent->new; | ||
| 508 | $ua->timeout(30); | ||
| 509 | $ua->env_proxy; | ||
| 510 | |||
| 511 | my $response = $ua->post("https://api.exmail.qq.com/cgi-bin/user/batchcheck?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 512 | if ($response->is_success) { | ||
| 513 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 514 | } | ||
| 515 | |||
| 516 | } | ||
| 517 | return 0; | ||
| 518 | } | ||
| 519 | |||
| 520 | |||
| 521 | 1; | ||
| 522 | __END__ |