| 1 | package QQ::weixin::work::externalcontact::message; | ||
| 2 | |||
| 3 | =encoding utf8 | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | QQ::weixin::work::externalcontact::message | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | 家校消息推送 | ||
| 12 | |||
| 13 | =cut | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use base qw(QQ::weixin::work::externalcontact); | ||
| 17 | use Encode; | ||
| 18 | use LWP::UserAgent; | ||
| 19 | use JSON; | ||
| 20 | use utf8; | ||
| 21 | |||
| 22 | our $VERSION = '0.10'; | ||
| 23 | our @EXPORT = qw/ send /; | ||
| 24 | |||
| 25 | =head1 FUNCTION | ||
| 26 | |||
| 27 | =head2 send(access_token, hash); | ||
| 28 | |||
| 29 | 发送「学校通知」 | ||
| 30 | 最后更新:2022/05/23 | ||
| 31 | |||
| 32 | =head2 SYNOPSIS | ||
| 33 | |||
| 34 | L<https://developer.work.weixin.qq.com/document/path/91609> | ||
| 35 | |||
| 36 | =head3 请求说明: | ||
| 37 | |||
| 38 | 学校可以通过此接口来给家长发送不同类型的学校通知,来满足多种场景下的学校通知需求。目前支持的消息类型为文本、图片、语音、视频、文件、图文。 | ||
| 39 | |||
| 40 | =head4 请求包结构体为: | ||
| 41 | |||
| 42 | =head4 参数说明: | ||
| 43 | |||
| 44 | 参数 是否必须 说明 | ||
| 45 | access_token 是 调用接口凭证 | ||
| 46 | |||
| 47 | 各个消息类型的具体POST格式参考以下文档。 | ||
| 48 | 支持id转译,将userid/部门id转成对应的企业通讯录内部的用户名/部门名,目前仅文本/图文/图文(mpnews)/小程序消息这四种消息类型的部分字段支持。具体支持的范围和语法,请查看附录id转译说明。 | ||
| 49 | 支持重复消息检查,当指定 "enable_duplicate_check": 1开启: 表示在一定时间间隔内,同样内容(请求json)的消息,不会重复收到;时间间隔可通过duplicate_check_interval指定,默认1800秒。 | ||
| 50 | |||
| 51 | =head3 权限说明 | ||
| 52 | |||
| 53 | 学校管理员需要将应用配置在「家长可使用的应用」才可调用 | ||
| 54 | |||
| 55 | =head3 RETURN 返回结果 | ||
| 56 | |||
| 57 | { | ||
| 58 | "errcode" : 0, | ||
| 59 | "errmsg" : "ok", | ||
| 60 | "invalid_parent_userid" : ["parent_userid1"], | ||
| 61 | "invalid_student_userid" : ["student_userid1"], | ||
| 62 | "invalid_party" : ["party1"] | ||
| 63 | } | ||
| 64 | |||
| 65 | 如果部分接收人无权限或不存在,发送仍然执行,但会返回无效的部分(invalid_parent_userid/invalid_student_userid/invalid_party)。 | ||
| 66 | |||
| 67 | =head4 RETURN 参数说明 | ||
| 68 | |||
| 69 | 参数 说明 | ||
| 70 | errcode 返回码 | ||
| 71 | errmsg 对返回码的文本描述内容 | ||
| 72 | |||
| 73 | =cut | ||
| 74 | |||
| 75 | sub send { | ||
| 76 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 77 | my $access_token = $_[0]; | ||
| 78 | my $json = $_[1]; | ||
| 79 | my $ua = LWP::UserAgent->new; | ||
| 80 | $ua->timeout(30); | ||
| 81 | $ua->env_proxy; | ||
| 82 | |||
| 83 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/message/send?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 84 | if ($response->is_success) { | ||
| 85 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 86 | } | ||
| 87 | |||
| 88 | } | ||
| 89 | return 0; | ||
| 90 | } | ||
| 91 | |||
| 92 | |||
| 93 | 1; | ||
| 94 | __END__ |