work/kf/service_state.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%
get
12.0
trans
12.0
BEGIN
2.0
CRAP 7.0
1 package QQ::weixin::work::kf::service_state;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::kf::service_state
8
9 =head1 DESCRIPTION
10
11 微信客服->会话分配与消息收发->分配客服会话
12 最后更新:2023/11/30
13
14 =cut
15
16 use strict;
17 use base qw(QQ::weixin::work::kf);
18 use Encode;
19 use LWP::UserAgent;
20 use JSON;
21 use utf8;
22
23 our $VERSION = '0.10';
24 our @EXPORT = qw/ get trans /;
25
26 =head1 FUNCTION
27
28 =head2 get(access_token, hash);
29
30 获取会话状态
31
32 =head2 SYNOPSIS
33
34 L<https://developer.work.weixin.qq.com/document/path/94669#获取会话状态>
35
36 =head3 请求说明:
37
38 =head4 请求包结构体为:
39
40 {
41 "open_kfid": "wkxxxxxxxxxxxxxxxxxx",
42 "external_userid": "wmxxxxxxxxxxxxxxxxxx"
43 }
44
45 =head4 参数说明:
46
47 参数 必须 类型 说明
48 access_token 是 调用接口凭证
49 open_kfid 是 客服帐号ID
50 external_userid 是 微信客户的external_userid
51
52 =head3 权限说明
53
54 调用的应用需要满足如下的权限
55
56 应用类型 权限要求
57 自建应用 配置到「 微信客服- 可调用接口的应用」中
58 第三方应用 具有“微信客服->管理账号、分配会话和收发消息”权限
59 代开发自建应用 具有“微信客服->管理账号、分配会话和收发消息”权限
60
61 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
62
63 只能通过API管理企业指定的客服账号。企业可在管理后台“微信客服-通过API管理微信客服账号”处设置对应的客服账号通过API来管理。
64 操作的客服账号对应的接待人员应在应用的可见范围内
65
66 =head3 RETURN 返回结果
67
68 {
69 "errcode": 0,
70 "errmsg": "ok",
71 "service_state": 3,
72 "servicer_userid": "zhangsan"
73 }
74
75 =head4 RETURN 参数说明
76
77 参数 类型 说明
78 errcode int 返回码
79 errmsg string 错误码描述
80 service_state int 当前的会话状态,状态定义参考概述中的表格
81 servicer_userid string 接待人员的userid。第三方应用为密文userid,即open_userid。仅当state=3时有效
82
83 =cut
84
85 sub get {
86 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
87 my $access_token = $_[0];
88 my $json = $_[1];
89 my $ua = LWP::UserAgent->new;
90 $ua->timeout(30);
91 $ua->env_proxy;
92
93 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/kf/service_state/get?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
94 if ($response->is_success) {
95 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
96 }
97
98 }
99 return 0;
100 }
101
102 =head2 trans(access_token, hash);
103
104 变更会话状态
105
106 =head2 SYNOPSIS
107
108 L<https://developer.work.weixin.qq.com/document/path/94669#变更会话状态>
109
110 =head3 请求说明:
111
112 =head4 请求包结构体为:
113
114 {
115 "open_kfid": "wkxxxxxxxxxxxxxxxxxx",
116 "external_userid": "wmxxxxxxxxxxxxxxxxxx",
117 "service_state": 3,
118 "servicer_userid": "zhangsan"
119 }
120
121 =head4 参数说明:
122
123 参数 必须 类型 说明
124 access_token 是 调用接口凭证
125 open_kfid 是 客服账号ID
126 external_userid 是 微信客户的external_userid
127 service_state 是 变更的目标状态,状态定义和所允许的变更可参考概述中的流程图和表格
128 servicer_userid 否 接待人员的userid。第三方应用填密文userid,即open_userid。当state=3时要求必填,接待人员须处于“正在接待”中。
129 注意:要求接待人员必须在企业微信激活使用,否则会返回95014错误。
130
131 =head3 权限说明
132
133 调用的应用需要满足如下的权限
134
135 应用类型 权限要求
136 自建应用 配置到「 微信客服- 可调用接口的应用」中
137 第三方应用 具有“微信客服->管理账号、分配会话和收发消息”权限
138 代开发自建应用 具有“微信客服->管理账号、分配会话和收发消息”权限
139
140 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
141
142 只能通过API管理企业指定的客服账号。企业可在管理后台“微信客服-通过API管理微信客服账号”处设置对应的客服账号通过API来管理。
143 操作的客服账号对应的接待人员应在应用的可见范围内
144
145 =head3 RETURN 返回结果
146
147 {
148 "errcode": 0,
149 "errmsg": "ok",
150 "msg_code": "MSG_CODE"
151 }
152
153 =head4 RETURN 参数说明
154
155 参数 类型 说明
156 errcode int 返回码
157 errmsg string 错误码描述
158 msg_code string 用于发送响应事件消息的code,将会话初次变更为service_state为2和3时,返回回复语code,service_state为4时,返回结束语code。
159 可用该code调用发送事件响应消息接口给客户发送事件响应消息
160
161 =cut
162
163 sub trans {
164 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
165 my $access_token = $_[0];
166 my $json = $_[1];
167 my $ua = LWP::UserAgent->new;
168 $ua->timeout(30);
169 $ua->env_proxy;
170
171 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/kf/service_state/trans?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
172 if ($response->is_success) {
173 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
174 }
175
176 }
177 return 0;
178 }
179
180
181
182 1;
183 __END__