| 1 | package QQ::weixin::work::externalcontact::moment_strategy; | ||
| 2 | |||
| 3 | =encoding utf8 | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | QQ::weixin::work::externalcontact::moment_strategy | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | 客户朋友圈规则组管理 | ||
| 12 | 最后更新:2023/12/01 | ||
| 13 | |||
| 14 | =head2 SYNOPSIS | ||
| 15 | |||
| 16 | L<https://developer.work.weixin.qq.com/document/path/94890> | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | use strict; | ||
| 21 | use base qw(QQ::weixin::work::externalcontact); | ||
| 22 | use Encode; | ||
| 23 | use LWP::UserAgent; | ||
| 24 | use JSON; | ||
| 25 | use utf8; | ||
| 26 | |||
| 27 | our $VERSION = '0.10'; | ||
| 28 | our @EXPORT = qw/ list get get_range create edit del /; | ||
| 29 | |||
| 30 | =head1 FUNCTION | ||
| 31 | |||
| 32 | =head2 权限说明 | ||
| 33 | |||
| 34 | 调用客户朋友圈规则组相关接口的应用需要满足如下的权限: | ||
| 35 | |||
| 36 | 应用类型 权限要求 | ||
| 37 | 自建应用 配置到「客户联系 可调用接口的应用」中 | ||
| 38 | 代开发应用 具有「管理客户朋友圈规则组」权限 | ||
| 39 | 第三方应用 具有「管理客户朋友圈规则组」权限 | ||
| 40 | |||
| 41 | 提示 | ||
| 42 | 应用仅能获取和管理由本应用创建的规则组 | ||
| 43 | |||
| 44 | 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情 | ||
| 45 | |||
| 46 | =head2 list(access_token, hash); | ||
| 47 | |||
| 48 | 获取规则组列表 | ||
| 49 | |||
| 50 | =head2 SYNOPSIS | ||
| 51 | |||
| 52 | L<https://developer.work.weixin.qq.com/document/path/94890#获取规则组列表> | ||
| 53 | |||
| 54 | =head3 请求说明: | ||
| 55 | |||
| 56 | 企业可通过此接口获取企业配置的所有客户朋友圈规则组id列表。 | ||
| 57 | |||
| 58 | =head4 请求包结构体为: | ||
| 59 | |||
| 60 | { | ||
| 61 | "cursor":"CURSOR", | ||
| 62 | "limit":1000 | ||
| 63 | } | ||
| 64 | |||
| 65 | =head4 参数说明: | ||
| 66 | |||
| 67 | 参数 必须 说明 | ||
| 68 | access_token 是 调用接口凭证 | ||
| 69 | cursor 否 分页查询游标,首次调用可不填 | ||
| 70 | limit 否 分页大小,默认为1000,最大不超过1000 | ||
| 71 | |||
| 72 | =head3 RETURN 返回结果: | ||
| 73 | |||
| 74 | { | ||
| 75 | "errcode": 0, | ||
| 76 | "errmsg": "ok", | ||
| 77 | "strategy": | ||
| 78 | [ | ||
| 79 | { | ||
| 80 | "strategy_id":1 | ||
| 81 | }, | ||
| 82 | { | ||
| 83 | "strategy_id":2 | ||
| 84 | } | ||
| 85 | ], | ||
| 86 | "next_cursor":"NEXT_CURSOR" | ||
| 87 | } | ||
| 88 | |||
| 89 | =head4 RETURN 参数说明: | ||
| 90 | |||
| 91 | 参数 说明 | ||
| 92 | errcode 返回码 | ||
| 93 | errmsg 对返回码的文本描述内容 | ||
| 94 | strategy_id 规则组id | ||
| 95 | next_cursor 分页游标,用于查询下一个分页的数据,无更多数据时不返回 | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | sub list { | ||
| 100 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 101 | my $access_token = $_[0]; | ||
| 102 | my $json = $_[1]; | ||
| 103 | my $ua = LWP::UserAgent->new; | ||
| 104 | $ua->timeout(30); | ||
| 105 | $ua->env_proxy; | ||
| 106 | |||
| 107 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/moment_strategy/list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 108 | if ($response->is_success) { | ||
| 109 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 110 | } | ||
| 111 | |||
| 112 | } | ||
| 113 | return 0; | ||
| 114 | } | ||
| 115 | |||
| 116 | =head2 get(access_token, hash); | ||
| 117 | |||
| 118 | 获取规则组详情 | ||
| 119 | |||
| 120 | =head2 SYNOPSIS | ||
| 121 | |||
| 122 | L<https://developer.work.weixin.qq.com/document/path/94890#获取规则组详情> | ||
| 123 | |||
| 124 | =head3 请求说明: | ||
| 125 | |||
| 126 | 企业可以通过此接口获取某个客户朋友圈规则组的详细信息。 | ||
| 127 | |||
| 128 | =head4 请求包结构体为: | ||
| 129 | |||
| 130 | { | ||
| 131 | "strategy_id":1 | ||
| 132 | } | ||
| 133 | |||
| 134 | =head4 参数说明: | ||
| 135 | |||
| 136 | 参数 必须 说明 | ||
| 137 | access_token 是 调用接口凭证 | ||
| 138 | strategy_id 是 规则组id | ||
| 139 | |||
| 140 | =head3 RETURN 返回结果: | ||
| 141 | |||
| 142 | { | ||
| 143 | "errcode": 0, | ||
| 144 | "errmsg": "ok", | ||
| 145 | "strategy": { | ||
| 146 | "strategy_id":1, | ||
| 147 | "parent_id":0, | ||
| 148 | "strategy_name": "NAME", | ||
| 149 | "create_time": 1557838797, | ||
| 150 | "admin_list":[ | ||
| 151 | "zhangsan", | ||
| 152 | "lisi" | ||
| 153 | ], | ||
| 154 | "privilege": | ||
| 155 | { | ||
| 156 | "view_moment_list":true, | ||
| 157 | "send_moment":true, | ||
| 158 | "manage_moment_cover_and_sign":true | ||
| 159 | } | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | =head4 RETURN 参数说明: | ||
| 164 | |||
| 165 | 参数 说明 | ||
| 166 | errcode 返回码 | ||
| 167 | errmsg 对返回码的文本描述内容 | ||
| 168 | strategy_id 规则组id | ||
| 169 | parent_id 父规则组id, 如果当前规则组没父规则组,则为0 | ||
| 170 | strategy_name 规则组名称 | ||
| 171 | create_time 规则组创建时间戳 | ||
| 172 | admin_list 规则组管理员userid列表 | ||
| 173 | privilege.view_moment_list 允许查看成员的全部客户朋友圈发表 | ||
| 174 | privilege.send_moment 允许成员发表客户朋友圈,默认为true | ||
| 175 | privilege.manage_moment_cover_and_sign 配置封面和签名,默认为true | ||
| 176 | |||
| 177 | 如果规则组具有父规则组则其管理范围必须是父规则组的子集。 | ||
| 178 | |||
| 179 | =cut | ||
| 180 | |||
| 181 | sub get { | ||
| 182 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 183 | my $access_token = $_[0]; | ||
| 184 | my $json = $_[1]; | ||
| 185 | my $ua = LWP::UserAgent->new; | ||
| 186 | $ua->timeout(30); | ||
| 187 | $ua->env_proxy; | ||
| 188 | |||
| 189 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/moment_strategy/get?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 190 | if ($response->is_success) { | ||
| 191 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 192 | } | ||
| 193 | |||
| 194 | } | ||
| 195 | return 0; | ||
| 196 | } | ||
| 197 | |||
| 198 | =head2 get_range(access_token, hash); | ||
| 199 | |||
| 200 | 获取规则组管理范围 | ||
| 201 | |||
| 202 | =head2 SYNOPSIS | ||
| 203 | |||
| 204 | L<https://developer.work.weixin.qq.com/document/path/94890#获取规则组管理范围> | ||
| 205 | |||
| 206 | =head3 请求说明: | ||
| 207 | |||
| 208 | 企业可通过此接口获取某个朋友圈规则组管理的成员和部门列表 | ||
| 209 | |||
| 210 | =head4 请求包结构体为: | ||
| 211 | |||
| 212 | { | ||
| 213 | "strategy_id":1, | ||
| 214 | "cursor":"CURSOR", | ||
| 215 | "limit":1000 | ||
| 216 | } | ||
| 217 | |||
| 218 | =head4 参数说明: | ||
| 219 | |||
| 220 | 参数 必须 说明 | ||
| 221 | access_token 是 调用接口凭证 | ||
| 222 | strategy_id 是 规则组id | ||
| 223 | cursor 否 分页游标 | ||
| 224 | limit 否 每个分页的成员/部门节点数,默认为1000,最大为1000 | ||
| 225 | |||
| 226 | =head3 RETURN 返回结果: | ||
| 227 | |||
| 228 | { | ||
| 229 | "errcode": 0, | ||
| 230 | "errmsg": "ok", | ||
| 231 | "range": | ||
| 232 | [ | ||
| 233 | { | ||
| 234 | "type":1, | ||
| 235 | "userid":"zhangsan" | ||
| 236 | }, | ||
| 237 | { | ||
| 238 | "type":2, | ||
| 239 | "partyid":1 | ||
| 240 | } | ||
| 241 | ], | ||
| 242 | "next_cursor":"NEXT_CURSOR" | ||
| 243 | } | ||
| 244 | |||
| 245 | =head4 RETURN 参数说明: | ||
| 246 | |||
| 247 | 参数 说明 | ||
| 248 | errcode 返回码 | ||
| 249 | errmsg 对返回码的文本描述内容 | ||
| 250 | range.type 节点类型,1-成员 2-部门 | ||
| 251 | range.userid 管理范围内配置的成员userid,仅type为1时返回 | ||
| 252 | item.partyid 管理范围内配置的部门partyid,仅type为2时返回 | ||
| 253 | next_cursor 分页游标,用于查询下一个分页的数据,无更多数据时不返回 | ||
| 254 | |||
| 255 | =cut | ||
| 256 | |||
| 257 | sub get_range { | ||
| 258 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 259 | my $access_token = $_[0]; | ||
| 260 | my $json = $_[1]; | ||
| 261 | my $ua = LWP::UserAgent->new; | ||
| 262 | $ua->timeout(30); | ||
| 263 | $ua->env_proxy; | ||
| 264 | |||
| 265 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/moment_strategy/get_range?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 266 | if ($response->is_success) { | ||
| 267 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 268 | } | ||
| 269 | |||
| 270 | } | ||
| 271 | return 0; | ||
| 272 | } | ||
| 273 | |||
| 274 | =head2 create(access_token, hash); | ||
| 275 | |||
| 276 | 创建新的规则组 | ||
| 277 | |||
| 278 | =head2 SYNOPSIS | ||
| 279 | |||
| 280 | L<https://developer.work.weixin.qq.com/document/path/94890#创建新的规则组> | ||
| 281 | |||
| 282 | =head3 请求说明: | ||
| 283 | |||
| 284 | 企业可通过此接口创建一个新的客户朋友圈规则组。该接口仅支持串行调用,请勿并发创建规则组。 | ||
| 285 | |||
| 286 | =head4 请求包结构体为: | ||
| 287 | |||
| 288 | { | ||
| 289 | "parent_id":0, | ||
| 290 | "strategy_name": "NAME", | ||
| 291 | "admin_list":[ | ||
| 292 | "zhangsan", | ||
| 293 | "lisi" | ||
| 294 | ], | ||
| 295 | "privilege" | ||
| 296 | { | ||
| 297 | "send_moment":true, | ||
| 298 | "view_moment_list":true, | ||
| 299 | "manage_moment_cover_and_sign":true | ||
| 300 | }, | ||
| 301 | "range": | ||
| 302 | [ | ||
| 303 | { | ||
| 304 | "type":1, | ||
| 305 | "userid":"zhangsan" | ||
| 306 | }, | ||
| 307 | { | ||
| 308 | "type":2, | ||
| 309 | "partyid":1 | ||
| 310 | } | ||
| 311 | ] | ||
| 312 | } | ||
| 313 | |||
| 314 | =head4 参数说明: | ||
| 315 | |||
| 316 | 参数 必须 说明 | ||
| 317 | access_token 是 调用接口凭证 | ||
| 318 | parent_id 否 父规则组id | ||
| 319 | strategy_name 是 规则组名称 | ||
| 320 | admin_list 是 规则组管理员userid列表,不可配置超级管理员,每个规则组最多可配置20个负责人 | ||
| 321 | privilege.view_moment_list 否 允许查看成员的全部客户朋友圈发表,默认为true | ||
| 322 | privilege.send_moment 否 允许成员发表客户朋友圈,默认为true | ||
| 323 | privilege.manage_moment_cover_and_sign 否 配置封面和签名,默认为true | ||
| 324 | range.type 是 规则组管理范围节点类型,1-成员 2-部门 | ||
| 325 | range.userid 否 规则组的管理成员id | ||
| 326 | range.partyid 否 规则组的管理部门id | ||
| 327 | |||
| 328 | 如果要创建的规则组具有父规则组,则其管理范围必须是父规则组的子集,且将完全继承父规则组的权限配置(privilege将被忽略) | ||
| 329 | 管理组的最大层级为5层 | ||
| 330 | 每个管理组的管理范围内最多支持3000个节点 | ||
| 331 | |||
| 332 | =head3 RETURN 返回结果: | ||
| 333 | |||
| 334 | { | ||
| 335 | "errcode": 0, | ||
| 336 | "errmsg": "ok", | ||
| 337 | "strategy_id":1 | ||
| 338 | } | ||
| 339 | |||
| 340 | =head4 RETURN 参数说明: | ||
| 341 | |||
| 342 | 参数 说明 | ||
| 343 | errcode 返回码 | ||
| 344 | errmsg 对返回码的文本描述内容 | ||
| 345 | strategy_id 规则组id | ||
| 346 | |||
| 347 | =cut | ||
| 348 | |||
| 349 | sub create { | ||
| 350 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 351 | my $access_token = $_[0]; | ||
| 352 | my $json = $_[1]; | ||
| 353 | my $ua = LWP::UserAgent->new; | ||
| 354 | $ua->timeout(30); | ||
| 355 | $ua->env_proxy; | ||
| 356 | |||
| 357 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/moment_strategy/create?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 358 | if ($response->is_success) { | ||
| 359 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 360 | } | ||
| 361 | |||
| 362 | } | ||
| 363 | return 0; | ||
| 364 | } | ||
| 365 | |||
| 366 | =head2 edit(access_token, hash); | ||
| 367 | |||
| 368 | 编辑规则组及其管理范围 | ||
| 369 | |||
| 370 | =head2 SYNOPSIS | ||
| 371 | |||
| 372 | L<https://developer.work.weixin.qq.com/document/path/94890#编辑规则组及其管理范围> | ||
| 373 | |||
| 374 | =head3 请求说明: | ||
| 375 | |||
| 376 | 企业可通过此接口编辑规则组的基本信息和修改客户朋友圈规则组管理范围。该接口仅支持串行调用,请勿并发修改规则组。 | ||
| 377 | |||
| 378 | =head4 请求包结构体为: | ||
| 379 | |||
| 380 | { | ||
| 381 | "strategy_id":1, | ||
| 382 | "strategy_name": "NAME", | ||
| 383 | "admin_list":[ | ||
| 384 | "zhangsan", | ||
| 385 | "lisi" | ||
| 386 | ], | ||
| 387 | "privilege": | ||
| 388 | { | ||
| 389 | "view_moment_list":true, | ||
| 390 | "send_moment":true, | ||
| 391 | "manage_moment_cover_and_sign":true | ||
| 392 | }, | ||
| 393 | "range_add": | ||
| 394 | [ | ||
| 395 | { | ||
| 396 | "type":1, | ||
| 397 | "userid":"zhangsan" | ||
| 398 | }, | ||
| 399 | { | ||
| 400 | "type":2, | ||
| 401 | "partyid":1 | ||
| 402 | } | ||
| 403 | ], | ||
| 404 | "range_del": | ||
| 405 | [ | ||
| 406 | { | ||
| 407 | "type":1, | ||
| 408 | "userid":"lisi" | ||
| 409 | }, | ||
| 410 | { | ||
| 411 | "type":2, | ||
| 412 | "partyid":2 | ||
| 413 | } | ||
| 414 | ] | ||
| 415 | } | ||
| 416 | |||
| 417 | =head4 参数说明: | ||
| 418 | |||
| 419 | 参数 必须 说明 | ||
| 420 | access_token 是 调用接口凭证 | ||
| 421 | strategy_id 是 规则组id | ||
| 422 | strategy_name 否 规则组名称 | ||
| 423 | admin_list 否 管理员列表,如果为空则不对负责人做编辑,如果有则覆盖旧的负责人列表 | ||
| 424 | privilege 否 权限配置,如果为空则不对权限做编辑,如果有则覆盖旧的权限配置 | ||
| 425 | range_add.type 否 向管理范围添加的节点类型 1-成员 2-部门 | ||
| 426 | range_add.userid 否 向管理范围添加成员的userid,仅type为1时有效 | ||
| 427 | range_add.partyid 否 向管理范围添加部门的partyid,仅type为2时有效 | ||
| 428 | range_del.type 否 从管理范围删除的节点类型 1-成员 2-部门 | ||
| 429 | range_del.userid 否 从管理范围删除的成员的userid,仅type为1时有效 | ||
| 430 | range_del.partyid 否 从管理范围删除的部门的partyid,仅type为2时有效 | ||
| 431 | |||
| 432 | 如果规则组具有父规则组,则其管理范围必须是父规则组的子集,且将完全继承父规则组的权限配置(privilege将被忽略) | ||
| 433 | 每个管理组的管理范围内最多支持3000个节点 | ||
| 434 | |||
| 435 | =head3 RETURN 返回结果: | ||
| 436 | |||
| 437 | { | ||
| 438 | "errcode": 0, | ||
| 439 | "errmsg": "ok" | ||
| 440 | } | ||
| 441 | |||
| 442 | =head4 RETURN 参数说明: | ||
| 443 | |||
| 444 | 参数 说明 | ||
| 445 | errcode 返回码 | ||
| 446 | errmsg 对返回码的文本描述内容 | ||
| 447 | |||
| 448 | =cut | ||
| 449 | |||
| 450 | sub edit { | ||
| 451 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 452 | my $access_token = $_[0]; | ||
| 453 | my $json = $_[1]; | ||
| 454 | my $ua = LWP::UserAgent->new; | ||
| 455 | $ua->timeout(30); | ||
| 456 | $ua->env_proxy; | ||
| 457 | |||
| 458 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/moment_strategy/edit?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 459 | if ($response->is_success) { | ||
| 460 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 461 | } | ||
| 462 | |||
| 463 | } | ||
| 464 | return 0; | ||
| 465 | } | ||
| 466 | |||
| 467 | =head2 del(access_token, hash); | ||
| 468 | |||
| 469 | 删除规则组 | ||
| 470 | |||
| 471 | =head2 SYNOPSIS | ||
| 472 | |||
| 473 | L<https://developer.work.weixin.qq.com/document/path/94890#删除规则组> | ||
| 474 | |||
| 475 | =head3 请求说明: | ||
| 476 | |||
| 477 | 企业可通过此接口删除某个客户朋友圈规则组。 | ||
| 478 | |||
| 479 | =head4 请求包结构体为: | ||
| 480 | |||
| 481 | { | ||
| 482 | "strategy_id":1 | ||
| 483 | } | ||
| 484 | |||
| 485 | =head4 参数说明: | ||
| 486 | |||
| 487 | 参数 必须 说明 | ||
| 488 | access_token 是 调用接口凭证 | ||
| 489 | strategy_id 是 规则组id | ||
| 490 | |||
| 491 | =head3 RETURN 返回结果: | ||
| 492 | |||
| 493 | { | ||
| 494 | "errcode": 0, | ||
| 495 | "errmsg": "ok" | ||
| 496 | } | ||
| 497 | |||
| 498 | =head4 RETURN 参数说明: | ||
| 499 | |||
| 500 | 参数 说明 | ||
| 501 | errcode 返回码 | ||
| 502 | errmsg 对返回码的文本描述内容 | ||
| 503 | |||
| 504 | =cut | ||
| 505 | |||
| 506 | sub del { | ||
| 507 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 508 | my $access_token = $_[0]; | ||
| 509 | my $json = $_[1]; | ||
| 510 | my $ua = LWP::UserAgent->new; | ||
| 511 | $ua->timeout(30); | ||
| 512 | $ua->env_proxy; | ||
| 513 | |||
| 514 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/moment_strategy/del?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 515 | if ($response->is_success) { | ||
| 516 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 517 | } | ||
| 518 | |||
| 519 | } | ||
| 520 | return 0; | ||
| 521 | } | ||
| 522 | |||
| 523 | 1; | ||
| 524 | __END__ |