| 1 | package QQ::weixin::work::pstncc; | ||
| 2 | |||
| 3 | =encoding utf8 | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | QQ::weixin::work::pstncc | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | 紧急通知应用 | ||
| 12 | |||
| 13 | =cut | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use base qw(QQ::weixin::work); | ||
| 17 | use Encode; | ||
| 18 | use LWP::UserAgent; | ||
| 19 | use JSON; | ||
| 20 | use utf8; | ||
| 21 | |||
| 22 | our $VERSION = '0.10'; | ||
| 23 | our @EXPORT = qw/ call getstates /; | ||
| 24 | |||
| 25 | =head1 FUNCTION | ||
| 26 | |||
| 27 | =head2 call(access_token, hash); | ||
| 28 | |||
| 29 | 发起语音电话 | ||
| 30 | 最后更新:2023/11/30 | ||
| 31 | |||
| 32 | =head2 SYNOPSIS | ||
| 33 | |||
| 34 | L<https://developer.work.weixin.qq.com/document/path/91627> | ||
| 35 | |||
| 36 | =head3 请求说明: | ||
| 37 | |||
| 38 | 通过此接口发起语音电话,提醒员工查看应用推送的重要消息。 | ||
| 39 | |||
| 40 | =head4 请求包体: | ||
| 41 | |||
| 42 | { | ||
| 43 | "callee_userid":["james","paul"] | ||
| 44 | } | ||
| 45 | |||
| 46 | =head4 参数说明: | ||
| 47 | |||
| 48 | 参数 必须 说明 | ||
| 49 | access_token 是 调用接口凭证 | ||
| 50 | callee_userid 是 需要呼叫的列表 | ||
| 51 | |||
| 52 | 1. callee_userid不能为空 | ||
| 53 | |||
| 54 | =head3 权限说明 | ||
| 55 | |||
| 56 | 应用类型 权限要求 | ||
| 57 | 自建应用 配置到「紧急通知 - 可调用接口的应用」中 | ||
| 58 | 代开发应用 暂不支持 | ||
| 59 | 第三方应用 暂不支持 | ||
| 60 | |||
| 61 | 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情 | ||
| 62 | |||
| 63 | =head3 RETURN 返回结果 | ||
| 64 | |||
| 65 | { | ||
| 66 | "errcode":0, | ||
| 67 | "errmsg":"ok", | ||
| 68 | "states":[ | ||
| 69 | { | ||
| 70 | "code":0, | ||
| 71 | "callid":"6-20190510201844181887818-4d0251082406000-out", | ||
| 72 | "userid":"james" | ||
| 73 | }, | ||
| 74 | { | ||
| 75 | "code":0, | ||
| 76 | "callid":"6-20190510201844181887818-4d025109f806000-out", | ||
| 77 | "userid":"paul" | ||
| 78 | } | ||
| 79 | ] | ||
| 80 | } | ||
| 81 | |||
| 82 | =head3 RETURN 参数说明 | ||
| 83 | |||
| 84 | 参数 说明 | ||
| 85 | errcode 返回码 | ||
| 86 | errmsg 对返回码的文本描述内容 | ||
| 87 | states 自动语音来电呼叫状态列表 | ||
| 88 | userid 用户id | ||
| 89 | callid 唯一标识一通呼叫的id | ||
| 90 | code 呼叫结果状态:0成功发起呼叫,非0则失败 | ||
| 91 | |||
| 92 | =head4 返回码: | ||
| 93 | |||
| 94 | 301049 调用接口的应用未在紧急通知应用中关联 | ||
| 95 | 301050 紧急通知应用未开启 | ||
| 96 | 301051 紧急通知应用余额不足 | ||
| 97 | |||
| 98 | =cut | ||
| 99 | |||
| 100 | sub call { | ||
| 101 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 102 | my $access_token = $_[0]; | ||
| 103 | my $json = $_[1]; | ||
| 104 | my $ua = LWP::UserAgent->new; | ||
| 105 | $ua->timeout(30); | ||
| 106 | $ua->env_proxy; | ||
| 107 | |||
| 108 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/pstncc/call?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 109 | if ($response->is_success) { | ||
| 110 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 111 | } | ||
| 112 | |||
| 113 | } | ||
| 114 | return 0; | ||
| 115 | } | ||
| 116 | |||
| 117 | =head2 getstates(access_token, hash); | ||
| 118 | |||
| 119 | 获取接听状态 | ||
| 120 | 最后更新:2023/11/30 | ||
| 121 | |||
| 122 | =head2 SYNOPSIS | ||
| 123 | |||
| 124 | L<https://developer.work.weixin.qq.com/document/path/91628> | ||
| 125 | |||
| 126 | =head3 请求说明: | ||
| 127 | |||
| 128 | 通过此接口,了解员工是否已接听语音电话。 | ||
| 129 | |||
| 130 | =head4 请求包体: | ||
| 131 | |||
| 132 | { | ||
| 133 | "callee_userid" : "james", | ||
| 134 | "callid" : "6-20190510201844181887818-4d0251082406000-out" | ||
| 135 | } | ||
| 136 | |||
| 137 | =head4 参数说明: | ||
| 138 | |||
| 139 | 参数 必须 说明 | ||
| 140 | access_token 是 调用接口凭证 | ||
| 141 | callee_userid 是 用户id | ||
| 142 | callid 是 发起自动语音来电callid | ||
| 143 | |||
| 144 | 1. callee_userid不能为空 | ||
| 145 | 2. callid 不能为空 | ||
| 146 | 3. 仅支持查询七天内的callid状态 | ||
| 147 | |||
| 148 | =head3 权限说明 | ||
| 149 | |||
| 150 | 应用类型 权限要求 | ||
| 151 | 自建应用 配置到「紧急通知 - 可调用接口的应用」中 | ||
| 152 | 代开发应用 暂不支持 | ||
| 153 | 第三方应用 暂不支持 | ||
| 154 | |||
| 155 | 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情 | ||
| 156 | |||
| 157 | =head3 RETURN 返回结果 | ||
| 158 | |||
| 159 | { | ||
| 160 | "errcode":0, | ||
| 161 | "errmsg":"ok", | ||
| 162 | "istalked":1, | ||
| 163 | "calltime":1557306531, | ||
| 164 | "talktime":2, | ||
| 165 | "reason":0 | ||
| 166 | } | ||
| 167 | |||
| 168 | =head3 RETURN 参数说明 | ||
| 169 | |||
| 170 | 参数 说明 | ||
| 171 | errcode 返回码 | ||
| 172 | errmsg 对返回码的文本描述内容 | ||
| 173 | istalked 0.表示未接听,1.表示接听 | ||
| 174 | calltime 呼叫发起时间戳 | ||
| 175 | talktime 通话时长单位(s) | ||
| 176 | reason 呼叫结果状态:0正常结束 | ||
| 177 | |||
| 178 | =head4 reason值含义: | ||
| 179 | |||
| 180 | 1: 振铃 | ||
| 181 | 2: 接听 | ||
| 182 | 3: 通话中 | ||
| 183 | 4: 呼叫超时 – 用户挂机 | ||
| 184 | 5: 不在服务区 | ||
| 185 | 6: 欠费未接听 | ||
| 186 | 7: 被叫拒接 | ||
| 187 | 8: 被叫关机 | ||
| 188 | 9: 空号 | ||
| 189 | 10: 呼叫受限 | ||
| 190 | 11: 线路错误 | ||
| 191 | 12: 呼叫超时 – 系统挂机 | ||
| 192 | 13: 呼叫超过限制(8分钟3次24小时8次) | ||
| 193 | 14: 线路超时未返回 | ||
| 194 | 15: 超限(主叫超限,需要换号码呼叫) | ||
| 195 | 16: 线路繁忙-稍后在呼 | ||
| 196 | 17: 呼叫取消通知 | ||
| 197 | 20: 外呼超时未确认 | ||
| 198 | 99: 其他 | ||
| 199 | |||
| 200 | =cut | ||
| 201 | |||
| 202 | sub getstates { | ||
| 203 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 204 | my $access_token = $_[0]; | ||
| 205 | my $json = $_[1]; | ||
| 206 | my $ua = LWP::UserAgent->new; | ||
| 207 | $ua->timeout(30); | ||
| 208 | $ua->env_proxy; | ||
| 209 | |||
| 210 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/pstncc/getstates?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 211 | if ($response->is_success) { | ||
| 212 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 213 | } | ||
| 214 | |||
| 215 | } | ||
| 216 | return 0; | ||
| 217 | } | ||
| 218 | |||
| 219 | 1; | ||
| 220 | __END__ |