Skip to content

Commit

Permalink
🆕 #2372【企业微信】新增客户群opengid转换和入群欢迎语素材管理相关接口
Browse files Browse the repository at this point in the history
  • Loading branch information
wslongchen authored Nov 3, 2021
1 parent dd83e16 commit 88301a6
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -740,4 +740,53 @@ WxCpGetMomentComments getMomentComments(String momentId, String userId)
*/
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

/**
* <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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";

}
}

0 comments on commit 88301a6

Please sign in to comment.