package QQ::weixin::work::appchat; =encoding utf8 =head1 Name QQ::weixin::work::appchat =head1 DESCRIPTION å‘é€æ¶ˆæ¯åˆ°ç¾¤èŠä¼šè¯ =cut use strict; use base qw(QQ::weixin::work); use Encode; use LWP::UserAgent; use JSON; use utf8; our $VERSION = '0.06'; our @EXPORT = qw/ create update get send /; =head1 FUNCTION =head2 create(access_token, hash); 创建群èŠä¼šè¯ =head2 SYNOPSIS L<https://developer.work.weixin.qq.com/document/path/90245> =head3 请求说明: =head4 请求包结构体为: { "name" : "NAME", "owner" : "userid1", "userlist" : ["userid1", "userid2", "userid3"], "chatid" : "CHATID" } =head4 å‚数说明: å‚æ•° å¿…é¡» 说明 access_token 是 调用接å£å‡è¯ name å¦ ç¾¤èŠå,最多50个utf8å—ç¬¦ï¼Œè¶…è¿‡å°†æˆªæ– owner å¦ æŒ‡å®šç¾¤ä¸»çš„id。如果ä¸æŒ‡å®šï¼Œç³»ç»Ÿä¼šéšæœºä»Žuserlistä¸é€‰ä¸€äººä½œä¸ºç¾¤ä¸» userlist 是 群æˆå‘˜id列表。至少2人,至多2000人 chatid å¦ ç¾¤èŠçš„å”¯ä¸€æ ‡å¿—ï¼Œä¸èƒ½ä¸Žå·²æœ‰çš„群é‡å¤ï¼›å—符串类型,最长32个å—符。åªå…许å—符0-9åŠå—æ¯a-zA-Z。如果ä¸å¡«ï¼Œç³»ç»Ÿä¼šéšæœºç”Ÿæˆç¾¤id =head3 æƒé™è¯´æ˜Ž åªå…许ä¼ä¸šè‡ªå»ºåº”用调用,且应用的å¯è§èŒƒå›´å¿…é¡»æ˜¯æ ¹éƒ¨é—¨ï¼› 群æˆå‘˜äººæ•°ä¸å¯è¶…过管ç†ç«¯é…置的“群æˆå‘˜äººæ•°ä¸Šé™â€ï¼Œä¸”最大ä¸å¯è¶…过2000人; æ¯ä¼ä¸šåˆ›å»ºç¾¤æ•°ä¸å¯è¶…过1000/天; =head3 RETURN 返回结果 { "errcode" : 0, "errmsg" : "ok", "chatid" : "CHATID" } =head4 RETURN å‚数说明 å‚æ•° 说明 errcode 返回ç errmsg 对返回ç 的文本æ述内容 chatid 群èŠçš„å”¯ä¸€æ ‡å¿— 注æ„:刚创建的群,如果没有下å‘消æ¯ï¼Œåœ¨ä¼ä¸šå¾®ä¿¡ä¸ä¼šå‡ºçŽ°è¯¥ç¾¤ã€‚ =cut sub create { if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { my $access_token = $_[0]; my $json = $_[1]; my $ua = LWP::UserAgent->new; $ua->timeout(30); $ua->env_proxy; my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/appchat/create?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); if ($response->is_success) { return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); } } return 0; } =head2 update(access_token, hash); 修改群èŠä¼šè¯ =head2 SYNOPSIS L<https://developer.work.weixin.qq.com/document/path/90246> =head3 请求说明: =head4 请求包结构体为: { "chatid" : "CHATID", "name" : "NAME", "owner" : "userid2", "add_user_list" : ["userid1", "userid2", "userid3"], "del_user_list" : ["userid3", "userid4"] } =head4 å‚数说明: å‚æ•° å¿…é¡» 说明 access_token 是 调用接å£å‡è¯ chatid 是 群èŠid name å¦ æ–°çš„ç¾¤èŠå。若ä¸éœ€æ›´æ–°ï¼Œè¯·å¿½ç•¥æ¤å‚数。最多50个utf8å—ç¬¦ï¼Œè¶…è¿‡å°†æˆªæ– owner å¦ æ–°ç¾¤ä¸»çš„id。若ä¸éœ€æ›´æ–°ï¼Œè¯·å¿½ç•¥æ¤å‚æ•° add_user_list å¦ æ·»åŠ æˆå‘˜çš„id列表 del_user_list å¦ è¸¢å‡ºæˆå‘˜çš„id列表 =head3 æƒé™è¯´æ˜Ž åªå…许ä¼ä¸šè‡ªå»ºåº”用调用,且应用的å¯è§èŒƒå›´å¿…é¡»æ˜¯æ ¹éƒ¨é—¨ï¼› chatid所代表的群必须是该应用所创建; 群æˆå‘˜äººæ•°ä¸å¯è¶…过2000人; æ¯ä¼ä¸šå˜æ›´ç¾¤çš„次数ä¸å¯è¶…过1000次/å°æ—¶ï¼› =head3 RETURN 返回结果 { "errcode": 0, "errmsg": "ok" } =head4 RETURN å‚数说明 å‚æ•° 说明 errcode 返回ç errmsg 对返回ç 的文本æ述内容 =cut sub update { if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { my $access_token = $_[0]; my $json = $_[1]; my $ua = LWP::UserAgent->new; $ua->timeout(30); $ua->env_proxy; my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/appchat/update?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); if ($response->is_success) { return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); } } return 0; } =head2 get(access_token, chatid); 获å–群èŠä¼šè¯ =head2 SYNOPSIS L<https://developer.work.weixin.qq.com/document/path/90247> =head3 请求说明: =head4 å‚数说明: å‚æ•° å¿…é¡» 说明 access_token 是 调用接å£å‡è¯ chatid 是 群èŠid =head4 æƒé™è¯´æ˜Žï¼š åªå…许ä¼ä¸šè‡ªå»ºåº”用调用,且应用的å¯è§èŒƒå›´å¿…é¡»æ˜¯æ ¹éƒ¨é—¨ï¼› chatid所代表的群必须是该应用所创建; 第三方ä¸å¯è°ƒç”¨ã€‚ =head3 RETURN 返回结果: { "errcode" : 0, "errmsg" : "ok", "chat_info" : { "chatid" : "CHATID", "name" : "NAME", "owner" : "userid2", "userlist" : ["userid1", "userid2", "userid3"] } } =head4 RETURN å‚数说明 å‚æ•° 说明 errcode 返回ç errmsg 对返回ç 的文本æ述内容 chat_info 群èŠä¿¡æ¯ chatid 群èŠå”¯ä¸€æ ‡å¿— name 群èŠå owner 群主id userlist 群æˆå‘˜id列表 =cut sub get { if ( @_ && $_[0] && $_[1] ) { my $access_token = $_[0]; my $chatid = $_[1]; my $ua = LWP::UserAgent->new; $ua->timeout(30); $ua->env_proxy; my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/appchat/get?access_token=$access_token&chatid=$chatid"); if ($response->is_success) { return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); } } return 0; } =head2 send(access_token, hash); 应用推é€æ¶ˆæ¯ =head2 SYNOPSIS L<https://developer.work.weixin.qq.com/document/path/90248> =head3 请求说明: 应用支æŒæŽ¨é€æ–‡æœ¬ã€å›¾ç‰‡ã€è§†é¢‘ã€æ–‡ä»¶ã€å›¾æ–‡ç‰ç±»åž‹ã€‚ =head4 请求包结构体为: å„个消æ¯ç±»åž‹çš„具体POSTæ ¼å¼å‚考åŽé¢æ¶ˆæ¯ç±»åž‹è¯´æ˜Ž =head4 å‚数说明: å‚æ•° å¿…é¡» 说明 access_token 是 调用接å£å‡è¯ =head3 æƒé™è¯´æ˜Ž åªå…许ä¼ä¸šè‡ªå»ºåº”用调用,且应用的å¯è§èŒƒå›´å¿…é¡»æ˜¯æ ¹éƒ¨é—¨ï¼› chatid所代表的群必须是该应用所创建; æ¯ä¼ä¸šæ¶ˆæ¯å‘é€é‡ä¸å¯è¶…过2万人次/分,ä¸å¯è¶…过30万人次/å°æ—¶ï¼ˆè‹¥ç¾¤æœ‰100人,æ¯å‘一次消æ¯ç®—100人次); æ¯ä¸ªæˆå‘˜åœ¨ç¾¤ä¸æ”¶åˆ°çš„应用消æ¯ä¸å¯è¶…过200æ¡/分,1万æ¡/天,超过会被丢弃(接å£ä¸ä¼šæŠ¥é”™ï¼‰ï¼› =head3 RETURN 返回结果 { "errcode": 0, "errmsg": "ok" } =head4 RETURN å‚数说明 å‚æ•° 说明 errcode 返回ç errmsg 对返回ç 的文本æ述内容 =cut sub send { if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { my $access_token = $_[0]; my $json = $_[1]; my $ua = LWP::UserAgent->new; $ua->timeout(30); $ua->env_proxy; my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/appchat/send?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); if ($response->is_success) { return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); } } return 0; } 1; __END__