Skip to content

【企业微信】【新增】客户群「加入群聊」管理 #2642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public interface WxCpExternalContactService {
* @throws WxErrorException the wx error exception
*/
WxCpContactWayInfo getContactWay(@NonNull String configId) throws WxErrorException;

/**
* 更新企业已配置的「联系我」方式
*
Expand Down Expand Up @@ -171,6 +170,50 @@ public interface WxCpExternalContactService {
*/
String unionidToExternalUserid(@NotNull String unionid,String openid) throws WxErrorException;

/**
*
* 配置客户群进群方式
* 企业可以在管理后台-客户联系中配置「加入群聊」的二维码或者小程序按钮,客户通过扫描二维码或点击小程序上的按钮,即可加入特定的客户群。
* 企业可通过此接口为具有客户联系功能的成员生成专属的二维码或者小程序按钮。
* 如果配置的是小程序按钮,需要开发者的小程序接入小程序插件。
* 注意:
* 通过API添加的配置不会在管理端进行展示,每个企业可通过API最多配置50万个「加入群聊」(与「联系我」共用50万的额度)。
* 文档地址:https://developer.work.weixin.qq.com/document/path/92229
* @param wxCpGroupJoinWayInfo
* @return {@link WxCpGroupJoinWayResult}
* @throws WxErrorException
*/
WxCpGroupJoinWayResult addJoinWay(@NonNull WxCpGroupJoinWayInfo wxCpGroupJoinWayInfo) throws WxErrorException;

/**
*更新客户群进群方式配置
* 更新进群方式配置信息。注意:使用覆盖的方式更新。
* 文档地址:https://developer.work.weixin.qq.com/document/path/92229
* @param wxCpGroupJoinWayInfo
* @return
* @throws WxErrorException
*/
WxCpBaseResp updateJoinWay(@NonNull WxCpGroupJoinWayInfo wxCpGroupJoinWayInfo) throws WxErrorException;

/**
* 获取客户群进群方式配置
* 获取企业配置的群二维码或小程序按钮。
* 文档地址:https://developer.work.weixin.qq.com/document/path/92229
* @param configId
* @return
* @throws WxErrorException
*/
WxCpGroupJoinWayInfo getJoinWay(@NonNull String configId) throws WxErrorException;

/**
* 删除客户群进群方式配置
* 文档地址:https://developer.work.weixin.qq.com/document/path/92229
* @param configId
* @return
* @throws WxErrorException
*/
WxCpBaseResp delJoinWay( @NonNull String configId) throws WxErrorException;

/**
* 代开发应用external_userid转换
* <pre>
Expand Down Expand Up @@ -1025,4 +1068,5 @@ WxMediaUploadResult uploadAttachment(String mediaType, Integer attachmentType, F
* @param productId 商品id
*/
void deleteProductAlbum(String productId) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -882,5 +882,43 @@ public void deleteProductAlbum(String productId) throws WxErrorException {
this.mainService.post(url, o.toString());
}

@Override
public WxCpGroupJoinWayResult addJoinWay(@NonNull WxCpGroupJoinWayInfo wxCpGroupJoinWayInfo) throws WxErrorException {
if (wxCpGroupJoinWayInfo.getJoinWay().getChatIdList() != null && wxCpGroupJoinWayInfo.getJoinWay().getChatIdList().size() > 5) {
throw new WxRuntimeException("使用该配置的客户群ID列表,支持5个");
}
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_JOIN_WAY);
String responseContent = this.mainService.post(url, wxCpGroupJoinWayInfo.getJoinWay().toJson());

return WxCpGroupJoinWayResult.fromJson(responseContent);
}

@Override
public WxCpBaseResp updateJoinWay(@NonNull WxCpGroupJoinWayInfo wxCpGroupJoinWayInfo) throws WxErrorException {
if (wxCpGroupJoinWayInfo.getJoinWay().getChatIdList() != null && wxCpGroupJoinWayInfo.getJoinWay().getChatIdList().size() > 5) {
throw new WxRuntimeException("使用该配置的客户群ID列表,支持5个");
}
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_JOIN_WAY);
String responseContent = this.mainService.post(url, wxCpGroupJoinWayInfo.getJoinWay().toJson());
return WxCpBaseResp.fromJson(responseContent);
}

@Override
public WxCpGroupJoinWayInfo getJoinWay(String configId) throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("config_id", configId);
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_JOIN_WAY);
String responseContent = this.mainService.post(url,json);

return WxCpGroupJoinWayInfo.fromJson(responseContent);
}

