| 1 | package QQ::weixin::work::oa::approval; | ||
| 2 | |||
| 3 | =encoding utf8 | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | QQ::weixin::work::oa::approval | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | 审批 | ||
| 12 | |||
| 13 | =cut | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use base qw(QQ::weixin::work::oa); | ||
| 17 | use Encode; | ||
| 18 | use LWP::UserAgent; | ||
| 19 | use JSON; | ||
| 20 | use utf8; | ||
| 21 | |||
| 22 | our $VERSION = '0.10'; | ||
| 23 | our @EXPORT = qw/ create_template update_template /; | ||
| 24 | |||
| 25 | =head1 FUNCTION | ||
| 26 | |||
| 27 | =head2 create_template(access_token, hash); | ||
| 28 | |||
| 29 | 创建审批模板 | ||
| 30 | 最后更新:2024/01/16 | ||
| 31 | |||
| 32 | =head2 SYNOPSIS | ||
| 33 | |||
| 34 | L<https://developer.work.weixin.qq.com/document/path/97437> | ||
| 35 | |||
| 36 | =head3 请求说明: | ||
| 37 | |||
| 38 | 可以调用此接口创建审批模板。创建新模板后,管理后台及审批应用内将生成对应模板,并生效默认流程和规则配置。 | ||
| 39 | |||
| 40 | =head4 请求包结构体为: | ||
| 41 | |||
| 42 | { | ||
| 43 | "template_name": [{ | ||
| 44 | "text": "我的api测试模版", | ||
| 45 | "lang": "zh_CN" | ||
| 46 | }], | ||
| 47 | "template_content": { | ||
| 48 | "controls": [{ | ||
| 49 | "property": { | ||
| 50 | "control": "Text", | ||
| 51 | "id": "Text-01", | ||
| 52 | "title": [{ | ||
| 53 | "text": "控件名称", | ||
| 54 | "lang": "zh_CN" | ||
| 55 | }], | ||
| 56 | "placeholder": [{ | ||
| 57 | "text": "控件说明", | ||
| 58 | "lang": "zh_CN" | ||
| 59 | }], | ||
| 60 | "require": 0, | ||
| 61 | "un_print": 1 | ||
| 62 | }, | ||
| 63 | "config":{ | ||
| 64 | |||
| 65 | } | ||
| 66 | }] | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | =head4 参数说明: | ||
| 71 | |||
| 72 | 参数 必须 说明 | ||
| 73 | access_token 是 调用接口凭证 | ||
| 74 | template_name 是 模版名称数组 | ||
| 75 | └ text 是 模版名称。需满足以下条件:1-模版名称不得和现有模版名称重复;2-长度不得超过40个字符。 | ||
| 76 | └ lang 是 显示语言,中文:zh_CN(注意不是zh-CN) | ||
| 77 | template_content 否 审批模版控件设置,由多个表单控件及其内容组成,其中包含需要对控件赋值的信息 | ||
| 78 | └ controls 否 控件数组,模版中可以设置多个控件类型,排列顺序和管理端展示的相同 | ||
| 79 | └└ property 是 控件的基础属性 | ||
| 80 | └└└ control 是 控件类型:Text-文本;Textarea-多行文本;Number-数字;Money-金额;Date-日期/日期+时间;Selector-单选/多选;;Contact-成员/部门;Tips-说明文字;File-附件;Table-明细;Location-位置;RelatedApproval-关联审批单;DateRange-时长;PhoneNumber-电话号码;Vacation-假期;Attendance-外出/出差/加班;BankAccount-收款账户 。以上为目前可支持的控件类型 | ||
| 81 | └└└ id 是 控件id。1-模版内控件id必须唯一;2-控件id格式:control-数字,如"Text-01" | ||
| 82 | └└└ title 是 控件名称 | ||
| 83 | └└└└ text 是 控件名称。需满足以下条件:1-控件名称不得和现有控件名称重复;2-长度不得超过40个字符。 | ||
| 84 | └└└└ lang 是 显示语言,中文:zh_CN(注意不是zh-CN) | ||
| 85 | └└└ placeholder 否 控件说明 | ||
| 86 | └└└└ text 否 控件说明。需满足以下条件:长度不得超过80个字符。 | ||
| 87 | └└└└ lang 否 显示语言,中文:zh_CN(注意不是zh-CN);若text填写,则该项为必填 | ||
| 88 | └└└ require 否 控件是否必填。0-非必填;1-必填;默认为0 | ||
| 89 | └└└ un_print 否 控件是否可打印。0-可打印;1-不可打印;默认为0 | ||
| 90 | └└ config 是or否 控件配置。控件的类型不同,其中填的参数不相同,下方将为每一个控件配置进行详细说明 | ||
| 91 | |||
| 92 | =head3 权限说明 | ||
| 93 | |||
| 94 | 应用类型 权限要求 | ||
| 95 | 自建应用 配置到「审批 - 可调用接口的应用」中 | ||
| 96 | 代开发应用 具有「审批」权限 | ||
| 97 | 第三方应用 暂不支持 | ||
| 98 | |||
| 99 | 1.第三方应用可以获取第三方应用添加的模板详情。 | ||
| 100 | 2.自建应用的Secret可获取企业自建模板的模板详情。 | ||
| 101 | 3.接口调用频率限制为600次/分钟。 | ||
| 102 | 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情 | ||
| 103 | |||
| 104 | 注意: | ||
| 105 | 1. 当模板的控件为必填属性时,表单中对应的控件必须有值。 | ||
| 106 | 2. 一个模版中只能拥有一类假勤控件类型,Vacation-假期;Attendance-外出/出差/加班 均为假勤控件类型。 | ||
| 107 | |||
| 108 | =head3 RETURN 返回结果 | ||
| 109 | |||
| 110 | { | ||
| 111 | "errcode":0, | ||
| 112 | "errmsg":"ok", | ||
| 113 | "template_id":"C4RbNKm731MCFVgk6XLq1Rs9W4aNXPJV2mmXT4qGy" | ||
| 114 | } | ||
| 115 | |||
| 116 | =head3 RETURN 参数说明 | ||
| 117 | |||
| 118 | 参数 说明 | ||
| 119 | errcode 错误码,详情见错误码说明 | ||
| 120 | errmsg 错误码对应的错误信息提示 | ||
| 121 | template_id 模版创建成功后返回的模版id | ||
| 122 | |||
| 123 | =head3 附录:各控件config参数介绍 | ||
| 124 | |||
| 125 | L<https://developer.work.weixin.qq.com/document/path/97437#附录:各控件config数介绍> | ||
| 126 | |||
| 127 | =head4 错误说明 | ||
| 128 | |||
| 129 | 错误码 说明 | ||
| 130 | 301088 无审批应用权限 | ||
| 131 | 301086 审批控件参数错误 | ||
| 132 | 301087 企业模版数超过上限 | ||
| 133 | 620004 服务器内部错误 | ||
| 134 | -1 未知错误 | ||
| 135 | |||
| 136 | =cut | ||
| 137 | |||
| 138 | sub create_template { | ||
| 139 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 140 | my $access_token = $_[0]; | ||
| 141 | my $json = $_[1]; | ||
| 142 | my $ua = LWP::UserAgent->new; | ||
| 143 | $ua->timeout(30); | ||
| 144 | $ua->env_proxy; | ||
| 145 | |||
| 146 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/oa/approval/create_template?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 147 | if ($response->is_success) { | ||
| 148 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 149 | } | ||
| 150 | |||
| 151 | } | ||
| 152 | return 0; | ||
| 153 | } | ||
| 154 | |||
| 155 | =head2 update_template(access_token, hash); | ||
| 156 | |||
| 157 | 更新审批模板 | ||
| 158 | 最后更新:2024/01/16 | ||
| 159 | |||
| 160 | =head2 SYNOPSIS | ||
| 161 | |||
| 162 | L<https://developer.work.weixin.qq.com/document/path/97438> | ||
| 163 | |||
| 164 | =head3 请求说明: | ||
| 165 | |||
| 166 | 可调用本接口更新审批模板。更新模板后,管理后台及审批应用内将更新原模板的内容,已配置的审批流程和规则不变。 | ||
| 167 | |||
| 168 | =head4 请求包结构体为: | ||
| 169 | |||
| 170 | { | ||
| 171 | "template_id": "C4RbNKm731MCFVgk6XLq1Rs9W4aNXPJV2mmXT4qGy", | ||
| 172 | "template_name": [{ | ||
| 173 | "text": "我的api测试模版", | ||
| 174 | "lang": "zh_CN" | ||
| 175 | }], | ||
| 176 | "template_content": { | ||
| 177 | "controls": [{ | ||
| 178 | "property": { | ||
| 179 | "control": "Text", | ||
| 180 | "id": "Text-01", | ||
| 181 | "title": [{ | ||
| 182 | "text": "控件名称", | ||
| 183 | "lang": "zh_CN" | ||
| 184 | }], | ||
| 185 | "placeholder": [{ | ||
| 186 | "text": "控件说明", | ||
| 187 | "lang": "zh_CN" | ||
| 188 | }], | ||
| 189 | "require": 0, | ||
| 190 | "un_print": 1 | ||
| 191 | }, | ||
| 192 | "config":{ | ||
| 193 | |||
| 194 | } | ||
| 195 | }] | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | =head4 参数说明: | ||
| 200 | |||
| 201 | 参数 必须 说明 | ||
| 202 | access_token 是 调用接口凭证。必须使用审批应用或企业内自建应用的secret获取,获取方式参考:文档-获取access_token | ||
| 203 | template_id 是 模版id | ||
| 204 | template_name 是 模版名称数组 | ||
| 205 | └ text 是 模版名称。需满足以下条件:1-模版名称不得和现有模版名称重复;2-长度不得超过40个字符。 | ||
| 206 | └ lang 是 显示语言,中文:zh_CN(注意不是zh-CN) | ||
| 207 | template_content 否 审批模版控件设置,由多个表单控件及其内容组成,其中包含需要对控件赋值的信息 | ||
| 208 | └ controls 否 控件数组,模版中可以设置多个控件类型,排列顺序和管理端展示的相同 | ||
| 209 | └└ property 是 控件的基础属性 | ||
| 210 | └└└ control 是 控件类型:Text-文本;Textarea-多行文本;Number-数字;Money-金额;Date-日期/日期+时间;Selector-单选/多选;;Contact-成员/部门;Tips-说明文字;File-附件;Table-明细;Location-位置;RelatedApproval-关联审批单;DateRange-时长;PhoneNumber-电话号码;Vacation-假期;Attendance-外出/出差/加班;BankAccount-收款账户。以上为目前可支持的控件类型 | ||
| 211 | └└└ id 是 控件id。1-模版内控件id必须唯一;2-控件id格式:control-数字,如"Text-01" | ||
| 212 | └└└ title 是 控件名称 | ||
| 213 | └└└└ text 是 控件名称。需满足以下条件:1-控件名称不得和现有控件名称重复;2-长度不得超过40个字符。 | ||
| 214 | └└└└ lang 是 显示语言,中文:zh_CN(注意不是zh-CN) | ||
| 215 | └└└ placeholder 否 控件说明 | ||
| 216 | └└└└ text 否 控件说明。需满足以下条件:长度不得超过80个字符。 | ||
| 217 | └└└└ lang 否 显示语言,中文:zh_CN(注意不是zh-CN);若text填写,则该项为必填 | ||
| 218 | └└└ require 否 控件是否必填。0-非必填;1-必填;默认为0 | ||
| 219 | └└└ un_print 否 控件是否可打印。0-可打印;1-不可打印;默认为0 | ||
| 220 | └└ config 是or否 控件配置。控件的类型不同,其中填的参数不相同,下方将为每一个控件配置进行详细说明 | ||
| 221 | |||
| 222 | 注意: | ||
| 223 | 1. 当模板的控件为必填属性时,表单中对应的控件必须有值。 | ||
| 224 | 2. 一个模版中只能拥有一类假勤控件类型,Vacation-假期;Attendance-外出/出差/加班 均为假勤控件类型。 | ||
| 225 | |||
| 226 | =head3 权限说明 | ||
| 227 | |||
| 228 | 应用类型 权限要求 | ||
| 229 | 自建应用 配置到「审批 - 可调用接口的应用」中 | ||
| 230 | 代开发应用 具有「审批」权限 | ||
| 231 | 第三方应用 暂不支持 | ||
| 232 | |||
| 233 | 仅能更新自身应用模板 | ||
| 234 | 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情 | ||
| 235 | |||
| 236 | =head3 RETURN 返回结果 | ||
| 237 | |||
| 238 | { | ||
| 239 | "errcode": 0, | ||
| 240 | "errmsg": "ok" | ||
| 241 | } | ||
| 242 | |||
| 243 | =head3 RETURN 参数说明 | ||
| 244 | |||
| 245 | 参数 类型 说明 | ||
| 246 | errcode int32 返回码 | ||
| 247 | errmsg string 错误码描述 | ||
| 248 | |||
| 249 | =head3 附录:各控件config参数介绍 | ||
| 250 | |||
| 251 | L<https://developer.work.weixin.qq.com/document/path/97438#附录:各控件config数介绍> | ||
| 252 | |||
| 253 | =head3 错误说明: | ||
| 254 | |||
| 255 | 错误码 说明 | ||
| 256 | 301088 无审批应用权限 | ||
| 257 | 301086 审批控件参数错误 | ||
| 258 | 301087 企业模版数超过上限 | ||
| 259 | 620004 服务器内部错误 | ||
| 260 | -1 未知错误 | ||
| 261 | |||
| 262 | =cut | ||
| 263 | |||
| 264 | sub update_template { | ||
| 265 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 266 | my $access_token = $_[0]; | ||
| 267 | my $json = $_[1]; | ||
| 268 | my $ua = LWP::UserAgent->new; | ||
| 269 | $ua->timeout(30); | ||
| 270 | $ua->env_proxy; | ||
| 271 | |||
| 272 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/oa/approval/update_template?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 273 | if ($response->is_success) { | ||
| 274 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 275 | } | ||
| 276 | |||
| 277 | } | ||
| 278 | return 0; | ||
| 279 | } | ||
| 280 | |||
| 281 | 1; | ||
| 282 | __END__ |