work/externalcontact/resigned.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 77 CC 5 SCAR 19.5
CC
5
Cov
0%
transfer_customer
12.0
transfer_result
12.0
BEGIN
2.0
CRAP 7.0
1 package QQ::weixin::work::externalcontact::resigned;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::externalcontact::resigned
8
9 =head1 DESCRIPTION
10
11 客户联系->离职继承
12
13 =cut
14
15 use strict;
16 use base qw(QQ::weixin::work::externalcontact);
17 use Encode;
18 use LWP::UserAgent;
19 use JSON;
20 use utf8;
21
22 our $VERSION = '0.10';
23 our @EXPORT = qw/ transfer_customer transfer_result /;
24
25 =head1 FUNCTION
26
27 =head2 transfer_customer(access_token, hash);
28
29 分配离职成员的客户
30 最后更新:2023/12/01
31
32 =head2 SYNOPSIS
33
34 L<https://developer.work.weixin.qq.com/document/path/94081>
35
36 =head3 请求说明:
37
38 企业可通过此接口,分配离职成员的客户给其他成员。
39
40 =head4 请求包结构体为:
41
42 {
43 "handover_userid": "zhangsan",
44 "takeover_userid": "lisi",
45 "external_userid":
46 [
47 "woAJ2GCAAAXtWyujaWJHDDGi0mACBBBB",
48 "woAJ2GCAAAXtWyujaWJHDDGi0mACAAAA"
49 ]
50 }
51
52 =head4 参数说明:
53
54 参数 必须 说明
55 access_token 是 调用接口凭证
56 handover_userid 是 原跟进成员的userid
57 takeover_userid 是 接替成员的userid
58 external_userid 是 客户的external_userid列表,最多一次转移100个客户
59
60 提示
61 原跟进成员离职时间不能超过1年且离职前一年内至少登录过一次企业微信; 接替成员最近一年内至少登陆过一次企业微信。
62
63 handover_userid必须是已离职用户。
64 external_userid必须是handover_userid的客户(即配置了客户联系功能的成员所添加的联系人)。
65
66 =head4 权限说明:
67
68 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
69 第三方应用需拥有“企业客户权限->客户联系->离职分配”权限
70 接替成员必须在此第三方应用或自建应用的可见范围内。
71 接替成员需要配置了客户联系功能。
72 接替成员需要在企业微信激活且已经过实名认证。
73
74 =head3 RETURN 返回结果:
75
76 {
77 "errcode": 0,
78 "errmsg": "ok",
79 "customer":
80 [
81 {
82 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACBBBB",
83 "errcode":0
84 },
85 {
86 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACAAAA",
87 "errcode":40096
88 }
89 ]
90 }
91
92 =head4 RETURN 参数说明:
93
94 参数 说明
95 errcode 返回码
96 errmsg 对返回码的文本描述内容
97 customer.external_userid 客户的external_userid
98 customer.errcode 对此客户进行分配的结果, 具体可参考全局错误码, 0表示开始分配流程,待24小时后自动接替,并不代表最终分配成功
99
100 原接口分配在职或离职成员的客户后续将不再更新维护,请使用新接口
101
102 =cut
103
104 sub transfer_customer {
105 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
106 my $access_token = $_[0];
107 my $json = $_[1];
108 my $ua = LWP::UserAgent->new;
109 $ua->timeout(30);
110 $ua->env_proxy;
111
112 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/resigned/transfer_customer?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
113 if ($response->is_success) {
114 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
115 }
116
117 }
118 return 0;
119 }
120
121 =head2 transfer_result(access_token, hash);
122
123 查询客户接替状态
124 最后更新:2021/03/24
125
126 =head2 SYNOPSIS
127
128 L<https://developer.work.weixin.qq.com/document/path/94082>
129
130 =head3 请求说明:
131
132 企业和第三方可通过此接口查询离职成员的客户分配情况。
133
134 =head4 请求包结构体为:
135
136 {
137 "handover_userid": "zhangsan",
138 "takeover_userid": "lisi",
139 "cursor":"CURSOR"
140 }
141
142 =head4 参数说明:
143
144 参数 必须 说明
145 access_token 是 调用接口凭证
146 handover_userid 是 原添加成员的userid
147 takeover_userid 是 接替成员的userid
148 cursor 否 分页查询的cursor,每个分页返回的数据不会超过1000条;不填或为空表示获取第一个分页
149
150 =head4 权限说明:
151
152 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
153 第三方应用需拥有“企业客户权限->客户联系->在职继承”权限
154 接替成员必须在此第三方应用或自建应用的可见范围内。
155
156 =head3 RETURN 返回结果:
157
158 {
159 "errcode": 0,
160 "errmsg": "ok",
161 "customer":
162 [
163 {
164 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACCCC",
165 "status":1,
166 "takeover_time":1588262400
167 },
168 {
169 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACBBBB",
170 "status":2,
171 "takeover_time":1588482400
172 },
173 {
174 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACAAAA",
175 "status":3,
176 "takeover_time":0
177 }
178 ],
179 "next_cursor":"NEXT_CURSOR"
180 }
181
182 =head4 RETURN 参数说明:
183
184 参数 说明
185 errcode 返回码
186 errmsg 对返回码的文本描述内容
187 customer.external_userid 转接客户的外部联系人userid
188 customer.status 接替状态, 1-接替完毕 2-等待接替 3-客户拒绝 4-接替成员客户达到上限
189 customer.takeover_time 接替客户的时间,如果是等待接替状态,则为未来的自动接替时间
190 next_cursor 下个分页的起始cursor
191
192 原接口查询客户接替结果后续将不再更新维护,请使用新接口
193
194 =cut
195
196 sub transfer_result {
197 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
198 my $access_token = $_[0];
199 my $json = $_[1];
200 my $ua = LWP::UserAgent->new;
201 $ua->timeout(30);
202 $ua->env_proxy;
203
204 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/resigned/transfer_result?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
205 if ($response->is_success) {
206 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
207 }
208
209 }
210 return 0;
211 }
212
213
214 1;
215 __END__