@Override
public WxCpBaseResp delJoinWay(@NonNull String configId) throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("config_id", configId);
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEL_JOIN_WAY);
String responseContent = this.mainService.post(url, json);
return WxCpBaseResp.fromJson(responseContent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package me.chanjar.weixin.cp.bean.external;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;
import java.util.List;

/**
*客户群「加入群聊」对象
* @author Jc
*/
@Data
@NoArgsConstructor
public class WxCpGroupJoinWayInfo implements Serializable {
private static final long serialVersionUID = 5621905029624794129L;
@SerializedName("join_way")
private JoinWay joinWay;
@Getter
@Setter
public static class JoinWay implements Serializable {
private static final long serialVersionUID = 5621905029624794122L;

/**
* 联系方式的配置id
*/
@SerializedName("config_id")
private String configId;
/**
* 场景。
* 1 - 群的小程序插件
* 2 - 群的二维码插件
*/
@SerializedName("scene")
private Integer scene;
/**
* 联系方式的备注信息,用于助记,超过30个字符将被截断
*/
@SerializedName("remark")
private String remark;
/**
* 当群满了后,是否自动新建群。0-否;1-是。 默认为1
*/
@SerializedName("auto_create_room")
private Integer autoCreateRoom;
/**
* 自动建群的群名前缀,当auto_create_room为1时有效。最长40个utf8字符
*/
@SerializedName("room_base_name")
private String roomBaseName;
/**
* 自动建群的群起始序号,当auto_create_room为1时有效
*/
@SerializedName("room_base_id")
private Integer roomBaseId;
/**
* 使用该配置的客户群ID列表,支持5个。
*/
@SerializedName("chat_id_list")
private List<String> chatIdList;
/**
* 联系二维码的URL,仅在配置为群二维码时返回
*/
@SerializedName("qr_code")
private String qrCode;
/**
企业自定义的state参数,用于区分不同的入群渠道。不超过30个UTF-8字符
如果有设置此参数,在调用获取客户群详情接口时会返回每个群成员对应的该参数值
*/
@SerializedName("state")
private Integer state;

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
public static WxCpGroupJoinWayInfo.JoinWay fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpGroupJoinWayInfo.JoinWay.class);
}
}

public static WxCpGroupJoinWayInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpGroupJoinWayInfo.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.chanjar.weixin.cp.bean.external;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

/**
*客户群「加入群聊」配置处理结果
* @author Jc
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class WxCpGroupJoinWayResult extends WxCpBaseResp {
private static final long serialVersionUID = 5621905029624794129L;
@SerializedName("config_id")
private String configId;

public static WxCpGroupJoinWayResult fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpGroupJoinWayResult.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ interface ExternalContact {
String UPDATE_REMARK = "/cgi-bin/externalcontact/remark";
String LIST_EXTERNAL_CONTACT = "/cgi-bin/externalcontact/list?userid=";
String LIST_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/get_unassigned_list";

@Deprecated
String TRANSFER_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/transfer";
String TRANSFER_CUSTOMER = "/cgi-bin/externalcontact/transfer_customer";
Expand All @@ -273,6 +274,10 @@ interface ExternalContact {
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";
String ADD_JOIN_WAY = "/cgi-bin/externalcontact/groupchat/add_join_way";
String GET_JOIN_WAY = "/cgi-bin/externalcontact/groupchat/get_join_way";
String UPDATE_JOIN_WAY = "/cgi-bin/externalcontact/groupchat/update_join_way";
String DEL_JOIN_WAY = "/cgi-bin/externalcontact/groupchat/del_join_way";
String ADD_MSG_TEMPLATE = "/cgi-bin/externalcontact/add_msg_template";
String SEND_WELCOME_MSG = "/cgi-bin/externalcontact/send_welcome_msg";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import me.chanjar.weixin.cp.bean.external.msg.Attachment;
import me.chanjar.weixin.cp.bean.external.msg.Image;
import me.chanjar.weixin.cp.bean.external.msg.Video;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.*;

import org.testng.collections.CollectionUtils;

import static org.testng.Assert.assertNotNull;
Expand Down Expand Up @@ -337,4 +336,51 @@ public void testGetMomentList() throws WxErrorException {
assertNotNull(result);
}

@Test
public void testAddJoinWay() throws WxErrorException {


WxCpGroupJoinWayInfo.JoinWay joinWay = new WxCpGroupJoinWayInfo.JoinWay();
joinWay.setChatIdList(Arrays.asList("wrfpBaCwAAxR-iIqIUa5vvbpZQcAexJA"));
joinWay.setScene(2);
joinWay.setAutoCreateRoom(1);
joinWay.setRemark("CreateDate:" + DateFormatUtils.ISO_8601_EXTENDED_DATETIME_FORMAT.format(new Date()));

WxCpGroupJoinWayInfo info = new WxCpGroupJoinWayInfo();
info.setJoinWay(joinWay);
this.wxCpService.getExternalContactService().addJoinWay(info);
}

@Test
public void testUpdateJoinWay() throws WxErrorException {

final String configId = "";

WxCpGroupJoinWayInfo.JoinWay joinWay = new WxCpGroupJoinWayInfo.JoinWay();
joinWay.setConfigId(configId);
joinWay.setChatIdList(Arrays.asList("wrfpBaCwAAxR-iIqIUa5vvbpZQcAexJA"));
joinWay.setScene(2);
joinWay.setAutoCreateRoom(1);
joinWay.setRemark("CreateDate:" + DateFormatUtils.ISO_8601_EXTENDED_DATETIME_FORMAT.format(new Date()));

WxCpGroupJoinWayInfo info = new WxCpGroupJoinWayInfo();
info.setJoinWay(joinWay);
this.wxCpService.getExternalContactService().updateJoinWay(info);
}

@Test
public void testDelJoinWay() throws WxErrorException {

final String configId = "";

this.wxCpService.getExternalContactService().delJoinWay(configId);
}

@Test
public void testGetJoinWay() throws WxErrorException {

final String configId = "";

this.wxCpService.getExternalContactService().getJoinWay(configId);
}
}