Skip to content

Commit 88301a6

Browse files
authored
🆕 #2372【企业微信】新增客户群opengid转换和入群欢迎语素材管理相关接口
1 parent dd83e16 commit 88301a6

File tree

4 files changed

+216
-54
lines changed

4 files changed

+216
-54
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java

Lines changed: 74 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,7 @@
33
import lombok.NonNull;
44
import me.chanjar.weixin.common.error.WxErrorException;
55
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6-
import me.chanjar.weixin.cp.bean.external.WxCpAddMomentResult;
7-
import me.chanjar.weixin.cp.bean.external.WxCpAddMomentTask;
8-
import me.chanjar.weixin.cp.bean.external.WxCpContactWayInfo;
9-
import me.chanjar.weixin.cp.bean.external.WxCpContactWayResult;
10-
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentComments;
11-
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentCustomerList;
12-
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentList;
13-
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentSendResult;
14-
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTask;
15-
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTaskResult;
16-
import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplate;
17-
import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplateAddResult;
18-
import me.chanjar.weixin.cp.bean.external.WxCpUpdateRemarkRequest;
19-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatInfo;
20-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatList;
21-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatStatistic;
22-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatTransferResp;
23-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalTagGroupInfo;
24-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalTagGroupList;
25-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalUnassignList;
26-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalUserBehaviorStatistic;
27-
import me.chanjar.weixin.cp.bean.external.WxCpUserTransferCustomerReq;
28-
import me.chanjar.weixin.cp.bean.external.WxCpUserTransferCustomerResp;
29-
import me.chanjar.weixin.cp.bean.external.WxCpUserTransferResultResp;
30-
import me.chanjar.weixin.cp.bean.external.WxCpWelcomeMsg;
6+
import me.chanjar.weixin.cp.bean.external.*;
317
import me.chanjar.weixin.cp.bean.external.contact.*;
328
import me.chanjar.weixin.cp.bean.oa.WxCpApprovalInfoQueryFilter;
339
import org.jetbrains.annotations.NotNull;
@@ -191,6 +167,30 @@ public interface WxCpExternalContactService {
191167
*/
192168
String unionidToExternalUserid(@NotNull String unionid,String openid) throws WxErrorException;
193169

170+
/**
171+
* 客户群opengid转换
172+
* <pre>
173+
*
174+
* 文档地址:https://open.work.weixin.qq.com/api/doc/90000/90135/94822
175+
*
176+
* 用户在微信里的客户群里打开小程序时,某些场景下可以获取到群的opengid,如果该群是企业微信的客户群,
177+
* 则企业或第三方可以调用此接口将一个opengid转换为客户群chat_id
178+
*
179+
* 权限说明:
180+
*
181+
* 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)
182+
* 第三方应用需具有“企业客户权限->客户基础信息”权限
183+
* 对于第三方/自建应用,群主必须在应用的可见范围
184+
* 仅支持企业服务人员创建的客户群
185+
* 仅可转换出自己企业下的客户群chat_id
186+
* </pre>
187+
*
188+
* @param opengid 小程序在微信获取到的群ID,参见wx.getGroupEnterInfo(https://developers.weixin.qq.com/miniprogram/dev/api/open-api/group/wx.getGroupEnterInfo.html)
189+
* @return 客户群ID,可以用来调用获取客户群详情
190+
* @throws WxErrorException .
191+
*/
192+
String opengidToChatid(@NotNull String opengid) throws WxErrorException;
193+
194194
/**
195195
* 批量获取客户详情.
196196
* <pre>
@@ -740,4 +740,53 @@ WxCpGetMomentComments getMomentComments(String momentId, String userId)
740740
*/
741741
WxCpGroupMsgTaskResult getGroupMsgTask(String msgid, Integer limit, String cursor) throws WxErrorException;
742742

743+
/**
744+
* <pre>
745+
* 添加入群欢迎语素材。
746+
* https://open.work.weixin.qq.com/api/doc/90000/90135/92366#添加入群欢迎语素材
747+
* </pre>
748+
*
749+
* @param template 素材内容
750+
* @return template_id 欢迎语素材id
751+
* @throws WxErrorException the wx error exception
752+
*/
753+
String addGroupWelcomeTemplate(WxCpGroupWelcomeTemplateResult template) throws WxErrorException;
754+
755+
/**
756+
* <pre>
757+
* 编辑入群欢迎语素材。
758+
* https://open.work.weixin.qq.com/api/doc/90000/90135/92366#编辑入群欢迎语素材
759+
* </pre>
760+
*
761+
* @param template
762+
* @return wx cp base resp
763+
* @throws WxErrorException the wx error exception
764+
*/
765+
WxCpBaseResp editGroupWelcomeTemplate(WxCpGroupWelcomeTemplateResult template) throws WxErrorException;
766+
767+
/**
768+
* <pre>
769+
* 获取入群欢迎语素材。
770+
* https://open.work.weixin.qq.com/api/doc/90000/90135/92366#获取入群欢迎语素材
771+
* </pre>
772+
*
773+
* @param templateId 群欢迎语的素材id
774+
* @return wx cp base resp
775+
* @throws WxErrorException the wx error exception
776+
*/
777+
WxCpGroupWelcomeTemplateResult getGroupWelcomeTemplate(@NotNull String templateId) throws WxErrorException;
778+
779+
/**
780+
* <pre>
781+
* 删除入群欢迎语素材。
782+
* 企业可通过此API删除入群欢迎语素材,且仅能删除调用方自己创建的入群欢迎语素材。
783+
* https://open.work.weixin.qq.com/api/doc/90000/90135/92366#删除入群欢迎语素材
784+
* </pre>
785+
*
786+
* @param templateId 群欢迎语的素材id
787+
* @param templateId 授权方安装的应用agentid。仅旧的第三方多应用套件需要填此参数
788+
* @return wx cp base resp
789+
* @throws WxErrorException the wx error exception
790+
*/
791+
WxCpBaseResp delGroupWelcomeTemplate(@NotNull String templateId, String agentId) throws WxErrorException;
743792
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java

Lines changed: 91 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,7 @@
1212
import me.chanjar.weixin.cp.api.WxCpExternalContactService;
1313
import me.chanjar.weixin.cp.api.WxCpService;
1414
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
15-
import me.chanjar.weixin.cp.bean.external.WxCpAddMomentResult;
16-
import me.chanjar.weixin.cp.bean.external.WxCpAddMomentTask;
17-
import me.chanjar.weixin.cp.bean.external.WxCpContactWayInfo;
18-
import me.chanjar.weixin.cp.bean.external.WxCpContactWayResult;
19-
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentComments;
20-
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentCustomerList;
21-
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentList;
22-
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentSendResult;
23-
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTask;
24-
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTaskResult;
25-
import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplate;
26-
import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplateAddResult;
27-
import me.chanjar.weixin.cp.bean.external.WxCpUpdateRemarkRequest;
28-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalContactList;
29-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatInfo;
30-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatList;
31-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatStatistic;
32-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatTransferResp;
33-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalTagGroupInfo;
34-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalTagGroupList;
35-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalUnassignList;
36-
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalUserBehaviorStatistic;
37-
import me.chanjar.weixin.cp.bean.external.WxCpUserTransferCustomerReq;
38-
import me.chanjar.weixin.cp.bean.external.WxCpUserTransferCustomerResp;
39-
import me.chanjar.weixin.cp.bean.external.WxCpUserTransferResultResp;
40-
import me.chanjar.weixin.cp.bean.external.WxCpUserWithExternalPermission;
41-
import me.chanjar.weixin.cp.bean.external.WxCpWelcomeMsg;
15+
import me.chanjar.weixin.cp.bean.external.*;
4216
import me.chanjar.weixin.cp.bean.external.contact.*;
4317
import org.apache.commons.lang3.ArrayUtils;
4418
import org.apache.commons.lang3.StringUtils;
@@ -157,6 +131,16 @@ public String unionidToExternalUserid(@NotNull String unionid,String openid) thr
157131
return tmpJson.get("external_userid").getAsString();
158132
}
159133

