mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-11-01 00:46:54 +08:00 
			
		
		
		
	🆕 #2372【企业微信】新增客户群opengid转换和入群欢迎语素材管理相关接口
This commit is contained in:
		| @@ -3,31 +3,7 @@ package me.chanjar.weixin.cp.api; | ||||
| 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转换 | ||||
|    * <pre> | ||||
|    * | ||||
|    * 文档地址:https://open.work.weixin.qq.com/api/doc/90000/90135/94822 | ||||
|    * | ||||
|    * 用户在微信里的客户群里打开小程序时,某些场景下可以获取到群的opengid,如果该群是企业微信的客户群, | ||||
|    * 则企业或第三方可以调用此接口将一个opengid转换为客户群chat_id | ||||
|    * | ||||
|    * 权限说明: | ||||
|    * | ||||
|    * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?) | ||||
|    * 第三方应用需具有“企业客户权限->客户基础信息”权限 | ||||
|    * 对于第三方/自建应用,群主必须在应用的可见范围 | ||||
|    * 仅支持企业服务人员创建的客户群 | ||||
|    * 仅可转换出自己企业下的客户群chat_id | ||||
|    * </pre> | ||||
|    * | ||||
|    * @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; | ||||
|    | ||||
|   /** | ||||
|    * 批量获取客户详情. | ||||
|    * <pre> | ||||
| @@ -740,4 +740,53 @@ public interface WxCpExternalContactService { | ||||
|    */ | ||||
|    WxCpGroupMsgTaskResult getGroupMsgTask(String msgid, Integer limit, String cursor) throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 添加入群欢迎语素材。 | ||||
|    * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#添加入群欢迎语素材 | ||||
|    * </pre> | ||||
|    * | ||||
|    * @param template          素材内容 | ||||
|    * @return template_id      欢迎语素材id | ||||
|    * @throws WxErrorException the wx error exception | ||||
|    */ | ||||
|   String addGroupWelcomeTemplate(WxCpGroupWelcomeTemplateResult template) throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 编辑入群欢迎语素材。 | ||||
|    * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#编辑入群欢迎语素材 | ||||
|    * </pre> | ||||
|    * | ||||
|    * @param template | ||||
|    * @return wx cp base resp | ||||
|    * @throws WxErrorException the wx error exception | ||||
|    */ | ||||
|   WxCpBaseResp editGroupWelcomeTemplate(WxCpGroupWelcomeTemplateResult template) throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 获取入群欢迎语素材。 | ||||
|    * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#获取入群欢迎语素材 | ||||
|    * </pre> | ||||
|    * | ||||
|    * @param templateId        群欢迎语的素材id | ||||
|    * @return wx cp base resp | ||||
|    * @throws WxErrorException the wx error exception | ||||
|    */ | ||||
|   WxCpGroupWelcomeTemplateResult getGroupWelcomeTemplate(@NotNull String templateId) throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 删除入群欢迎语素材。 | ||||
|    * 企业可通过此API删除入群欢迎语素材,且仅能删除调用方自己创建的入群欢迎语素材。 | ||||
|    * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#删除入群欢迎语素材 | ||||
|    * </pre> | ||||
|    * | ||||
|    * @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; | ||||
| } | ||||
|   | ||||
| @@ -12,33 +12,7 @@ import me.chanjar.weixin.common.util.json.GsonParser; | ||||
| 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 class WxCpExternalContactServiceImpl implements WxCpExternalContactServic | ||||
|     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 class WxCpExternalContactServiceImpl implements WxCpExternalContactServic | ||||
|     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 class WxCpExternalContactServiceImpl implements WxCpExternalContactServic | ||||
|     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); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 添加入群欢迎语素材。 | ||||
|    * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#添加入群欢迎语素材 | ||||
|    * </pre> | ||||
|    * | ||||
|    * @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(); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 编辑入群欢迎语素材。 | ||||
|    * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#编辑入群欢迎语素材 | ||||
|    * </pre> | ||||
|    * | ||||
|    * @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); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 获取入群欢迎语素材。 | ||||
|    * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#获取入群欢迎语素材 | ||||
|    * </pre> | ||||
|    * | ||||
|    * @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); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 删除入群欢迎语素材。 | ||||
|    * 企业可通过此API删除入群欢迎语素材,且仅能删除调用方自己创建的入群欢迎语素材。 | ||||
|    * https://open.work.weixin.qq.com/api/doc/90000/90135/92366#删除入群欢迎语素材 | ||||
|    * </pre> | ||||
|    * | ||||
|    * @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); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -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 <a href="https://github.com/wslongchen">Mr.Pan</a> | ||||
|  * @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); | ||||
|   } | ||||
| } | ||||
| @@ -194,6 +194,7 @@ public interface WxCpApiPathConsts { | ||||
|     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 @@ public interface WxCpApiPathConsts { | ||||
|     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"; | ||||
|  | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 潘安
					潘安