From 88301a619251c9b4a3c87f71c2e4117443f4661d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BD=98=E5=AE=89?= Date: Wed, 3 Nov 2021 23:20:33 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#2372=E3=80=90=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E3=80=91=E6=96=B0=E5=A2=9E=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=BE=A4opengid=E8=BD=AC=E6=8D=A2=E5=92=8C=E5=85=A5=E7=BE=A4?= =?UTF-8?q?=E6=AC=A2=E8=BF=8E=E8=AF=AD=E7=B4=A0=E6=9D=90=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cp/api/WxCpExternalContactService.java | 99 +++++++++++---- .../impl/WxCpExternalContactServiceImpl.java | 120 +++++++++++++----- .../WxCpGroupWelcomeTemplateResult.java | 45 +++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 6 + 4 files changed, 216 insertions(+), 54 deletions(-) create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpGroupWelcomeTemplateResult.java diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java index d252fb831e..396bbe4a9c 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java @@ -3,31 +3,7 @@ import lombok.NonNull; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.bean.WxCpBaseResp; -import me.chanjar.weixin.cp.bean.external.WxCpAddMomentResult; -import me.chanjar.weixin.cp.bean.external.WxCpAddMomentTask; -import me.chanjar.weixin.cp.bean.external.WxCpContactWayInfo; -import me.chanjar.weixin.cp.bean.external.WxCpContactWayResult; -import me.chanjar.weixin.cp.bean.external.WxCpGetMomentComments; -import me.chanjar.weixin.cp.bean.external.WxCpGetMomentCustomerList; -import me.chanjar.weixin.cp.bean.external.WxCpGetMomentList; -import me.chanjar.weixin.cp.bean.external.WxCpGetMomentSendResult; -import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTask; -import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTaskResult; -import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplate; -import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplateAddResult; -import me.chanjar.weixin.cp.bean.external.WxCpUpdateRemarkRequest; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatInfo; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatList; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatStatistic; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatTransferResp; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalTagGroupInfo; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalTagGroupList; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalUnassignList; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalUserBehaviorStatistic; -import me.chanjar.weixin.cp.bean.external.WxCpUserTransferCustomerReq; -import me.chanjar.weixin.cp.bean.external.WxCpUserTransferCustomerResp; -import me.chanjar.weixin.cp.bean.external.WxCpUserTransferResultResp; -import me.chanjar.weixin.cp.bean.external.WxCpWelcomeMsg; +import me.chanjar.weixin.cp.bean.external.*; import me.chanjar.weixin.cp.bean.external.contact.*; import me.chanjar.weixin.cp.bean.oa.WxCpApprovalInfoQueryFilter; import org.jetbrains.annotations.NotNull; @@ -191,6 +167,30 @@ public interface WxCpExternalContactService { */ String unionidToExternalUserid(@NotNull String unionid,String openid) throws WxErrorException; + /** + * 客户群opengid转换 + *
+   *
+   * 文档地址:https://open.work.weixin.qq.com/api/doc/90000/90135/94822
+   *
+   * 用户在微信里的客户群里打开小程序时,某些场景下可以获取到群的opengid,如果该群是企业微信的客户群,
+   * 则企业或第三方可以调用此接口将一个opengid转换为客户群chat_id
+   *
+   * 权限说明:
+   *
+   * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)
+   * 第三方应用需具有“企业客户权限->客户基础信息”权限
+   * 对于第三方/自建应用,群主必须在应用的可见范围
+   * 仅支持企业服务人员创建的客户群
+   * 仅可转换出自己企业下的客户群chat_id
+   * 
+ * + * @param opengid 小程序在微信获取到的群ID,参见wx.getGroupEnterInfo(https://developers.weixin.qq.com/miniprogram/dev/api/open-api/group/wx.getGroupEnterInfo.html) + * @return 客户群ID,可以用来调用获取客户群详情 + * @throws WxErrorException . + */ + String opengidToChatid(@NotNull String opengid) throws WxErrorException; + /** * 批量获取客户详情. *
@@ -740,4 +740,53 @@ WxCpGetMomentComments getMomentComments(String momentId, String userId)
    */
    WxCpGroupMsgTaskResult getGroupMsgTask(String msgid, Integer limit, String cursor) throws WxErrorException;
 
+  /**
+   * 
+   * 添加入群欢迎语素材。
+   * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#添加入群欢迎语素材
+   * 
+ * + * @param template 素材内容 + * @return template_id 欢迎语素材id + * @throws WxErrorException the wx error exception + */ + String addGroupWelcomeTemplate(WxCpGroupWelcomeTemplateResult template) throws WxErrorException; + + /** + *
+   * 编辑入群欢迎语素材。
+   * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#编辑入群欢迎语素材
+   * 
+ * + * @param template + * @return wx cp base resp + * @throws WxErrorException the wx error exception + */ + WxCpBaseResp editGroupWelcomeTemplate(WxCpGroupWelcomeTemplateResult template) throws WxErrorException; + + /** + *
+   * 获取入群欢迎语素材。
+   * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#获取入群欢迎语素材
+   * 
+ * + * @param templateId 群欢迎语的素材id + * @return wx cp base resp + * @throws WxErrorException the wx error exception + */ + WxCpGroupWelcomeTemplateResult getGroupWelcomeTemplate(@NotNull String templateId) throws WxErrorException; + + /** + *
+   * 删除入群欢迎语素材。
+   * 企业可通过此API删除入群欢迎语素材,且仅能删除调用方自己创建的入群欢迎语素材。
+   * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#删除入群欢迎语素材
+   * 
+ * + * @param templateId 群欢迎语的素材id + * @param templateId 授权方安装的应用agentid。仅旧的第三方多应用套件需要填此参数 + * @return wx cp base resp + * @throws WxErrorException the wx error exception + */ + WxCpBaseResp delGroupWelcomeTemplate(@NotNull String templateId, String agentId) throws WxErrorException; } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java index 72c2c93b90..19937e3827 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java @@ -12,33 +12,7 @@ import me.chanjar.weixin.cp.api.WxCpExternalContactService; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.bean.WxCpBaseResp; -import me.chanjar.weixin.cp.bean.external.WxCpAddMomentResult; -import me.chanjar.weixin.cp.bean.external.WxCpAddMomentTask; -import me.chanjar.weixin.cp.bean.external.WxCpContactWayInfo; -import me.chanjar.weixin.cp.bean.external.WxCpContactWayResult; -import me.chanjar.weixin.cp.bean.external.WxCpGetMomentComments; -import me.chanjar.weixin.cp.bean.external.WxCpGetMomentCustomerList; -import me.chanjar.weixin.cp.bean.external.WxCpGetMomentList; -import me.chanjar.weixin.cp.bean.external.WxCpGetMomentSendResult; -import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTask; -import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTaskResult; -import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplate; -import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplateAddResult; -import me.chanjar.weixin.cp.bean.external.WxCpUpdateRemarkRequest; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalContactList; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatInfo; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatList; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatStatistic; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatTransferResp; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalTagGroupInfo; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalTagGroupList; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalUnassignList; -import me.chanjar.weixin.cp.bean.external.WxCpUserExternalUserBehaviorStatistic; -import me.chanjar.weixin.cp.bean.external.WxCpUserTransferCustomerReq; -import me.chanjar.weixin.cp.bean.external.WxCpUserTransferCustomerResp; -import me.chanjar.weixin.cp.bean.external.WxCpUserTransferResultResp; -import me.chanjar.weixin.cp.bean.external.WxCpUserWithExternalPermission; -import me.chanjar.weixin.cp.bean.external.WxCpWelcomeMsg; +import me.chanjar.weixin.cp.bean.external.*; import me.chanjar.weixin.cp.bean.external.contact.*; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -157,6 +131,16 @@ public String unionidToExternalUserid(@NotNull String unionid,String openid) thr return tmpJson.get("external_userid").getAsString(); } + @Override + public String opengidToChatid(@NotNull String opengid) throws WxErrorException { + JsonObject json = new JsonObject(); + json.addProperty("opengid",opengid); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(OPENID_TO_CHATID); + String responseContent = this.mainService.post(url, json.toString()); + JsonObject tmpJson = GsonParser.parse(responseContent); + return tmpJson.get("chat_id").getAsString(); + } + @Override public WxCpExternalContactBatchInfo getContactDetailBatch(String[] userIdList, String cursor, @@ -586,7 +570,7 @@ public WxCpGroupMsgListResult getGroupMsgListV2(String chatType, @NonNull Date s json.addProperty("limit", limit); json.addProperty("cursor", cursor); - final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_GROUP_MSG_SEND_RESULT); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_GROUP_MSG_LIST_V2); final String result = this.mainService.post(url, json.toString()); return WxCpGroupMsgListResult.fromJson(result); } @@ -636,8 +620,86 @@ public WxCpGroupMsgTaskResult getGroupMsgTask(String msgid, Integer limit, Strin json.addProperty("limit", limit); json.addProperty("cursor", cursor); - final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_GROUP_MSG_SEND_RESULT); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_GROUP_MSG_TASK); final String result = this.mainService.post(url, json.toString()); return WxCpGroupMsgTaskResult.fromJson(result); } + + /** + *
+   * 添加入群欢迎语素材。
+   * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#添加入群欢迎语素材
+   * 
+ * + * @param template 素材内容 + * @return template_id 欢迎语素材id + * @throws WxErrorException the wx error exception + */ + @Override + public String addGroupWelcomeTemplate(WxCpGroupWelcomeTemplateResult template) throws WxErrorException { + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GROUP_WELCOME_TEMPLATE_ADD); + final String responseContent = this.mainService.post(url, template.toJson()); + JsonObject tmpJson = GsonParser.parse(responseContent); + return tmpJson.get("template_id").getAsString(); + } + + /** + *
+   * 编辑入群欢迎语素材。
+   * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#编辑入群欢迎语素材
+   * 
+ * + * @param template + * @return wx cp base resp + * @throws WxErrorException the wx error exception + */ + @Override + public WxCpBaseResp editGroupWelcomeTemplate(WxCpGroupWelcomeTemplateResult template) throws WxErrorException { + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GROUP_WELCOME_TEMPLATE_EDIT); + final String result = this.mainService.post(url, template.toJson()); + return WxCpGroupWelcomeTemplateResult.fromJson(result); + } + + /** + *
+   * 获取入群欢迎语素材。
+   * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#获取入群欢迎语素材
+   * 
+ * + * @param templateId 群欢迎语的素材id + * @return wx cp base resp + * @throws WxErrorException the wx error exception + */ + @Override + public WxCpGroupWelcomeTemplateResult getGroupWelcomeTemplate(@NotNull String templateId) throws WxErrorException { + JsonObject json = new JsonObject(); + json.addProperty("template_id", templateId); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GROUP_WELCOME_TEMPLATE_GET); + final String result = this.mainService.post(url, json.toString()); + return WxCpGroupWelcomeTemplateResult.fromJson(result); + } + + /** + *
+   * 删除入群欢迎语素材。
+   * 企业可通过此API删除入群欢迎语素材,且仅能删除调用方自己创建的入群欢迎语素材。
+   * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#删除入群欢迎语素材
+   * 
+ * + * @param templateId 群欢迎语的素材id + * @param agentId + * @return wx cp base resp + * @throws WxErrorException the wx error exception + */ + @Override + public WxCpBaseResp delGroupWelcomeTemplate(@NotNull String templateId, String agentId) throws WxErrorException { + JsonObject json = new JsonObject(); + json.addProperty("template_id", templateId); + if (!StringUtils.isEmpty(agentId)) { + json.addProperty("agentid", agentId); + } + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GROUP_WELCOME_TEMPLATE_DEL); + final String result = this.mainService.post(url, json.toString()); + return WxCpBaseResp.fromJson(result); + } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpGroupWelcomeTemplateResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpGroupWelcomeTemplateResult.java new file mode 100644 index 0000000000..5b92a02098 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpGroupWelcomeTemplateResult.java @@ -0,0 +1,45 @@ +package me.chanjar.weixin.cp.bean.external; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.external.msg.*; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; + +/** + * 入群欢迎语素材. + * + * @author Mr.Pan + * @date 2021-11-3 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpGroupWelcomeTemplateResult extends WxCpBaseResp implements Serializable { + private static final long serialVersionUID = -6406667238670580612L; + + private Text text; + + private Image image; + + private Link link; + + private MiniProgram miniprogram; + + private File file; + + private Video video; + + public static WxCpGroupWelcomeTemplateResult fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpGroupWelcomeTemplateResult.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index c09116d752..ddc56d133e 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -194,6 +194,7 @@ interface ExternalContact { String RESIGNED_TRANSFER_RESULT = "/cgi-bin/externalcontact/resigned/transfer_result"; String GROUP_CHAT_LIST = "/cgi-bin/externalcontact/groupchat/list"; String GROUP_CHAT_INFO = "/cgi-bin/externalcontact/groupchat/get"; + String OPENID_TO_CHATID= "/cgi-bin/externalcontact/opengid_to_chatid"; String GROUP_CHAT_TRANSFER = "/cgi-bin/externalcontact/groupchat/transfer"; String LIST_USER_BEHAVIOR_DATA = "/cgi-bin/externalcontact/get_user_behavior_data"; String LIST_GROUP_CHAT_DATA = "/cgi-bin/externalcontact/groupchat/statistic"; @@ -218,5 +219,10 @@ interface ExternalContact { String GET_GROUP_MSG_TASK = "/cgi-bin/externalcontact/get_groupmsg_task"; String GET_GROUP_MSG_LIST_V2 = "/cgi-bin/externalcontact/get_groupmsg_list_v2"; + String GROUP_WELCOME_TEMPLATE_ADD = "/cgi-bin/externalcontact/group_welcome_template/add"; + String GROUP_WELCOME_TEMPLATE_EDIT = "/cgi-bin/externalcontact/group_welcome_template/edit"; + String GROUP_WELCOME_TEMPLATE_GET = "/cgi-bin/externalcontact/group_welcome_template/get"; + String GROUP_WELCOME_TEMPLATE_DEL = "/cgi-bin/externalcontact/group_welcome_template/del"; + } }