134+
@Override
135+
public String opengidToChatid(@NotNull String opengid) throws WxErrorException {
136+
JsonObject json = new JsonObject();
137+
json.addProperty("opengid",opengid);
138+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(OPENID_TO_CHATID);
139+
String responseContent = this.mainService.post(url, json.toString());
140+
JsonObject tmpJson = GsonParser.parse(responseContent);
141+
return tmpJson.get("chat_id").getAsString();
142+
}
143+
160144
@Override
161145
public WxCpExternalContactBatchInfo getContactDetailBatch(String[] userIdList,
162146
String cursor,
@@ -586,7 +570,7 @@ public WxCpGroupMsgListResult getGroupMsgListV2(String chatType, @NonNull Date s
586570
json.addProperty("limit", limit);
587571
json.addProperty("cursor", cursor);
588572

589-
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_GROUP_MSG_SEND_RESULT);
573+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_GROUP_MSG_LIST_V2);
590574
final String result = this.mainService.post(url, json.toString());
591575
return WxCpGroupMsgListResult.fromJson(result);
592576
}
@@ -636,8 +620,86 @@ public WxCpGroupMsgTaskResult getGroupMsgTask(String msgid, Integer limit, Strin
636620
json.addProperty("limit", limit);
637621
json.addProperty("cursor", cursor);
638622

639-
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_GROUP_MSG_SEND_RESULT);
623+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_GROUP_MSG_TASK);
640624
final String result = this.mainService.post(url, json.toString());
641625
return WxCpGroupMsgTaskResult.fromJson(result);
642626
}
627+
628+
/**
629+
* <pre>
630+
* 添加入群欢迎语素材。
631+
* https://open.work.weixin.qq.com/api/doc/90000/90135/92366#添加入群欢迎语素材
632+
* </pre>
633+
*
634+
* @param template 素材内容
635+
* @return template_id 欢迎语素材id
636+
* @throws WxErrorException the wx error exception
637+
*/
638+
@Override
639+
public String addGroupWelcomeTemplate(WxCpGroupWelcomeTemplateResult template) throws WxErrorException {
640+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GROUP_WELCOME_TEMPLATE_ADD);
641+
final String responseContent = this.mainService.post(url, template.toJson());
642+
JsonObject tmpJson = GsonParser.parse(responseContent);
643+
return tmpJson.get("template_id").getAsString();
644+
}
645+
646+
/**
647+
* <pre>
648+
* 编辑入群欢迎语素材。
649+
* https://open.work.weixin.qq.com/api/doc/90000/90135/92366#编辑入群欢迎语素材
650+
* </pre>
651+
*
652+
* @param template
653+
* @return wx cp base resp
654+
* @throws WxErrorException the wx error exception
655+
*/
656+
@Override
657+
public WxCpBaseResp editGroupWelcomeTemplate(WxCpGroupWelcomeTemplateResult template) throws WxErrorException {
658+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GROUP_WELCOME_TEMPLATE_EDIT);
659+
final String result = this.mainService.post(url, template.toJson());
660+
return WxCpGroupWelcomeTemplateResult.fromJson(result);
661+
}
662+
663+
/**
664+
* <pre>
665+
* 获取入群欢迎语素材。
666+
* https://open.work.weixin.qq.com/api/doc/90000/90135/92366#获取入群欢迎语素材
667+
* </pre>
668+
*
669+
* @param templateId 群欢迎语的素材id
670+
* @return wx cp base resp
671+
* @throws WxErrorException the wx error exception
672+
*/
673+
@Override
674+
public WxCpGroupWelcomeTemplateResult getGroupWelcomeTemplate(@NotNull String templateId) throws WxErrorException {
675+
JsonObject json = new JsonObject();
676+
json.addProperty("template_id", templateId);
677+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GROUP_WELCOME_TEMPLATE_GET);
678+
final String result = this.mainService.post(url, json.toString());
679+
return WxCpGroupWelcomeTemplateResult.fromJson(result);
680+
}
681+
682+
/**
683+
* <pre>
684+
* 删除入群欢迎语素材。
685+
* 企业可通过此API删除入群欢迎语素材,且仅能删除调用方自己创建的入群欢迎语素材。
686+
* https://open.work.weixin.qq.com/api/doc/90000/90135/92366#删除入群欢迎语素材
687+
* </pre>
688+
*
689+
* @param templateId 群欢迎语的素材id
690+
* @param agentId
691+
* @return wx cp base resp
692+
* @throws WxErrorException the wx error exception
693+
*/
694+
@Override
695+
public WxCpBaseResp delGroupWelcomeTemplate(@NotNull String templateId, String agentId) throws WxErrorException {
696+
JsonObject json = new JsonObject();
697+
json.addProperty("template_id", templateId);
698+
if (!StringUtils.isEmpty(agentId)) {
699+
json.addProperty("agentid", agentId);
700+
}
701+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GROUP_WELCOME_TEMPLATE_DEL);
702+
final String result = this.mainService.post(url, json.toString());
703+
return WxCpBaseResp.fromJson(result);
704+
}
643705
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package me.chanjar.weixin.cp.bean.external;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.bean.external.msg.*;
9+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
10+
11+
import java.io.Serializable;
12+
13+
/**
14+
* 入群欢迎语素材.
15+
*
16+
* @author <a href="https://github.com/wslongchen">Mr.Pan</a>
17+
* @date 2021-11-3
18+
*/
19+
@Data
20+
@Builder
21+
@NoArgsConstructor
22+
@AllArgsConstructor
23+
public class WxCpGroupWelcomeTemplateResult extends WxCpBaseResp implements Serializable {
24+
private static final long serialVersionUID = -6406667238670580612L;
25+
26+
private Text text;
27+
28+
private Image image;
29+
30+
private Link link;
31+
32+
private MiniProgram miniprogram;
33+
34+
private File file;
35+
36+
private Video video;
37+
38+
public static WxCpGroupWelcomeTemplateResult fromJson(String json) {
39+
return WxCpGsonBuilder.create().fromJson(json, WxCpGroupWelcomeTemplateResult.class);
40+
}
41+
42+
public String toJson() {
43+
return WxCpGsonBuilder.create().toJson(this);
44+
}
45+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ interface ExternalContact {
194194
String RESIGNED_TRANSFER_RESULT = "/cgi-bin/externalcontact/resigned/transfer_result";
195195
String GROUP_CHAT_LIST = "/cgi-bin/externalcontact/groupchat/list";
196196
String GROUP_CHAT_INFO = "/cgi-bin/externalcontact/groupchat/get";
197+
String OPENID_TO_CHATID= "/cgi-bin/externalcontact/opengid_to_chatid";
197198
String GROUP_CHAT_TRANSFER = "/cgi-bin/externalcontact/groupchat/transfer";
198199
String LIST_USER_BEHAVIOR_DATA = "/cgi-bin/externalcontact/get_user_behavior_data";
199200
String LIST_GROUP_CHAT_DATA = "/cgi-bin/externalcontact/groupchat/statistic";
@@ -218,5 +219,10 @@ interface ExternalContact {
218219
String GET_GROUP_MSG_TASK = "/cgi-bin/externalcontact/get_groupmsg_task";
219220
String GET_GROUP_MSG_LIST_V2 = "/cgi-bin/externalcontact/get_groupmsg_list_v2";
220221

222+
String GROUP_WELCOME_TEMPLATE_ADD = "/cgi-bin/externalcontact/group_welcome_template/add";
223+
String GROUP_WELCOME_TEMPLATE_EDIT = "/cgi-bin/externalcontact/group_welcome_template/edit";
224+
String GROUP_WELCOME_TEMPLATE_GET = "/cgi-bin/externalcontact/group_welcome_template/get";
225+
String GROUP_WELCOME_TEMPLATE_DEL = "/cgi-bin/externalcontact/group_welcome_template/del";
226+
221227
}
222228
}

0 commit comments

Comments
 (0)