| 1 | package QQ::weixin::work::wedoc::document; | ||
| 2 | |||
| 3 | =encoding utf8 | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | QQ::weixin::work::wedoc::document | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | 文档 | ||
| 12 | |||
| 13 | =cut | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use base qw(QQ::weixin::work::wedoc); | ||
| 17 | use Encode; | ||
| 18 | use LWP::UserAgent; | ||
| 19 | use JSON; | ||
| 20 | use utf8; | ||
| 21 | |||
| 22 | our $VERSION = '0.10'; | ||
| 23 | our @EXPORT = qw/ batch_update get /; | ||
| 24 | |||
| 25 | =head1 FUNCTION | ||
| 26 | |||
| 27 | 编辑文档 | ||
| 28 | |||
| 29 | =head2 batch_update(access_token, hash); | ||
| 30 | |||
| 31 | 编辑文档内容 | ||
| 32 | 最后更新:2022/12/10 | ||
| 33 | |||
| 34 | =head2 SYNOPSIS | ||
| 35 | |||
| 36 | L<https://developer.work.weixin.qq.com/document/path/97626> | ||
| 37 | |||
| 38 | =head3 请求说明: | ||
| 39 | |||
| 40 | 该接口可以对一个在线文档批量执行多个更新操作。 | ||
| 41 | |||
| 42 | 注意: | ||
| 43 | |||
| 44 | 批量更新请求,若其中有一个操作报错则全部更新操作不生效。 | ||
| 45 | 单次批量更新操作数量 <= 30。 | ||
| 46 | |||
| 47 | =head4 请求包结构体为: | ||
| 48 | |||
| 49 | { | ||
| 50 | "docid": "DOCID", | ||
| 51 | "verison": 10, | ||
| 52 | "requests": [ | ||
| 53 | { | ||
| 54 | "insert_text": { | ||
| 55 | "text": "text content", | ||
| 56 | "location": { | ||
| 57 | "index": 10 | ||
| 58 | } | ||
| 59 | } | ||
| 60 | }, | ||
| 61 | { | ||
| 62 | "insert_table": { | ||
| 63 | "rows": 2, | ||
| 64 | "cols": 2, | ||
| 65 | "location": { | ||
| 66 | "index": 10 | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | ] | ||
| 71 | } | ||
| 72 | |||
| 73 | =head4 参数说明: | ||
| 74 | |||
| 75 | 参数 类型 是否必须 说明 | ||
| 76 | access_token 是 调用接口凭证 | ||
| 77 | docid string 是 文档的docid | ||
| 78 | version uint32 否 操作的文档版本, 该参数可以通过获取文档内容接口获得。操作后文档版本将更新一版。要更新的文档版本与最新文档版本相差不能超过100个。 | ||
| 79 | requests object[] 是 更新操作列表,详见 UpdateRequest | ||
| 80 | |||
| 81 | =head4 权限说明: | ||
| 82 | |||
| 83 | 自建应用需配置到“可调用应用”列表中的应用secret所获取的accesstoken来调用(accesstoken如何获取?) | ||
| 84 | 第三方应用需具有“文档”权限 | ||
| 85 | 代开发自建应用需具有“文档”权限 | ||
| 86 | |||
| 87 | =head3 RETURN 返回结果: | ||
| 88 | |||
| 89 | { | ||
| 90 | "errcode": 0, | ||
| 91 | "errmsg": "ok" | ||
| 92 | } | ||
| 93 | |||
| 94 | =head4 RETURN 参数说明: | ||
| 95 | |||
| 96 | 参数 类型 说明 | ||
| 97 | errcode int32 错误码 | ||
| 98 | errmsg string 错误码说明 | ||
| 99 | |||
| 100 | =head4 参数详细说明 | ||
| 101 | |||
| 102 | L<https://developer.work.weixin.qq.com/document/path/97626#参数详细说明> | ||
| 103 | |||
| 104 | =cut | ||
| 105 | |||
| 106 | sub batch_update { | ||
| 107 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 108 | my $access_token = $_[0]; | ||
| 109 | my $json = $_[1]; | ||
| 110 | my $ua = LWP::UserAgent->new; | ||
| 111 | $ua->timeout(30); | ||
| 112 | $ua->env_proxy; | ||
| 113 | |||
| 114 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/wedoc/document/batch_update?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 115 | if ($response->is_success) { | ||
| 116 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 117 | } | ||
| 118 | |||
| 119 | } | ||
| 120 | return 0; | ||
| 121 | } | ||
| 122 | |||
| 123 | =head1 FUNCTION | ||
| 124 | |||
| 125 | 获取文档数据 | ||
| 126 | |||
| 127 | =head2 get(access_token, hash); | ||
| 128 | |||
| 129 | 获取文档数据 | ||
| 130 | 最后更新:2023/10/19 | ||
| 131 | |||
| 132 | =head2 SYNOPSIS | ||
| 133 | |||
| 134 | L<https://developer.work.weixin.qq.com/document/path/97659> | ||
| 135 | |||
| 136 | =head3 请求说明: | ||
| 137 | |||
| 138 | 该接口用于获取文档数据 | ||
| 139 | |||
| 140 | =head4 请求包结构体为: | ||
| 141 | |||
| 142 | { | ||
| 143 | "docid": "DOCID" | ||
| 144 | } | ||
| 145 | |||
| 146 | =head4 参数说明: | ||
| 147 | |||
| 148 | 参数 类型 是否必须 说明 | ||
| 149 | access_token 是 调用接口凭证 | ||
| 150 | docid string 是 文档的docid | ||
| 151 | |||
| 152 | =head4 权限说明: | ||
| 153 | |||
| 154 | 自建应用需配置到“可调用应用”列表中的应用secret所获取的accesstoken来调用(accesstoken如何获取?) | ||
| 155 | 第三方应用需具有“文档”权限 | ||
| 156 | 代开发自建应用需具有“文档”权限 | ||
| 157 | |||
| 158 | =head3 RETURN 返回结果: | ||
| 159 | |||
| 160 | { | ||
| 161 | "errcode": 0, | ||
| 162 | "errmsg": "ok", | ||
| 163 | "version": 10, | ||
| 164 | "document": { | ||
| 165 | ... | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | =head4 RETURN 参数说明: | ||
| 170 | |||
| 171 | 参数 类型 说明 | ||
| 172 | errcode int32 错误码 | ||
| 173 | errmsg string 错误码说明 | ||
| 174 | version uint32 文档版本 | ||
| 175 | document object(Node) 文档内容根节点,详见Node | ||
| 176 | |||
| 177 | =head4 参数详细说明 | ||
| 178 | |||
| 179 | L<https://developer.work.weixin.qq.com/document/path/97659#参数详细说明> | ||
| 180 | |||
| 181 | =cut | ||
| 182 | |||
| 183 | sub get { | ||
| 184 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 185 | my $access_token = $_[0]; | ||
| 186 | my $json = $_[1]; | ||
| 187 | my $ua = LWP::UserAgent->new; | ||
| 188 | $ua->timeout(30); | ||
| 189 | $ua->env_proxy; | ||
| 190 | |||
| 191 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/wedoc/document/get?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 192 | if ($response->is_success) { | ||
| 193 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 194 | } | ||
| 195 | |||
| 196 | } | ||
| 197 | return 0; | ||
| 198 | } | ||
| 199 | |||
| 200 | 1; | ||
| 201 | __END__ |