| 1 | package QQ::weixin::work::user; | ||
| 2 | |||
| 3 | =encoding utf8 | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | QQ::weixin::work::user | ||
| 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/ create get update delete batchdelete | ||
| 24 | simplelist list convert_to_openid convert_to_userid authsucc | ||
| 25 | get_active_stat getuserid get_userid_by_email list_id | ||
| 26 | getuserinfo get_mobile_hashcode tfa_succ /; | ||
| 27 | |||
| 28 | =head1 FUNCTION | ||
| 29 | |||
| 30 | =head2 create(access_token, hash); | ||
| 31 | |||
| 32 | 创建成员 | ||
| 33 | 最后更新:2023/09/27 | ||
| 34 | |||
| 35 | =head2 SYNOPSIS | ||
| 36 | |||
| 37 | L<https://developer.work.weixin.qq.com/document/path/90195> | ||
| 38 | |||
| 39 | =head3 请求说明: | ||
| 40 | |||
| 41 | =head4 请求包结构体为: | ||
| 42 | |||
| 43 | { | ||
| 44 | "userid": "zhangsan", | ||
| 45 | "name": "张三", | ||
| 46 | "alias": "jackzhang", | ||
| 47 | "mobile": "+86 13800000000", | ||
| 48 | "department": [1, 2], | ||
| 49 | "order":[10,40], | ||
| 50 | "position": "产品经理", | ||
| 51 | "gender": "1", | ||
| 52 | "email": "zhangsan@gzdev.com", | ||
| 53 | "biz_mail":"zhangsan@qyycs2.wecom.work", | ||
| 54 | "is_leader_in_dept": [1, 0], | ||
| 55 | "direct_leader":["lisi"], | ||
| 56 | "enable":1, | ||
| 57 | "avatar_mediaid": "2-G6nrLmr5EC3MNb_-zL1dDdzkd0p7cNliYu9V5w7o8K0", | ||
| 58 | "telephone": "020-123456", | ||
| 59 | "address": "广州市海珠区新港中路", | ||
| 60 | "main_department": 1, | ||
| 61 | "extattr": { | ||
| 62 | "attrs": [ | ||
| 63 | { | ||
| 64 | "type": 0, | ||
| 65 | "name": "文本名称", | ||
| 66 | "text": { | ||
| 67 | "value": "文本" | ||
| 68 | } | ||
| 69 | }, | ||
| 70 | { | ||
| 71 | "type": 1, | ||
| 72 | "name": "网页名称", | ||
| 73 | "web": { | ||
| 74 | "url": "http://www.test.com", | ||
| 75 | "title": "标题" | ||
| 76 | } | ||
| 77 | } | ||
| 78 | ] | ||
| 79 | }, | ||
| 80 | "to_invite": true, | ||
| 81 | "external_position": "高级产品经理", | ||
| 82 | "external_profile": { | ||
| 83 | "external_corp_name": "企业简称", | ||
| 84 | "wechat_channels": { | ||
| 85 | "nickname": "视频号名称" | ||
| 86 | }, | ||
| 87 | "external_attr": [ | ||
| 88 | { | ||
| 89 | "type": 0, | ||
| 90 | "name": "文本名称", | ||
| 91 | "text": { | ||
| 92 | "value": "文本" | ||
| 93 | } | ||
| 94 | }, | ||
| 95 | { | ||
| 96 | "type": 1, | ||
| 97 | "name": "网页名称", | ||
| 98 | "web": { | ||
| 99 | "url": "http://www.test.com", | ||
| 100 | "title": "标题" | ||
| 101 | } | ||
| 102 | }, | ||
| 103 | { | ||
| 104 | "type": 2, | ||
| 105 | "name": "测试app", | ||
| 106 | "miniprogram": { | ||
| 107 | "appid": "wx8bd8012614784fake", | ||
| 108 | "pagepath": "/index", | ||
| 109 | "title": "my miniprogram" | ||
| 110 | } | ||
| 111 | } | ||
| 112 | ] | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | =head4 参数说明: | ||
| 117 | |||
| 118 | 参数 必须 说明 | ||
| 119 | access_token 是 调用接口凭证。获取方法查看“获取access_token” | ||
| 120 | userid 是 成员UserID。对应管理端的账号,企业内必须唯一。长度为1~64个字节。只能由数字、字母和“_-@.”四种字符组成,且第一个字符必须是数字或字母。系统进行唯一性检查时会忽略大小写。 | ||
| 121 | name 是 成员名称。长度为1~64个utf8字符 | ||
| 122 | alias 否 成员别名。长度1~64个utf8字符 | ||
| 123 | mobile 否 手机号码。企业内必须唯一,mobile/email二者不能同时为空 | ||
| 124 | department 是 成员所属部门id列表,不超过100个 | ||
| 125 | order 否 部门内的排序值,默认为0,成员次序以创建时间从小到大排列。个数必须和参数department的个数一致,数值越大排序越前面。有效的值范围是[0, 2^32) | ||
| 126 | position 否 职务信息。长度为0~128个字符 | ||
| 127 | gender 否 性别。1表示男性,2表示女性 | ||
| 128 | email 否 邮箱。长度6~64个字节,且为有效的email格式。企业内必须唯一,mobile/email二者不能同时为空 | ||
| 129 | biz_mail 否 企业邮箱。仅对开通企业邮箱的企业有效。长度6~64个字节,且为有效的企业邮箱格式。企业内必须唯一。未填写则系统会为用户生成默认企业邮箱(由系统生成的邮箱可修改一次,2022年4月25日之后创建的成员需通过企业管理后台-协作-邮件-邮箱管理-成员邮箱修改) | ||
| 130 | telephone 否 座机。32字节以内,由纯数字、“-”、“+”或“,”组成。 | ||
| 131 | is_leader_in_dept 否 个数必须和参数department的个数一致,表示在所在的部门内是否为部门负责人。1表示为部门负责人,0表示非部门负责人。在审批(自建、第三方)等应用里可以用来标识上级审批人 | ||
| 132 | direct_leader 否 直属上级UserID,设置范围为企业内成员,可以设置最多1个上级 | ||
| 133 | avatar_mediaid 否 成员头像的mediaid,通过素材管理接口上传图片获得的mediaid | ||
| 134 | enable 否 启用/禁用成员。1表示启用成员,0表示禁用成员 | ||
| 135 | extattr 否 自定义字段。自定义字段需要先在WEB管理端添加,见扩展属性添加方法,否则忽略未知属性的赋值。 | ||
| 136 | extattr.type 是 属性类型: 0-文本 1-网页 2-小程序 | ||
| 137 | extattr.name 是 属性名称: 需要先确保在管理端有创建该属性,否则会忽略 | ||
| 138 | extattr.text 否 文本类型的属性 | ||
| 139 | extattr.text.value 是 文本属性内容,长度限制64个UTF8字符 | ||
| 140 | extattr.web 否 网页类型的属性,url和title字段要么同时为空表示清除该属性,要么同时不为空 | ||
| 141 | extattr.web.url 是 网页的url,必须包含http或者https头 | ||
| 142 | extattr.web.title 是 网页的展示标题,长度限制12个UTF8字符 | ||
| 143 | to_invite 否 是否邀请该成员使用企业微信(将通过微信服务通知或短信或邮件下发邀请,每天自动下发一次,最多持续3个工作日),默认值为true。 | ||
| 144 | external_profile 否 成员对外属性,字段详情见对外属性 | ||
| 145 | external_position 否 对外职务,如果设置了该值,则以此作为对外展示的职务,否则以position来展示。长度12个汉字内 | ||
| 146 | nickname 否 视频号名字(设置后,成员将对外展示该视频号)。须从企业绑定到企业微信的视频号中选择,可在“我的企业”页中查看绑定的视频号 | ||
| 147 | address 否 地址。长度最大128个字符 | ||
| 148 | main_department 否 主部门 | ||
| 149 | |||
| 150 | =head3 权限说明 | ||
| 151 | |||
| 152 | 仅通讯录同步助手或第三方通讯录应用可调用。 | ||
| 153 | |||
| 154 | 注意,每个部门下的部门、成员总数不能超过3万个。建议保证创建department对应的部门和创建成员是串行化处理。 | ||
| 155 | |||
| 156 | =head3 RETURN 返回结果 | ||
| 157 | |||
| 158 | { | ||
| 159 | "errcode": 0, | ||
| 160 | "errmsg": "created" | ||
| 161 | } | ||
| 162 | |||
| 163 | =head3 RETURN 参数说明 | ||
| 164 | |||
| 165 | 参数 说明 | ||
| 166 | errcode 返回码 | ||
| 167 | errmsg 对返回码的文本描述内容 | ||
| 168 | |||
| 169 | =cut | ||
| 170 | |||
| 171 | sub create { | ||
| 172 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 173 | my $access_token = $_[0]; | ||
| 174 | my $json = $_[1]; | ||
| 175 | my $ua = LWP::UserAgent->new; | ||
| 176 | $ua->timeout(30); | ||
| 177 | $ua->env_proxy; | ||
| 178 | |||
| 179 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 180 | if ($response->is_success) { | ||
| 181 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 182 | } | ||
| 183 | |||
| 184 | } | ||
| 185 | return 0; | ||
| 186 | } | ||
| 187 | |||
| 188 | =head2 get(access_token, userid); | ||
| 189 | |||
| 190 | 读取成员 | ||
| 191 | 最后更新:2023/10/23 | ||
| 192 | |||
| 193 | =head2 SYNOPSIS | ||
| 194 | |||
| 195 | L<https://developer.work.weixin.qq.com/document/path/90196> | ||
| 196 | |||
| 197 | =head3 请求说明: | ||
| 198 | |||
| 199 | =head4 参数说明: | ||
| 200 | |||
| 201 | 参数 必须 说明 | ||
| 202 | access_token 是 调用接口凭证 | ||
| 203 | userid 是 成员UserID。对应管理端的帐号,企业内必须唯一。不区分大小写,长度为1~64个字节 | ||
| 204 | |||
| 205 | =head3 权限说明 | ||
| 206 | |||
| 207 | 应用须拥有指定成员的查看权限。 | ||
| 208 | |||
| 209 | =head3 RETURN 返回结果 | ||
| 210 | |||
| 211 | { | ||
| 212 | "errcode": 0, | ||
| 213 | "errmsg": "ok", | ||
| 214 | "userid": "zhangsan", | ||
| 215 | "name": "张三", | ||
| 216 | "department": [1, 2], | ||
| 217 | "order": [1, 2], | ||
| 218 | "position": "后台工程师", | ||
| 219 | "mobile": "13800000000", | ||
| 220 | "gender": "1", | ||
| 221 | "email": "zhangsan@gzdev.com", | ||
| 222 | "biz_mail":"zhangsan@qyycs2.wecom.work", | ||
| 223 | "is_leader_in_dept": [1, 0], | ||
| 224 | "direct_leader":["lisi"], | ||
| 225 | "avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0", | ||
| 226 | "thumb_avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/100", | ||
| 227 | "telephone": "020-123456", | ||
| 228 | "alias": "jackzhang", | ||
| 229 | "address": "广州市海珠区新港中路", | ||
| 230 | "open_userid": "xxxxxx", | ||
| 231 | "main_department": 1, | ||
| 232 | "extattr": { | ||
| 233 | "attrs": [ | ||
| 234 | { | ||
| 235 | "type": 0, | ||
| 236 | "name": "文本名称", | ||
| 237 | "text": { | ||
| 238 | "value": "文本" | ||
| 239 | } | ||
| 240 | }, | ||
| 241 | { | ||
| 242 | "type": 1, | ||
| 243 | "name": "网页名称", | ||
| 244 | "web": { | ||
| 245 | "url": "http://www.test.com", | ||
| 246 | "title": "标题" | ||
| 247 | } | ||
| 248 | } | ||
| 249 | ] | ||
| 250 | }, | ||
| 251 | "status": 1, | ||
| 252 | "qr_code": "https://open.work.weixin.qq.com/wwopen/userQRCode?vcode=xxx", | ||
| 253 | "external_position": "产品经理", | ||
| 254 | "external_profile": { | ||
| 255 | "external_corp_name": "企业简称", | ||
| 256 | "wechat_channels": { | ||
| 257 | "nickname": "视频号名称", | ||
| 258 | "status": 1 | ||
| 259 | }, | ||
| 260 | "external_attr": [{ | ||
| 261 | "type": 0, | ||
| 262 | "name": "文本名称", | ||
| 263 | "text": { | ||
| 264 | "value": "文本" | ||
| 265 | } | ||
| 266 | }, | ||
| 267 | { | ||
| 268 | "type": 1, | ||
| 269 | "name": "网页名称", | ||
| 270 | "web": { | ||
| 271 | "url": "http://www.test.com", | ||
| 272 | "title": "标题" | ||
| 273 | } | ||
| 274 | }, | ||
| 275 | { | ||
| 276 | "type": 2, | ||
| 277 | "name": "测试app", | ||
| 278 | "miniprogram": { | ||
| 279 | "appid": "wx8bd80126147dFAKE", | ||
| 280 | "pagepath": "/index", | ||
| 281 | "title": "my miniprogram" | ||
| 282 | } | ||
| 283 | } | ||
| 284 | ] | ||
| 285 | } | ||
| 286 | } | ||
| 287 | |||
| 288 | =head4 RETURN 参数说明 | ||
| 289 | |||
| 290 | 参数 说明 | ||
| 291 | errcode 返回码 | ||
| 292 | errmsg 对返回码的文本描述内容 | ||
| 293 | userid 成员UserID。对应管理端的帐号,企业内必须唯一。不区分大小写,长度为1~64个字节 | ||
| 294 | name 成员名称;第三方不可获取,调用时返回userid以代替name;代开发自建应用需要管理员授权才返回;对于非第三方创建的成员,第三方通讯录应用也不可获取;未返回name的情况需要通过通讯录展示组件来展示名字 | ||
| 295 | mobile 手机号码,代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 296 | department 成员所属部门id列表,仅返回该应用有查看权限的部门id;成员授权模式下,固定返回根部门id,即固定为1。对授权了“组织架构信息”权限的第三方应用,返回成员所属的全部部门id | ||
| 297 | order 部门内的排序值,默认为0。数量必须和department一致,数值越大排序越前面。值范围是0, 2^32)。[成员授权模式下不返回该字段 | ||
| 298 | position 职务信息;代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 299 | gender 性别。0表示未定义,1表示男性,2表示女性。第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段。注:不可获取指返回值0 | ||
| 300 | email 邮箱,代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 301 | biz_mail 企业邮箱,代开发自建应用不返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 302 | is_leader_in_dept 表示在所在的部门内是否为部门负责人,数量与department一致;第三方通讯录应用或者授权了“组织架构信息-应用可获取企业的部门组织架构信息-部门负责人”权限的第三方应用可获取;对于非第三方创建的成员,第三方通讯录应用不可获取;上游企业不可获取下游企业成员该字段 | ||
| 303 | direct_leader 直属上级UserID,返回在应用可见范围内的直属上级列表,最多有五个直属上级;第三方通讯录应用或者授权了“组织架构信息-应用可获取可见范围内成员组织架构信息-直属上级”权限的第三方应用可获取;对于非第三方创建的成员,第三方通讯录应用不可获取;上游企业不可获取下游企业成员该字段 | ||
| 304 | avatar 头像url。 第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 305 | thumb_avatar 头像缩略图url。第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 306 | telephone 座机。代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 307 | alias 别名;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 308 | extattr 扩展属性,代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 309 | status 激活状态: 1=已激活,2=已禁用,4=未激活,5=退出企业。 | ||
| 310 | 已激活代表已激活企业微信或已关注微信插件(原企业号)。未激活代表既未激活企业微信又未关注微信插件(原企业号)。 | ||
| 311 | qr_code 员工个人二维码,扫描可添加为外部联系人(注意返回的是一个url,可在浏览器上打开该url以展示二维码);第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 312 | external_profile 成员对外属性,字段详情见对外属性;代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 313 | external_position 对外职务,如果设置了该值,则以此作为对外展示的职务,否则以position来展示。代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 314 | address 地址。代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 315 | open_userid 全局唯一。对于同一个服务商,不同应用获取到企业内同一个成员的open_userid是相同的,最多64个字节。仅第三方应用可获取 | ||
| 316 | main_department 主部门,仅当应用对主部门有查看权限时返回。 | ||
| 317 | |||
| 318 | =cut | ||
| 319 | |||
| 320 | sub get { | ||
| 321 | if ( @_ && $_[0] && $_[1] ) { | ||
| 322 | my $access_token = $_[0]; | ||
| 323 | my $userid = $_[1]; | ||
| 324 | my $ua = LWP::UserAgent->new; | ||
| 325 | $ua->timeout(30); | ||
| 326 | $ua->env_proxy; | ||
| 327 | |||
| 328 | my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=$access_token&userid=$userid"); | ||
| 329 | if ($response->is_success) { | ||
| 330 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 331 | } | ||
| 332 | |||
| 333 | } | ||
| 334 | return 0; | ||
| 335 | } | ||
| 336 | |||
| 337 | =head2 update(access_token, hash); | ||
| 338 | |||
| 339 | 更新成员 | ||
| 340 | 最后更新:2023/09/07 | ||
| 341 | |||
| 342 | =head2 SYNOPSIS | ||
| 343 | |||
| 344 | L<https://developer.work.weixin.qq.com/document/path/90197> | ||
| 345 | |||
| 346 | =head3 请求说明: | ||
| 347 | |||
| 348 | =head4 请求包体: | ||
| 349 | |||
| 350 | { | ||
| 351 | "userid": "zhangsan", | ||
| 352 | "name": "李四", | ||
| 353 | "department": [1], | ||
| 354 | "order": [10], | ||
| 355 | "position": "后台工程师", | ||
| 356 | "mobile": "13800000000", | ||
| 357 | "gender": "1", | ||
| 358 | "email": "zhangsan@gzdev.com", | ||
| 359 | "biz_mail":"zhangsan@qyycs2.wecom.work", | ||
| 360 | "is_leader_in_dept": [1], | ||
| 361 | "direct_leader":["lisi"], | ||
| 362 | "enable": 1, | ||
| 363 | "avatar_mediaid": "2-G6nrLmr5EC3MNb_-zL1dDdzkd0p7cNliYu9V5w7o8K0", | ||
| 364 | "telephone": "020-123456", | ||
| 365 | "alias": "jackzhang", | ||
| 366 | "address": "广州市海珠区新港中路", | ||
| 367 | "main_department": 1, | ||
| 368 | "extattr": { | ||
| 369 | "attrs": [ | ||
| 370 | { | ||
| 371 | "type": 0, | ||
| 372 | "name": "文本名称", | ||
| 373 | "text": { | ||
| 374 | "value": "文本" | ||
| 375 | } | ||
| 376 | }, | ||
| 377 | { | ||
| 378 | "type": 1, | ||
| 379 | "name": "网页名称", | ||
| 380 | "web": { | ||
| 381 | "url": "http://www.test.com", | ||
| 382 | "title": "标题" | ||
| 383 | } | ||
| 384 | } | ||
| 385 | ] | ||
| 386 | }, | ||
| 387 | "external_position": "工程师", | ||
| 388 | "external_profile": { | ||
| 389 | "external_corp_name": "企业简称", | ||
| 390 | "wechat_channels": { | ||
| 391 | "nickname": "视频号名称", | ||
| 392 | }, | ||
| 393 | "external_attr": [ | ||
| 394 | { | ||
| 395 | "type": 0, | ||
| 396 | "name": "文本名称", | ||
| 397 | "text": { | ||
| 398 | "value": "文本" | ||
| 399 | } | ||
| 400 | }, | ||
| 401 | { | ||
| 402 | "type": 1, | ||
| 403 | "name": "网页名称", | ||
| 404 | "web": { | ||
| 405 | "url": "http://www.test.com", | ||
| 406 | "title": "标题" | ||
| 407 | } | ||
| 408 | }, | ||
| 409 | { | ||
| 410 | "type": 2, | ||
| 411 | "name": "测试app", | ||
| 412 | "miniprogram": { | ||
| 413 | "appid": "wx8bd80126147dFAKE", | ||
| 414 | "pagepath": "/index", | ||
| 415 | "title": "my miniprogram" | ||
| 416 | } | ||
| 417 | } | ||
| 418 | ] | ||
| 419 | } | ||
| 420 | } | ||
| 421 | |||
| 422 | =head4 参数说明: | ||
| 423 | |||
| 424 | 参数 必须 说明 | ||
| 425 | access_token 是 调用接口凭证 | ||
| 426 | userid 是 成员UserID。对应管理端的帐号,企业内必须唯一。不区分大小写,长度为1~64个字节 | ||
| 427 | name 否 成员名称。长度为1~64个utf8字符 | ||
| 428 | alias 否 别名。长度为1-64个utf8字符 | ||
| 429 | mobile 否 手机号码。企业内必须唯一。若成员已激活企业微信,则需成员自行修改(此情况下该参数被忽略,但不会报错) | ||
| 430 | department 否 成员所属部门id列表,不超过100个 | ||
| 431 | order 否 部门内的排序值,默认为0。当有传入department时有效。数量必须和department一致,数值越大排序越前面。有效的值范围是[0, 2^32) | ||
| 432 | position 否 职务信息。长度为0~128个字符 | ||
| 433 | gender 否 性别。1表示男性,2表示女性 | ||
| 434 | email 否 邮箱。长度不超过64个字节,且为有效的email格式。企业内必须唯一。 | ||
| 435 | biz_mail 否 邮箱。企业邮箱。仅对开通企业邮箱的企业有效。长度6~64个字节,且为有效的企业邮箱格式。企业内必须唯一 | ||
| 436 | telephone 否 座机。由1-32位的纯数字、“-”、“+”或“,”组成 | ||
| 437 | is_leader_in_dept 否 部门负责人字段,个数必须和department一致,表示在所在的部门内是否为负责人。 | ||
| 438 | direct_leader 否 直属上级,可以设置企业范围内成员为直属上级,最多设置5个 | ||
| 439 | avatar_mediaid 否 成员头像的mediaid,通过素材管理接口上传图片获得的mediaid | ||
| 440 | enable 否 启用/禁用成员。1表示启用成员,0表示禁用成员 | ||
| 441 | extattr 否 自定义字段。自定义字段需要先在WEB管理端添加,见扩展属性添加方法,否则忽略未知属性的赋值。 | ||
| 442 | extattr.type 是 属性类型: 0-文本 1-网页 2-小程序 | ||
| 443 | extattr.name 是 属性名称: 需要先确保在管理端有创建该属性,否则会忽略 | ||
| 444 | extattr.text 否 文本类型的属性 | ||
| 445 | extattr.text.value 是 文本属性内容,长度限制64个UTF8字符 | ||
| 446 | extattr.web 否 网页类型的属性,url和title字段要么同时为空表示清除该属性,要么同时不为空 | ||
| 447 | extattr.web.url 是 网页的url,必须包含http或者https头 | ||
| 448 | extattr.web.title 是 网页的展示标题,长度限制12个UTF8字符 | ||
| 449 | external_profile 否 成员对外属性,字段详情见对外属性 | ||
| 450 | external_position 否 对外职务,如果设置了该值,则以此作为对外展示的职务,否则以position来展示。不超过12个汉字 | ||
| 451 | nickname 否 视频号名字(设置后,成员将对外展示该视频号)。须从企业绑定到企业微信的视频号中选择,可在“我的企业”页中查看绑定的视频号 | ||
| 452 | address 否 地址。长度最大128个字符 | ||
| 453 | main_department 否 主部门 | ||
| 454 | |||
| 455 | 特别地,如果userid由系统自动生成,则仅允许修改一次。新值可由new_userid字段指定。 | ||
| 456 | 如果创建时『企业邮箱』为系统默认分配的,则仅允许修改一次,若创建时填入了合规的『企业邮箱』,则无法修改 | ||
| 457 | |||
| 458 | =head3 权限说明 | ||
| 459 | |||
| 460 | 仅通讯录同步助手或第三方通讯录应用可调用。 | ||
| 461 | |||
| 462 | 注意,每个部门下的部门、成员总数不能超过3万个。 | ||
| 463 | |||
| 464 | =head3 RETURN 返回结果 | ||
| 465 | |||
| 466 | { | ||
| 467 | "errcode": 0, | ||
| 468 | "errmsg": "updated" | ||
| 469 | } | ||
| 470 | |||
| 471 | =head3 RETURN 参数说明 | ||
| 472 | |||
| 473 | 参数 说明 | ||
| 474 | errcode 返回码 | ||
| 475 | errmsg 对返回码的文本描述内容 | ||
| 476 | |||
| 477 | =cut | ||
| 478 | |||
| 479 | sub update { | ||
| 480 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 481 | my $access_token = $_[0]; | ||
| 482 | my $json = $_[1]; | ||
| 483 | my $ua = LWP::UserAgent->new; | ||
| 484 | $ua->timeout(30); | ||
| 485 | $ua->env_proxy; | ||
| 486 | |||
| 487 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 488 | if ($response->is_success) { | ||
| 489 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 490 | } | ||
| 491 | |||
| 492 | } | ||
| 493 | return 0; | ||
| 494 | } | ||
| 495 | |||
| 496 | =head2 delete(access_token, userid); | ||
| 497 | |||
| 498 | 删除成员 | ||
| 499 | 最后更新:2021/08/09 | ||
| 500 | |||
| 501 | =head2 SYNOPSIS | ||
| 502 | |||
| 503 | L<https://developer.work.weixin.qq.com/document/path/90198> | ||
| 504 | |||
| 505 | =head3 请求说明: | ||
| 506 | |||
| 507 | =head4 参数说明: | ||
| 508 | |||
| 509 | 参数 必须 说明 | ||
| 510 | access_token 是 调用接口凭证 | ||
| 511 | userid 是 成员UserID。成员UserID。对应管理端的帐号 | ||
| 512 | |||
| 513 | =head3 权限说明 | ||
| 514 | |||
| 515 | 仅通讯录同步助手或第三方通讯录应用可调用。 | ||
| 516 | 若是绑定了腾讯企业邮,则会同时删除邮箱帐号。 | ||
| 517 | |||
| 518 | =head3 RETURN 返回结果 | ||
| 519 | |||
| 520 | { | ||
| 521 | "errcode": 0, | ||
| 522 | "errmsg": "deleted" | ||
| 523 | } | ||
| 524 | |||
| 525 | =head4 RETURN 参数说明 | ||
| 526 | |||
| 527 | 参数 说明 | ||
| 528 | errcode 返回码 | ||
| 529 | errmsg 对返回码的文本描述内容 | ||
| 530 | |||
| 531 | =cut | ||
| 532 | |||
| 533 | sub delete { | ||
| 534 | if ( @_ && $_[0] && $_[1] ) { | ||
| 535 | my $access_token = $_[0]; | ||
| 536 | my $userid = $_[1]; | ||
| 537 | my $ua = LWP::UserAgent->new; | ||
| 538 | $ua->timeout(30); | ||
| 539 | $ua->env_proxy; | ||
| 540 | |||
| 541 | my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token=$access_token&userid=$userid"); | ||
| 542 | if ($response->is_success) { | ||
| 543 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 544 | } | ||
| 545 | |||
| 546 | } | ||
| 547 | return 0; | ||
| 548 | } | ||
| 549 | |||
| 550 | =head2 batchdelete(access_token, hash); | ||
| 551 | |||
| 552 | 批量删除成员 | ||
| 553 | 最后更新:2019/06/13 | ||
| 554 | |||
| 555 | =head2 SYNOPSIS | ||
| 556 | |||
| 557 | L<https://developer.work.weixin.qq.com/document/path/90199> | ||
| 558 | |||
| 559 | =head3 请求说明: | ||
| 560 | |||
| 561 | =head4 请求包结构体为: | ||
| 562 | |||
| 563 | { | ||
| 564 | "useridlist": ["zhangsan", "lisi"] | ||
| 565 | } | ||
| 566 | |||
| 567 | =head4 参数说明: | ||
| 568 | |||
| 569 | 参数 必须 说明 | ||
| 570 | access_token 是 调用接口凭证 | ||
| 571 | useridlist 是 成员UserID列表。对应管理端的帐号。最多支持200个。若存在无效UserID,直接返回错误 | ||
| 572 | |||
| 573 | =head3 权限说明 | ||
| 574 | |||
| 575 | 仅通讯录同步助手或第三方通讯录应用可调用。 | ||
| 576 | |||
| 577 | =head3 RETURN 返回结果 | ||
| 578 | |||
| 579 | { | ||
| 580 | "errcode": 0, | ||
| 581 | "errmsg": "deleted" | ||
| 582 | } | ||
| 583 | |||
| 584 | =head3 RETURN 参数说明 | ||
| 585 | |||
| 586 | 参数 说明 | ||
| 587 | errcode 返回码 | ||
| 588 | errmsg 对返回码的文本描述内容 | ||
| 589 | |||
| 590 | =cut | ||
| 591 | |||
| 592 | sub batchdelete { | ||
| 593 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 594 | my $access_token = $_[0]; | ||
| 595 | my $json = $_[1]; | ||
| 596 | my $ua = LWP::UserAgent->new; | ||
| 597 | $ua->timeout(30); | ||
| 598 | $ua->env_proxy; | ||
| 599 | |||
| 600 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 601 | if ($response->is_success) { | ||
| 602 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 603 | } | ||
| 604 | |||
| 605 | } | ||
| 606 | return 0; | ||
| 607 | } | ||
| 608 | |||
| 609 | =head2 simplelist(access_token, department_id); | ||
| 610 | |||
| 611 | 获取部门成员 | ||
| 612 | 最后更新:2022/08/22 | ||
| 613 | |||
| 614 | =head2 SYNOPSIS | ||
| 615 | |||
| 616 | L<https://work.weixin.qq.com/api/doc/90000/90135/90200> | ||
| 617 | |||
| 618 | =head3 请求说明: | ||
| 619 | |||
| 620 | 企业通讯录安全特别重要,企业微信将持续升级加固通讯录接口的安全机制,以下是关键的变更点: | ||
| 621 | |||
| 622 | 【重要】从2022年8月15日10点开始,“企业管理后台 - 管理工具 - 通讯录同步”的新增IP将不能再调用此接口,企业可通过「获取成员ID列表」和「获取部门ID列表」接口获取userid和部门ID列表。查看调整详情 | ||
| 623 | |||
| 624 | =head4 参数说明: | ||
| 625 | |||
| 626 | 参数 必须 说明 | ||
| 627 | access_token 是 调用接口凭证 | ||
| 628 | department_id 是 获取的部门id | ||
| 629 | |||
| 630 | 如需获取该部门及其子部门的所有成员,需先获取该部门下的子部门,然后再获取子部门下的部门成员,逐层递归获取。 | ||
| 631 | |||
| 632 | =head3 权限说明 | ||
| 633 | |||
| 634 | 应用须拥有指定部门的查看权限。 | ||
| 635 | |||
| 636 | =head3 RETURN 返回结果 | ||
| 637 | |||
| 638 | { | ||
| 639 | "errcode": 0, | ||
| 640 | "errmsg": "ok", | ||
| 641 | "userlist": [ | ||
| 642 | { | ||
| 643 | "userid": "zhangsan", | ||
| 644 | "name": "张三", | ||
| 645 | "department": [1, 2], | ||
| 646 | "open_userid": "xxxxxx" | ||
| 647 | } | ||
| 648 | ] | ||
| 649 | } | ||
| 650 | |||
| 651 | =head4 RETURN 参数说明 | ||
| 652 | |||
| 653 | 参数 说明 | ||
| 654 | errcode 返回码 | ||
| 655 | errmsg 对返回码的文本描述内容 | ||
| 656 | userlist 成员列表 | ||
| 657 | userid 成员UserID。对应管理端的帐号 | ||
| 658 | name 成员名称,此字段从2019年12月30日起,对新创建第三方应用不再返回,2020年6月30日起,对所有历史第三方应用不再返回,后续第三方仅通讯录应用可获取,第三方页面需要通过通讯录展示组件来展示名字 | ||
| 659 | department 成员所属部门列表。列表项为部门ID,32位整型 | ||
| 660 | open_userid 全局唯一。对于同一个服务商,不同应用获取到企业内同一个成员的open_userid是相同的,最多64个字节。仅第三方应用可获取 | ||
| 661 | |||
| 662 | =cut | ||
| 663 | |||
| 664 | sub simplelist { | ||
| 665 | if ( @_ && $_[0] && $_[1] ) { | ||
| 666 | my $access_token = $_[0]; | ||
| 667 | my $department_id = $_[1]; | ||
| 668 | my $ua = LWP::UserAgent->new; | ||
| 669 | $ua->timeout(30); | ||
| 670 | $ua->env_proxy; | ||
| 671 | |||
| 672 | my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=$access_token&department_id=$department_id"); | ||
| 673 | if ($response->is_success) { | ||
| 674 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 675 | } | ||
| 676 | |||
| 677 | } | ||
| 678 | return 0; | ||
| 679 | } | ||
| 680 | |||
| 681 | =head2 list(access_token, department_id); | ||
| 682 | |||
| 683 | 获取部门成员详情 | ||
| 684 | 最后更新:2023/09/07 | ||
| 685 | |||
| 686 | =head2 SYNOPSIS | ||
| 687 | |||
| 688 | L<https://developer.work.weixin.qq.com/document/path/90201> | ||
| 689 | |||
| 690 | =head3 请求说明: | ||
| 691 | |||
| 692 | 应用只能获取可见范围内的成员信息,且每种应用获取的字段有所不同,在返回结果说明中会逐个说明。企业通讯录安全特别重要,企业微信持续升级加固通讯录接口的安全机制,以下是关键的变更点: | ||
| 693 | |||
| 694 | 从2022年6月20号20点开始,除通讯录同步以外的基础应用(如客户联系、微信客服、会话存档、日程等),以及新创建的自建应用与代开发应用,调用该接口时,不再返回以下字段:头像、性别、手机、邮箱、企业邮箱、员工个人二维码、地址,应用需要通过oauth2手工授权的方式获取管理员与员工本人授权的字段。 | ||
| 695 | |||
| 696 | 【重要】从2022年8月15日10点开始,“企业管理后台 - 管理工具 - 通讯录同步”的新增IP将不能再调用此接口,企业可通过「获取成员ID列表」和「获取部门ID列表」接口获取userid和部门ID列表。查看调整详情。 | ||
| 697 | |||
| 698 | =head4 参数说明: | ||
| 699 | |||
| 700 | 参数 必须 说明 | ||
| 701 | access_token 是 调用接口凭证 | ||
| 702 | department_id 是 获取的部门id | ||
| 703 | |||
| 704 | 如需获取该部门及其子部门的所有成员,需先获取该部门下的子部门,然后再获取子部门下的部门成员,逐层递归获取。 | ||
| 705 | |||
| 706 | =head3 权限说明 | ||
| 707 | |||
| 708 | 应用须拥有指定部门的查看权限。 | ||
| 709 | |||
| 710 | =head3 RETURN 返回结果 | ||
| 711 | |||
| 712 | { | ||
| 713 | "errcode": 0, | ||
| 714 | "errmsg": "ok", | ||
| 715 | "userlist": [{ | ||
| 716 | "userid": "zhangsan", | ||
| 717 | "name": "李四", | ||
| 718 | "department": [1, 2], | ||
| 719 | "order": [1, 2], | ||
| 720 | "position": "后台工程师", | ||
| 721 | "mobile": "13800000000", | ||
| 722 | "gender": "1", | ||
| 723 | "email": "zhangsan@gzdev.com", | ||
| 724 | "biz_mail":"zhangsan@qyycs2.wecom.work", | ||
| 725 | "is_leader_in_dept": [1, 0], | ||
| 726 | "direct_leader":["lisi"], | ||
| 727 | "avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0", | ||
| 728 | "thumb_avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/100", | ||
| 729 | "telephone": "020-123456", | ||
| 730 | "alias": "jackzhang", | ||
| 731 | "status": 1, | ||
| 732 | "address": "广州市海珠区新港中路", | ||
| 733 | "english_name" : "jacky", | ||
| 734 | "open_userid": "xxxxxx", | ||
| 735 | "main_department": 1, | ||
| 736 | "extattr": { | ||
| 737 | "attrs": [ | ||
| 738 | { | ||
| 739 | "type": 0, | ||
| 740 | "name": "文本名称", | ||
| 741 | "text": { | ||
| 742 | "value": "文本" | ||
| 743 | } | ||
| 744 | }, | ||
| 745 | { | ||
| 746 | "type": 1, | ||
| 747 | "name": "网页名称", | ||
| 748 | "web": { | ||
| 749 | "url": "http://www.test.com", | ||
| 750 | "title": "标题" | ||
| 751 | } | ||
| 752 | } | ||
| 753 | ] | ||
| 754 | }, | ||
| 755 | "qr_code": "https://open.work.weixin.qq.com/wwopen/userQRCode?vcode=xxx", | ||
| 756 | "external_position": "产品经理", | ||
| 757 | "external_profile": { | ||
| 758 | "external_corp_name": "企业简称", | ||
| 759 | "wechat_channels": { | ||
| 760 | "nickname": "视频号名称", | ||
| 761 | "status": 1 | ||
| 762 | }, | ||
| 763 | "external_attr": [{ | ||
| 764 | "type": 0, | ||
| 765 | "name": "文本名称", | ||
| 766 | "text": { | ||
| 767 | "value": "文本" | ||
| 768 | } | ||
| 769 | }, | ||
| 770 | { | ||
| 771 | "type": 1, | ||
| 772 | "name": "网页名称", | ||
| 773 | "web": { | ||
| 774 | "url": "http://www.test.com", | ||
| 775 | "title": "标题" | ||
| 776 | } | ||
| 777 | }, | ||
| 778 | { | ||
| 779 | "type": 2, | ||
| 780 | "name": "测试app", | ||
| 781 | "miniprogram": { | ||
| 782 | "appid": "wx8bd80126147dFAKE", | ||
| 783 | "pagepath": "/index", | ||
| 784 | "title": "miniprogram" | ||
| 785 | } | ||
| 786 | } | ||
| 787 | ] | ||
| 788 | } | ||
| 789 | }] | ||
| 790 | } | ||
| 791 | |||
| 792 | =head4 RETURN 参数说明 | ||
| 793 | |||
| 794 | 参数 说明 | ||
| 795 | errcode 返回码 | ||
| 796 | errmsg 对返回码的文本描述内容 | ||
| 797 | userlist 成员列表 | ||
| 798 | userid 成员UserID。对应管理端的帐号 | ||
| 799 | name 成员名称;第三方不可获取,调用时返回userid以代替name;代开发自建应用需要管理员授权才返回;对于非第三方创建的成员,第三方通讯录应用也不可获取;未返回名称的情况需要通过通讯录展示组件来展示名字 | ||
| 800 | mobile 手机号码,代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 801 | department 成员所属部门id列表,仅返回该应用有查看权限的部门id。对授权了“组织架构信息”的第三方应用,返回成员所属的全部部门id列表 | ||
| 802 | order 部门内的排序值,默认为0。数量必须和department一致,数值越大排序越前面。值范围是[0, 2^32) | ||
| 803 | position 职务信息;代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 804 | gender 性别。0表示未定义,1表示男性,2表示女性。第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段。注:不可获取指返回值为0 | ||
| 805 | email 邮箱,代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 806 | biz_mail 企业邮箱,代开发自建应用不返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 807 | is_leader_in_dept 表示在所在的部门内是否为部门负责人。0-否;1-是。是一个列表,数量必须与department一致。第三方通讯录应用或者授权了“组织架构信息-应用可获取企业的部门组织架构信息-部门负责人”权限的第三方应用可获取;对于非第三方创建的成员,第三方通讯录应用不可获取;上游企业不可获取下游企业成员该字段 | ||
| 808 | direct_leader 直属上级UserID,返回在应用可见范围内的直属上级列表,最多有五个直属上级;第三方通讯录应用或者授权了“组织架构信息-应用可获取可见范围内成员组织架构信息-直属上级”权限的第三方应用可获取;对于非第三方创建的成员,第三方通讯录应用不可获取;上游企业不可获取下游企业成员该字段 | ||
| 809 | avatar 头像url。 第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 810 | thumb_avatar 头像缩略图url。第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 811 | telephone 座机。代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 812 | alias 别名;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 813 | extattr 扩展属性,代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 814 | status 激活状态: 1=已激活,2=已禁用,4=未激活,5=退出企业。 | ||
| 815 | 已激活代表已激活企业微信或已关注微信插件(原企业号)。未激活代表既未激活企业微信又未关注微信插件(原企业号)。 | ||
| 816 | qr_code 员工个人二维码,扫描可添加为外部联系人(注意返回的是一个url,可在浏览器上打开该url以展示二维码);第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 817 | external_profile 成员对外属性,字段详情见对外属性;代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 818 | external_position 对外职务,如果设置了该值,则以此作为对外展示的职务,否则以position来展示。代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 819 | address 地址。代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 | ||
| 820 | open_userid 全局唯一。对于同一个服务商,不同应用获取到企业内同一个成员的open_userid是相同的,最多64个字节。仅第三方应用可获取 | ||
| 821 | main_department 主部门,仅当应用对主部门有查看权限时返回。 | ||
| 822 | |||
| 823 | =cut | ||
| 824 | |||
| 825 | sub list { | ||
| 826 | if ( @_ && $_[0] && $_[1] ) { | ||
| 827 | my $access_token = $_[0]; | ||
| 828 | my $department_id = $_[1]; | ||
| 829 | my $ua = LWP::UserAgent->new; | ||
| 830 | $ua->timeout(30); | ||
| 831 | $ua->env_proxy; | ||
| 832 | |||
| 833 | my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=$access_token&department_id=$department_id"); | ||
| 834 | if ($response->is_success) { | ||
| 835 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 836 | } | ||
| 837 | |||
| 838 | } | ||
| 839 | return 0; | ||
| 840 | } | ||
| 841 | |||
| 842 | =head2 convert_to_openid(access_token, hash); | ||
| 843 | |||
| 844 | userid与openid互换: | ||
| 845 | 最后更新:2022/01/20 | ||
| 846 | |||
| 847 | userid转openid | ||
| 848 | |||
| 849 | =head2 SYNOPSIS | ||
| 850 | |||
| 851 | L<https://developer.work.weixin.qq.com/document/path/90202> | ||
| 852 | |||
| 853 | =head3 请求说明: | ||
| 854 | |||
| 855 | 该接口使用场景为企业支付,在使用企业红包和向员工付款时,需要自行将企业微信的userid转成openid。 | ||
| 856 | |||
| 857 | 注:需要成员使用微信登录企业微信或者关注微工作台(原企业号)才能转成openid; | ||
| 858 | |||
| 859 | 如果是外部联系人,请使用外部联系人openid转换转换openid | ||
| 860 | |||
| 861 | =head4 请求包结构体为: | ||
| 862 | |||
| 863 | { | ||
| 864 | "userid": "zhangsan" | ||
| 865 | } | ||
| 866 | |||
| 867 | =head4 参数说明: | ||
| 868 | |||
| 869 | 参数 必须 说明 | ||
| 870 | access_token 是 调用接口凭证 | ||
| 871 | userid 是 企业内的成员id | ||
| 872 | |||
| 873 | =head3 权限说明 | ||
| 874 | |||
| 875 | 成员必须处于应用的可见范围内 | ||
| 876 | |||
| 877 | =head3 RETURN 返回结果 | ||
| 878 | |||
| 879 | { | ||
| 880 | "errcode": 0, | ||
| 881 | "errmsg": "ok", | ||
| 882 | "openid": "oDjGHs-1yCnGrRovBj2yHij5JAAA" | ||
| 883 | } | ||
| 884 | |||
| 885 | =head3 RETURN 参数说明 | ||
| 886 | |||
| 887 | 参数 说明 | ||
| 888 | errcode 返回码 | ||
| 889 | errmsg 对返回码的文本描述内容 | ||
| 890 | openid 企业微信成员userid对应的openid | ||
| 891 | |||
| 892 | =cut | ||
| 893 | |||
| 894 | sub convert_to_openid { | ||
| 895 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 896 | my $access_token = $_[0]; | ||
| 897 | my $json = $_[1]; | ||
| 898 | my $ua = LWP::UserAgent->new; | ||
| 899 | $ua->timeout(30); | ||
| 900 | $ua->env_proxy; | ||
| 901 | |||
| 902 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 903 | if ($response->is_success) { | ||
| 904 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 905 | } | ||
| 906 | |||
| 907 | } | ||
| 908 | return 0; | ||
| 909 | } | ||
| 910 | |||
| 911 | =head2 convert_to_userid(access_token, hash); | ||
| 912 | |||
| 913 | userid与openid互换: openid转userid | ||
| 914 | |||
| 915 | =head2 SYNOPSIS | ||
| 916 | |||
| 917 | L<https://developer.work.weixin.qq.com/document/path/90202> | ||
| 918 | |||
| 919 | =head3 请求说明: | ||
| 920 | |||
| 921 | 该接口主要应用于使用企业支付之后的结果查询。 | ||
| 922 | |||
| 923 | 开发者需要知道某个结果事件的openid对应企业微信内成员的信息时,可以通过调用该接口进行转换查询。 | ||
| 924 | |||
| 925 | =head4 请求包结构体为: | ||
| 926 | |||
| 927 | { | ||
| 928 | "openid": "oDjGHs-1yCnGrRovBj2yHij5JAAA" | ||
| 929 | } | ||
| 930 | |||
| 931 | =head4 参数说明: | ||
| 932 | |||
| 933 | 参数 必须 说明 | ||
| 934 | access_token 是 调用接口凭证 | ||
| 935 | openid 是 在使用企业支付之后,返回结果的openid | ||
| 936 | |||
| 937 | =head3 权限说明 | ||
| 938 | |||
| 939 | 管理组需对openid对应的企业微信成员有查看权限。 | ||
| 940 | |||
| 941 | =head3 RETURN 返回结果 | ||
| 942 | |||
| 943 | { | ||
| 944 | "errcode": 0, | ||
| 945 | "errmsg": "ok", | ||
| 946 | "userid": "zhangsan" | ||
| 947 | } | ||
| 948 | |||
| 949 | =head3 RETURN 参数说明 | ||
| 950 | |||
| 951 | 参数 说明 | ||
| 952 | errcode 返回码 | ||
| 953 | errmsg 对返回码的文本描述内容 | ||
| 954 | userid 该openid在企业微信对应的成员userid | ||
| 955 | |||
| 956 | =cut | ||
| 957 | |||
| 958 | sub convert_to_userid { | ||
| 959 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 960 | my $access_token = $_[0]; | ||
| 961 | my $json = $_[1]; | ||
| 962 | my $ua = LWP::UserAgent->new; | ||
| 963 | $ua->timeout(30); | ||
| 964 | $ua->env_proxy; | ||
| 965 | |||
| 966 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_userid?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 967 | if ($response->is_success) { | ||
| 968 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 969 | } | ||
| 970 | |||
| 971 | } | ||
| 972 | return 0; | ||
| 973 | } | ||
| 974 | |||
| 975 | =head2 authsucc(access_token, userid); | ||
| 976 | |||
| 977 | 二次验证 | ||
| 978 | 最后更新:2023/11/15 | ||
| 979 | |||
| 980 | =head2 SYNOPSIS | ||
| 981 | |||
| 982 | L<https://work.weixin.qq.com/api/doc/90000/90135/90203> | ||
| 983 | |||
| 984 | =head3 请求说明: | ||
| 985 | |||
| 986 | 此接口可以满足安全性要求高的企业进行成员加入验证。开启二次验证后,用户加入企业时需要跳转企业自定义的页面进行验证。 | ||
| 987 | |||
| 988 | 企业在开启二次验证时,必须在管理端填写企业二次验证页面的url。 | ||
| 989 | |||
| 990 | 当成员登录企业微信或关注微工作台(原企业号)加入企业时,会自动跳转到企业的验证页面。在跳转到企业的验证页面时,会带上如下参数:code=CODE。 | ||
| 991 | |||
| 992 | 企业收到code后,使用“通讯录同步助手”调用接口“根据code获取成员信息”获取成员的userid。然后在验证成员信息成功后,调用如下接口即可让成员成功加入企业。 | ||
| 993 | |||
| 994 | =head4 参数说明: | ||
| 995 | |||
| 996 | 参数 必须 说明 | ||
| 997 | access_token 是 调用接口凭证 | ||
| 998 | userid 是 成员UserID。对应管理端的帐号 | ||
| 999 | |||
| 1000 | =head3 权限说明 | ||
| 1001 | |||
| 1002 | =head3 RETURN 返回结果 | ||
| 1003 | |||
| 1004 | { | ||
| 1005 | "errcode": 0, | ||
| 1006 | "errmsg": "ok" | ||
| 1007 | } | ||
| 1008 | |||
| 1009 | =head4 RETURN 参数说明 | ||
| 1010 | |||
| 1011 | 参数 说明 | ||
| 1012 | errcode 返回码 | ||
| 1013 | errmsg 对返回码的文本描述内容 | ||
| 1014 | |||
| 1015 | =cut | ||
| 1016 | |||
| 1017 | sub authsucc { | ||
| 1018 | if ( @_ && $_[0] && $_[1] ) { | ||
| 1019 | my $access_token = $_[0]; | ||
| 1020 | my $userid = $_[1]; | ||
| 1021 | my $ua = LWP::UserAgent->new; | ||
| 1022 | $ua->timeout(30); | ||
| 1023 | $ua->env_proxy; | ||
| 1024 | |||
| 1025 | my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/user/authsucc?access_token=$access_token&userid=$userid"); | ||
| 1026 | if ($response->is_success) { | ||
| 1027 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 1028 | } | ||
| 1029 | |||
| 1030 | } | ||
| 1031 | return 0; | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | =head2 get_active_stat(access_token, hash); | ||
| 1035 | |||
| 1036 | 获取企业活跃成员数 | ||
| 1037 | |||
| 1038 | =head2 SYNOPSIS | ||
| 1039 | |||
| 1040 | L<https://developer.work.weixin.qq.com/document/path/92714> | ||
| 1041 | |||
| 1042 | =head3 请求说明: | ||
| 1043 | |||
| 1044 | =head4 请求包结构体为: | ||
| 1045 | |||
| 1046 | { | ||
| 1047 | "date": "2020-03-27" | ||
| 1048 | } | ||
| 1049 | |||
| 1050 | =head4 参数说明: | ||
| 1051 | |||
| 1052 | 参数 必须 说明 | ||
| 1053 | access_token 是 调用接口凭证。获取方法查看“获取access_token” | ||
| 1054 | date 是 具体某天的活跃人数,最长支持获取30天前数据 | ||
| 1055 | |||
| 1056 | =head3 权限说明 | ||
| 1057 | |||
| 1058 | 仅通讯录同步助手可调用。 | ||
| 1059 | |||
| 1060 | =head3 RETURN 返回结果 | ||
| 1061 | |||
| 1062 | { | ||
| 1063 | "errcode": 0, | ||
| 1064 | "errmsg": "ok", | ||
| 1065 | "active_cnt": 100 | ||
| 1066 | } | ||
| 1067 | |||
| 1068 | =head3 RETURN 参数说明 | ||
| 1069 | |||
| 1070 | 参数 说明 | ||
| 1071 | errcode 返回码 | ||
| 1072 | errmsg 对返回码的文本描述内容 | ||
| 1073 | active_cnt 活跃成员数 | ||
| 1074 | |||
| 1075 | =cut | ||
| 1076 | |||
| 1077 | sub get_active_stat { | ||
| 1078 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 1079 | my $access_token = $_[0]; | ||
| 1080 | my $json = $_[1]; | ||
| 1081 | my $ua = LWP::UserAgent->new; | ||
| 1082 | $ua->timeout(30); | ||
| 1083 | $ua->env_proxy; | ||
| 1084 | |||
| 1085 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/user/get_active_stat?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 1086 | if ($response->is_success) { | ||
| 1087 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 1088 | } | ||
| 1089 | |||
| 1090 | } | ||
| 1091 | return 0; | ||
| 1092 | } | ||
| 1093 | |||
| 1094 | =head2 getuserid(access_token, hash); | ||
| 1095 | |||
| 1096 | 手机号获取userid | ||
| 1097 | 最后更新:2022/08/16 | ||
| 1098 | |||
| 1099 | =head2 SYNOPSIS | ||
| 1100 | |||
| 1101 | L<https://developer.work.weixin.qq.com/document/path/95402> | ||
| 1102 | |||
| 1103 | =head3 请求说明: | ||
| 1104 | |||
| 1105 | 通过手机号获取其所对应的userid。 | ||
| 1106 | |||
| 1107 | =head4 请求包结构体为: | ||
| 1108 | |||
| 1109 | { | ||
| 1110 | "mobile": "13430388888" | ||
| 1111 | } | ||
| 1112 | |||
| 1113 | =head4 参数说明: | ||
| 1114 | |||
| 1115 | 参数 必须 说明 | ||
| 1116 | access_token 是 调用接口凭证,授权企业的token(通过获取企业凭证获取)或上游获取的下游企业的token(通过获取下级/下游企业的access_token) | ||
| 1117 | mobile 是 手机号码。长度为5~32个字节 | ||
| 1118 | |||
| 1119 | =head3 权限说明 | ||
| 1120 | |||
| 1121 | 应用须拥有指定成员的查看权限。 | ||
| 1122 | |||
| 1123 | =head3 RETURN 返回结果 | ||
| 1124 | |||
| 1125 | { | ||
| 1126 | "errcode": 0, | ||
| 1127 | "errmsg": "ok", | ||
| 1128 | "userid": "zhangsan" | ||
| 1129 | } | ||
| 1130 | |||
| 1131 | =head3 RETURN 参数说明 | ||
| 1132 | |||
| 1133 | 参数 说明 | ||
| 1134 | errcode 返回码 | ||
| 1135 | errmsg 对返回码的文本描述内容 | ||
| 1136 | userid 成员UserID。对应管理端的帐号,企业内必须唯一。不区分大小写,长度为1~64个字节。注意:第三方应用获取的值是密文的userid | ||
| 1137 | |||
| 1138 | =head3 更多说明 | ||
| 1139 | |||
| 1140 | 请确保手机号的正确性,若出错的次数超出企业规模人数的20%,会导致1天不可调用。 | ||
| 1141 | |||
| 1142 | =cut | ||
| 1143 | |||
| 1144 | sub getuserid { | ||
| 1145 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 1146 | my $access_token = $_[0]; | ||
| 1147 | my $json = $_[1]; | ||
| 1148 | my $ua = LWP::UserAgent->new; | ||
| 1149 | $ua->timeout(30); | ||
| 1150 | $ua->env_proxy; | ||
| 1151 | |||
| 1152 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/user/getuserid?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 1153 | if ($response->is_success) { | ||
| 1154 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 1155 | } | ||
| 1156 | |||
| 1157 | } | ||
| 1158 | return 0; | ||
| 1159 | } | ||
| 1160 | |||
| 1161 | =head2 get_userid_by_email(access_token, hash); | ||
| 1162 | |||
| 1163 | 邮箱获取userid | ||
| 1164 | 最后更新:2022/07/19 | ||
| 1165 | |||
| 1166 | =head2 SYNOPSIS | ||
| 1167 | |||
| 1168 | L<https://developer.work.weixin.qq.com/document/path/95895> | ||
| 1169 | |||
| 1170 | =head3 请求说明: | ||
| 1171 | |||
| 1172 | 通过邮箱获取其所对应的userid。 | ||
| 1173 | |||
| 1174 | =head4 请求包结构体为: | ||
| 1175 | |||
| 1176 | { | ||
| 1177 | "email":"12345@qq.com", | ||
| 1178 | "email_type":1 | ||
| 1179 | } | ||
| 1180 | |||
| 1181 | =head4 参数说明: | ||
| 1182 | |||
| 1183 | 参数 必须 说明 | ||
| 1184 | access_token 是 调用接口凭证,授权企业的token(通过获取企业凭证获取)或上游获取的下游企业的token(通过获取下级/下游企业的access_token) | ||
| 1185 | email 是 邮箱 | ||
| 1186 | email_type 否 邮箱类型:1-企业邮箱(默认);2-个人邮箱 | ||
| 1187 | |||
| 1188 | =head3 权限说明 | ||
| 1189 | |||
| 1190 | 应用须拥有指定成员的查看权限。 | ||
| 1191 | |||
| 1192 | =head3 RETURN 返回结果 | ||
| 1193 | |||
| 1194 | { | ||
| 1195 | "errcode": 0, | ||
| 1196 | "errmsg": "ok", | ||
| 1197 | "userid": "zhangsan" | ||
| 1198 | } | ||
| 1199 | |||
| 1200 | =head3 RETURN 参数说明 | ||
| 1201 | |||
| 1202 | 参数 说明 | ||
| 1203 | errcode 返回码 | ||
| 1204 | errmsg 对返回码的文本描述内容 | ||
| 1205 | userid 成员UserID。注意:已升级openid的代开发或第三方,获取的是密文userid | ||
| 1206 | |||
| 1207 | =head3 更多说明 | ||
| 1208 | |||
| 1209 | 请确保邮箱的正确性,若出错的次数较多,会导致1天不可调用。(限制阈值取决于安装企业的员工规模) | ||
| 1210 | |||
| 1211 | =cut | ||
| 1212 | |||
| 1213 | sub get_userid_by_email { | ||
| 1214 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 1215 | my $access_token = $_[0]; | ||
| 1216 | my $json = $_[1]; | ||
| 1217 | my $ua = LWP::UserAgent->new; | ||
| 1218 | $ua->timeout(30); | ||
| 1219 | $ua->env_proxy; | ||
| 1220 | |||
| 1221 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/user/get_userid_by_email?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 1222 | if ($response->is_success) { | ||
| 1223 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 1224 | } | ||
| 1225 | |||
| 1226 | } | ||
| 1227 | return 0; | ||
| 1228 | } | ||
| 1229 | |||
| 1230 | =head2 list_id(access_token, hash); | ||
| 1231 | |||
| 1232 | 获取成员ID列表 | ||
| 1233 | 最后更新:2022/08/09 | ||
| 1234 | |||
| 1235 | =head2 SYNOPSIS | ||
| 1236 | |||
| 1237 | L<https://developer.work.weixin.qq.com/document/path/96067> | ||
| 1238 | |||
| 1239 | =head3 请求说明: | ||
| 1240 | |||
| 1241 | 获取企业成员的userid与对应的部门ID列表,预计于2022年8月8号发布。若需要获取其他字段,参见「适配建议」。 | ||
| 1242 | |||
| 1243 | =head4 请求包结构体为: | ||
| 1244 | |||
| 1245 | { | ||
| 1246 | "cursor": "xxxxxxx", | ||
| 1247 | "limit": 10000 | ||
| 1248 | } | ||
| 1249 | |||
| 1250 | =head4 参数说明: | ||
| 1251 | |||
| 1252 | 参数 必须 说明 | ||
| 1253 | access_token 是 调用接口凭证,授权企业的token(通过获取企业凭证获取)或上游获取的下游企业的token(通过获取下级/下游企业的access_token) | ||
| 1254 | email 是 邮箱 | ||
| 1255 | email_type 否 邮箱类型:1-企业邮箱(默认);2-个人邮箱 | ||
| 1256 | |||
| 1257 | =head3 权限说明 | ||
| 1258 | |||
| 1259 | 应用须拥有指定成员的查看权限。 | ||
| 1260 | =head4 参数说明: | ||
| 1261 | |||
| 1262 | 参数 必须 说明 | ||
| 1263 | access_token 是 调用接口凭证 | ||
| 1264 | cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用不填 | ||
| 1265 | limit 否 分页,预期请求的数据量,取值范围 1 ~ 10000 | ||
| 1266 | |||
| 1267 | =head3 权限说明 | ||
| 1268 | |||
| 1269 | 仅支持通过“通讯录同步secret”调用。 | ||
| 1270 | |||
| 1271 | =head3 RETURN 返回结果 | ||
| 1272 | |||
| 1273 | { | ||
| 1274 | "errcode": 0, | ||
| 1275 | "errmsg": "ok", | ||
| 1276 | "next_cursor": "aaaaaaaaa", | ||
| 1277 | "dept_user": [ | ||
| 1278 | { | ||
| 1279 | "userid": "zhangsan", | ||
| 1280 | "department": 1 | ||
| 1281 | }, | ||
| 1282 | { | ||
| 1283 | "userid": "zhangsan", | ||
| 1284 | "department": 2 | ||
| 1285 | }, | ||
| 1286 | { | ||
| 1287 | "userid": "lisi", | ||
| 1288 | "department": 2 | ||
| 1289 | } | ||
| 1290 | } | ||
| 1291 | |||
| 1292 | =head4 RETURN 参数说明 | ||
| 1293 | |||
| 1294 | 参数 说明 | ||
| 1295 | errcode 返回码 | ||
| 1296 | errmsg 对返回码的文本描述内容 | ||
| 1297 | next_cursor 分页游标,下次请求时填写以获取之后分页的记录。如果该字段返回空则表示已没有更多数据 | ||
| 1298 | dept_user 用户-部门关系列表 | ||
| 1299 | userid 用户userid,当用户在多个部门下时会有多条记录 | ||
| 1300 | department 用户所属部门 | ||
| 1301 | |||
| 1302 | =cut | ||
| 1303 | |||
| 1304 | sub list_id { | ||
| 1305 | if ( @_ && $_[0] && $_[1] ) { | ||
| 1306 | my $access_token = $_[0]; | ||
| 1307 | my $json = $_[1]; | ||
| 1308 | my $ua = LWP::UserAgent->new; | ||
| 1309 | $ua->timeout(30); | ||
| 1310 | $ua->env_proxy; | ||
| 1311 | |||
| 1312 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/user/list_id?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 1313 | if ($response->is_success) { | ||
| 1314 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 1315 | } | ||
| 1316 | |||
| 1317 | } | ||
| 1318 | return 0; | ||
| 1319 | } | ||
| 1320 | |||
| 1321 | =head2 getuserinfo(access_token, code); | ||
| 1322 | |||
| 1323 | 获取访问用户身份 | ||
| 1324 | |||
| 1325 | =head2 SYNOPSIS | ||
| 1326 | |||
| 1327 | L<https://work.weixin.qq.com/api/doc/90000/90135/91023> | ||
| 1328 | |||
| 1329 | =head3 请求说明: | ||
| 1330 | |||
| 1331 | 该接口用于根据code获取成员信息 | ||
| 1332 | |||
| 1333 | =head4 参数说明: | ||
| 1334 | |||
| 1335 | 参数 必须 说明 | ||
| 1336 | access_token 是 调用接口凭证 | ||
| 1337 | code 是 通过成员授权获取到的code,最大为512字节。每次成员授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。 | ||
| 1338 | |||
| 1339 | =head3 权限说明 | ||
| 1340 | |||
| 1341 | 跳转的域名须完全匹配access_token对应应用的可信域名,否则会返回50001错误。 | ||
| 1342 | |||
| 1343 | =head3 RETURN 返回结果a | ||
| 1344 | |||
| 1345 | { | ||
| 1346 | "errcode": 0, | ||
| 1347 | "errmsg": "ok", | ||
| 1348 | "UserId":"USERID", | ||
| 1349 | "DeviceId":"DEVICEID" | ||
| 1350 | } | ||
| 1351 | |||
| 1352 | =head4 RETURN 参数说明a | ||
| 1353 | |||
| 1354 | 参数 说明 | ||
| 1355 | errcode 返回码 | ||
| 1356 | errmsg 对返回码的文本描述内容 | ||
| 1357 | UserId 成员UserID。若需要获得用户详情信息,可调用通讯录接口:读取成员 | ||
| 1358 | DeviceId 手机设备号(由企业微信在安装时随机生成,删除重装会改变,升级不受影响) | ||
| 1359 | |||
| 1360 | =head3 RETURN 返回结果b | ||
| 1361 | |||
| 1362 | { | ||
| 1363 | "errcode": 0, | ||
| 1364 | "errmsg": "ok", | ||
| 1365 | "OpenId":"OPENID", | ||
| 1366 | "DeviceId":"DEVICEID" | ||
| 1367 | } | ||
| 1368 | |||
| 1369 | =head4 RETURN 参数说明b | ||
| 1370 | |||
| 1371 | 参数 说明 | ||
| 1372 | errcode 返回码 | ||
| 1373 | errmsg 对返回码的文本描述内容 | ||
| 1374 | OpenId 非企业成员的标识,对当前企业唯一 | ||
| 1375 | DeviceId 手机设备号(由企业微信在安装时随机生成,删除重装会改变,升级不受影响) | ||
| 1376 | |||
| 1377 | =cut | ||
| 1378 | |||
| 1379 | sub getuserinfo { | ||
| 1380 | if ( @_ && $_[0] && $_[1] ) { | ||
| 1381 | my $access_token = $_[0]; | ||
| 1382 | my $json = $_[1]; | ||
| 1383 | my $ua = LWP::UserAgent->new; | ||
| 1384 | $ua->timeout(30); | ||
| 1385 | $ua->env_proxy; | ||
| 1386 | |||
| 1387 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 1388 | if ($response->is_success) { | ||
| 1389 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 1390 | } | ||
| 1391 | |||
| 1392 | } | ||
| 1393 | return 0; | ||
| 1394 | } | ||
| 1395 | |||
| 1396 | =head2 get_mobile_hashcode(access_token, hash); | ||
| 1397 | |||
| 1398 | 获取手机号随机串 | ||
| 1399 | |||
| 1400 | =head2 SYNOPSIS | ||
| 1401 | |||
| 1402 | L<https://work.weixin.qq.com/api/doc/90000/90135/91735> | ||
| 1403 | |||
| 1404 | =head3 请求说明: | ||
| 1405 | |||
| 1406 | 支持企业获取手机号随机串,该随机串可直接在企业微信终端搜索手机号对应的微信用户。 | ||
| 1407 | |||
| 1408 | =head4 请求包结构体为: | ||
| 1409 | |||
| 1410 | { | ||
| 1411 | "mobile" : "+8613800000000", | ||
| 1412 | "state": "123456" | ||
| 1413 | } | ||
| 1414 | |||
| 1415 | =head4 参数说明: | ||
| 1416 | |||
| 1417 | 参数 必须 说明 | ||
| 1418 | access_token 是 调用接口凭证 | ||
| 1419 | mobile 是 手机号 | ||
| 1420 | state 否 企业自定义的state参数,用于区分不同的添加渠道,在调用“获取外部联系人详情”时会返回该参数值 | ||
| 1421 | |||
| 1422 | =head3 权限说明 | ||
| 1423 | |||
| 1424 | 仅限自建应用调用。 | ||
| 1425 | |||
| 1426 | =head3 RETURN 返回结果 | ||
| 1427 | |||
| 1428 | { | ||
| 1429 | "errcode": 0, | ||
| 1430 | "errmsg": "ok", | ||
| 1431 | "hashcode": "1abcd2xaba3dxab4sdxa" | ||
| 1432 | } | ||
| 1433 | |||
| 1434 | =head3 RETURN 参数说明 | ||
| 1435 | |||
| 1436 | 参数 说明 | ||
| 1437 | errcode 返回码 | ||
| 1438 | errmsg 对返回码的文本描述内容 | ||
| 1439 | hashcode 手机号对应的随机串,20个字节,30分钟内有效 | ||
| 1440 | |||
| 1441 | =cut | ||
| 1442 | |||
| 1443 | sub get_mobile_hashcode { | ||
| 1444 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 1445 | my $access_token = $_[0]; | ||
| 1446 | my $json = $_[1]; | ||
| 1447 | my $ua = LWP::UserAgent->new; | ||
| 1448 | $ua->timeout(30); | ||
| 1449 | $ua->env_proxy; | ||
| 1450 | |||
| 1451 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/user/get_mobile_hashcode?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 1452 | if ($response->is_success) { | ||
| 1453 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 1454 | } | ||
| 1455 | |||
| 1456 | } | ||
| 1457 | return 0; | ||
| 1458 | } | ||
| 1459 | |||
| 1460 | =head2 tfa_succ(access_token, hash); | ||
| 1461 | |||
| 1462 | 使用二次验证 | ||
| 1463 | 最后更新:2023/11/15 | ||
| 1464 | |||
| 1465 | =head2 SYNOPSIS | ||
| 1466 | |||
| 1467 | L<https://developer.work.weixin.qq.com/document/path/99500> | ||
| 1468 | |||
| 1469 | =head3 请求说明: | ||
| 1470 | |||
| 1471 | =head4 请求包结构体为: | ||
| 1472 | |||
| 1473 | { | ||
| 1474 | "userid":"USERID", | ||
| 1475 | "tfa_code": "TFA_CODE" | ||
| 1476 | } | ||
| 1477 | |||
| 1478 | =head4 参数说明: | ||
| 1479 | |||
| 1480 | 参数 必须 说明 | ||
| 1481 | access_token 是 调用接口凭证 | ||
| 1482 | userid 是 用户的userid | ||
| 1483 | tfa_code 是 获取用户二次验证信息接口返回的tfa_code,tfa_code五分钟内有效且只能使用一次 | ||
| 1484 | |||
| 1485 | =head3 权限说明 | ||
| 1486 | |||
| 1487 | 仅『通讯录同步』或者自建应用可调用,如用自建应用调用,用户需要在二次验证范围和应用可见范围内。 | ||
| 1488 | 并发限制:20 | ||
| 1489 | |||
| 1490 | =head3 RETURN 返回结果 | ||
| 1491 | |||
| 1492 | { | ||
| 1493 | "errcode": 0, | ||
| 1494 | "errmsg": "ok" | ||
| 1495 | } | ||
| 1496 | |||
| 1497 | =head3 RETURN 参数说明 | ||
| 1498 | |||
| 1499 | 参数 说明 | ||
| 1500 | errcode 返回码 | ||
| 1501 | errmsg 对返回码的文本描述内容 | ||
| 1502 | |||
| 1503 | =cut | ||
| 1504 | |||
| 1505 | sub tfa_succ { | ||
| 1506 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 1507 | my $access_token = $_[0]; | ||
| 1508 | my $json = $_[1]; | ||
| 1509 | my $ua = LWP::UserAgent->new; | ||
| 1510 | $ua->timeout(30); | ||
| 1511 | $ua->env_proxy; | ||
| 1512 | |||
| 1513 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/user/tfa_succ?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 1514 | if ($response->is_success) { | ||
| 1515 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 1516 | } | ||
| 1517 | |||
| 1518 | } | ||
| 1519 | return 0; | ||
| 1520 | } | ||
| 1521 | |||
| 1522 | 1; | ||
| 1523 | __END__ |