| 1 | package QQ::weixin::work::corpgroup::batch; | ||
| 2 | |||
| 3 | =encoding utf8 | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | QQ::weixin::work::corpgroup::batch | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | =cut | ||
| 12 | |||
| 13 | use strict; | ||
| 14 | use base qw(QQ::weixin::work::corpgroup); | ||
| 15 | use Encode; | ||
| 16 | use LWP::UserAgent; | ||
| 17 | use JSON; | ||
| 18 | use utf8; | ||
| 19 | |||
| 20 | our $VERSION = '0.10'; | ||
| 21 | our @EXPORT = qw/ external_userid_to_pending_id /; | ||
| 22 | |||
| 23 | =head1 FUNCTION | ||
| 24 | |||
| 25 | =head2 external_userid_to_pending_id(access_token, hash); | ||
| 26 | |||
| 27 | external_userid查询pending_id | ||
| 28 | 最后更新:2023/03/30 | ||
| 29 | |||
| 30 | =head2 SYNOPSIS | ||
| 31 | |||
| 32 | L<https://developer.work.weixin.qq.com/document/path/97357> | ||
| 33 | |||
| 34 | =head3 请求说明: | ||
| 35 | |||
| 36 | external_userid的说明 | ||
| 37 | |||
| 38 | external_userid是企业微信用于表示企业的外部联系人而设立的id,且满足以下条件 | ||
| 39 | 假设同一个微信用户属于多个下游企业的外部联系人 | ||
| 40 | 1.同一上游企业获取到不同企业的外部联系人的external_userid不一致。 | ||
| 41 | 2.不同一上游企业获取同一个企业的同一个外部联系人的external_userid也不一致。 | ||
| 42 | |||
| 43 | pending_id的说明 | ||
| 44 | |||
| 45 | pending_id主要用于关联微信unionid与外部联系人external_userid,可理解为临时外部联系人ID; | ||
| 46 | 上游企业可通过此接口将微信unionid转为pending_id,当微信用户成为下游企业客户后,可使用上下游external_userid转pending_id接口将下游external_userid转换为pending_id,建立unionid => pending_id => external_userid的映射关系; | ||
| 47 | pending_id有效期90天,共享应用内唯一。 | ||
| 48 | |||
| 49 | =head4 请求包结构体为: | ||
| 50 | |||
| 51 | { | ||
| 52 | "chat_id":"xxxxxx", | ||
| 53 | "external_userid":["oAAAAAAA", "oBBBBB"] | ||
| 54 | } | ||
| 55 | |||
| 56 | =head4 参数说明: | ||
| 57 | |||
| 58 | 参数 必须 说明 | ||
| 59 | access_token 是 调用接口凭证 | ||
| 60 | external_userid 是 上游或下游企业外部联系人id,最多同时查询100个 | ||
| 61 | chat_id 否 群id,如果有传入该参数,则只检查群主是否在可见范围,同时会忽略在该群以外的external_userid。如果不传入该参数,则只检查客户跟进人是否在可见范围内。 | ||
| 62 | |||
| 63 | =head4 权限说明: | ||
| 64 | |||
| 65 | 调用该接口的应用必须是上下游共享的自建应用或代开发应用 | ||
| 66 | 应用需要具有客户联系权限 | ||
| 67 | 该客户的跟进人或其所在客户群群主必须在应用的可见范围之内 | ||
| 68 | 上游应用须调用过unionid转pending_id接口 | ||
| 69 | 上游和下游企业须认证或验证;若为代开发应用,服务商必须已认证 | ||
| 70 | |||
| 71 | =head3 RETURN 返回结果: | ||
| 72 | |||
| 73 | { | ||
| 74 | "errcode":0, | ||
| 75 | "errmsg":"ok", | ||
| 76 | "result":[ | ||
| 77 | { | ||
| 78 | "external_userid":"oAAAAAAA", | ||
| 79 | "pending_id":"pAAAAA" | ||
| 80 | }, | ||
| 81 | { | ||
| 82 | "external_userid":"oBBBBB", | ||
| 83 | "pending_id":"pBBBBB" | ||
| 84 | } | ||
| 85 | ] | ||
| 86 | } | ||
| 87 | |||
| 88 | =head4 RETURN 参数说明: | ||
| 89 | |||
| 90 | 参数 说明 | ||
| 91 | errcode 出错返回码,为0表示成功,非0表示调用失败 | ||
| 92 | errmsg 对返回码的文本描述内容 | ||
| 93 | result 转换结果 | ||
| 94 | result.external_userid 转换的external_userid | ||
| 95 | result.pending_id 该微信账号还未成为企业客户时,返回的临时外部联系人ID | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | sub external_userid_to_pending_id { | ||
| 100 | if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) { | ||
| 101 | my $access_token = $_[0]; | ||
| 102 | my $json = $_[1]; | ||
| 103 | my $ua = LWP::UserAgent->new; | ||
| 104 | $ua->timeout(30); | ||
| 105 | $ua->env_proxy; | ||
| 106 | |||
| 107 | my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/corpgroup/batch/external_userid_to_pending_id?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json'); | ||
| 108 | if ($response->is_success) { | ||
| 109 | return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1}); | ||
| 110 | } | ||
| 111 | |||
| 112 | } | ||
| 113 | return 0; | ||
| 114 | } | ||
| 115 | |||
| 116 | |||
| 117 | 1; | ||
| 118 | __END__ |