Skip to content

Commit

Permalink
🆕 #1493 企业微信增加管理企业客户标签的相关接口
Browse files Browse the repository at this point in the history
  • Loading branch information
huangxm129 authored Jul 26, 2020
1 parent 0758049 commit 694f2c2
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
<email>[email protected]</email>
<url>https://github.com/howardliu-cn</url>
</developer>
<developer>
<name>huangxiaoming</name>
<email>[email protected]</email>
<url>https://github.com/huangxm129</url>
</developer>
</developers>

<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,61 @@ public interface WxCpExternalContactService {
WxCpUserExternalGroupChatStatistic getGroupChatStatistic(Date startTime, Integer orderBy, Integer orderAsc, Integer pageIndex, Integer pageSize, String[] userIds, String[] partyIds) throws WxErrorException;

WxCpMsgTemplateAddResult addMsgTemplate(WxCpMsgTemplate wxCpMsgTemplate) throws WxErrorException;


/**
* <pre>
* 企业可通过此接口获取企业客户标签详情。
* </pre>
* @param tagId
* @return
*/
WxCpUserExternalTagGroup getCorpTagList(String [] tagId) throws WxErrorException;


/**
* <pre>
* 企业可通过此接口向客户标签库中添加新的标签组和标签,每个企业最多可配置3000个企业标签。
* 暂不支持第三方调用。
* </pre>
* @param tagGroup
* @return
*/
WxCpUserExternalTagGroup addCorpTag(WxCpUserExternalTagGroup tagGroup)throws WxErrorException;

/**
* <pre>
* 企业可通过此接口编辑客户标签/标签组的名称或次序值。
* 暂不支持第三方调用。
* </pre>
* @param id
* @param name
* @param order
* @return
*/
WxCpBaseResp editCorpTag(String id,String name,Integer order)throws WxErrorException;

/**
* <pre>
* 企业可通过此接口删除客户标签库中的标签,或删除整个标签组。
* 暂不支持第三方调用。
* </pre>
* @param tagId
* @param groupId
* @return
*/
WxCpBaseResp delCorpTag(String [] tagId,String[] groupId)throws WxErrorException;

/**
* <pre>
* 企业可通过此接口为指定成员的客户添加上由企业统一配置的标签。
* https://work.weixin.qq.com/api/doc/90000/90135/92117
* </pre>
* @param userid
* @param externalUserid
* @param addTag
* @param removeTag
* @return
*/
WxCpBaseResp markTag(String userid,String externalUserid,String[] addTag,String [] removeTag)throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,70 @@ public WxCpMsgTemplateAddResult addMsgTemplate(WxCpMsgTemplate wxCpMsgTemplate)
final String result = this.mainService.post(url, wxCpMsgTemplate.toJson());
return WxCpMsgTemplateAddResult.fromJson(result);
}

@Override
public WxCpUserExternalTagGroup getCorpTagList(String[] tagId) throws WxErrorException {
JsonObject json = new JsonObject();
if(ArrayUtils.isNotEmpty(tagId)){
json.add("tag_id",new Gson().toJsonTree(tagId).getAsJsonArray());
}
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CORP_TAG_LIST);
final String result = this.mainService.post(url,json.toString());
return WxCpUserExternalTagGroup.fromJson(result);
}

@Override
public WxCpUserExternalTagGroup addCorpTag(WxCpUserExternalTagGroup tagGroup) throws WxErrorException{

final String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_CORP_TAG);
final String result = this.mainService.post(url,tagGroup.toJson());
return WxCpUserExternalTagGroup.fromJson(result);
}

@Override
public WxCpBaseResp editCorpTag(String id, String name, Integer order) throws WxErrorException{

JsonObject json = new JsonObject();
json.addProperty("id",id);
json.addProperty("name",name);
json.addProperty("order",order);
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(EDIT_CORP_TAG);
final String result = this.mainService.post(url,json.toString());
return WxCpBaseResp.fromJson(result);
}

@Override
public WxCpBaseResp delCorpTag(String[] tagId, String[] groupId) throws WxErrorException{
JsonObject json = new JsonObject();
if(ArrayUtils.isNotEmpty(tagId)){
json.add("tag_id",new Gson().toJsonTree(tagId).getAsJsonArray());
}
if(ArrayUtils.isNotEmpty(groupId)){
json.add("group_id",new Gson().toJsonTree(tagId).getAsJsonArray());
}

final String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEL_CORP_TAG);
final String result = this.mainService.post(url,json.toString());
return WxCpBaseResp.fromJson(result);
}

@Override
public WxCpBaseResp markTag(String userid, String externalUserid, String[] addTag, String[] removeTag)throws WxErrorException{


JsonObject json = new JsonObject();
json.addProperty("userid",userid);
json.addProperty("external_userid",externalUserid);

if(ArrayUtils.isNotEmpty(addTag)){
json.add("add_tag",new Gson().toJsonTree(addTag).getAsJsonArray());
}
if(ArrayUtils.isNotEmpty(removeTag)){
json.add("remove_tag",new Gson().toJsonTree(removeTag).getAsJsonArray());
}

final String url = this.mainService.getWxCpConfigStorage().getApiUrl(MARK_TAG);
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,69 @@
package me.chanjar.weixin.cp.bean;

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

import java.util.List;

/**
*
*/
@Getter
@Setter
public class WxCpUserExternalTagGroup extends WxCpBaseResp {

@SerializedName("group_id")
private String groupId;

@SerializedName("group_name")
private String groupName;

@SerializedName("create_time")
private Long createTime;

@SerializedName("order")
private Integer order;

@SerializedName("deleted")
private Boolean deleted;


@SerializedName("tag")
private List<Tag> tag;

@Getter
@Setter
public static class Tag {

/**
* 客户群ID
*/
@SerializedName("id")
private String id;


@SerializedName("name")
private String name;

@SerializedName("create_time")
private Long createTime;

@SerializedName("order")
private Integer order;

@SerializedName("deleted")
private Boolean deleted;

}

public String toJson() {
return WxGsonBuilder.create().toJson(this);
}

public static WxCpUserExternalTagGroup fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpUserExternalTagGroup.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,11 @@ public static class ExternalContact {
public static final String LIST_USER_BEHAVIOR_DATA = "/cgi-bin/externalcontact/get_user_behavior_data";
public static final String LIST_GROUP_CHAT_DATA = "/cgi-bin/externalcontact/groupchat/statistic";
public static final String ADD_MSG_TEMPLATE = "/cgi-bin/externalcontact/add_msg_template";

public static final String GET_CORP_TAG_LIST = "/cgi-bin/externalcontact/get_corp_tag_list";
public static final String ADD_CORP_TAG = "/cgi-bin/externalcontact/add_corp_tag";
public static final String EDIT_CORP_TAG = "/cgi-bin/externalcontact/edit_corp_tag";
public static final String DEL_CORP_TAG = "/cgi-bin/externalcontact/del_corp_tag";
public static final String MARK_TAG = "/cgi-bin/externalcontact/mark_tag";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.WxCpContactWayInfo;
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
import me.chanjar.weixin.cp.bean.WxCpUserExternalTagGroup;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

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

Expand Down Expand Up @@ -105,4 +107,70 @@ public void testGetContactDetail() throws WxErrorException {
assertNotNull(result);
}

@Test
public void testGetCorpTagList() throws WxErrorException {
String tag[]={};
WxCpUserExternalTagGroup result = this.wxCpService.getExternalContactService().getCorpTagList(null);
System.out.println(result);
assertNotNull(result);
}

@Test
public void testAddCorpTag() throws WxErrorException {

List<WxCpUserExternalTagGroup.Tag> list = new ArrayList<>();

WxCpUserExternalTagGroup.Tag tag = new WxCpUserExternalTagGroup.Tag();
tag.setName("测试标签1");
tag.setOrder(1);
list.add(tag);

WxCpUserExternalTagGroup tagGroup = new WxCpUserExternalTagGroup();
tagGroup.setGroupName("其他");
tagGroup.setOrder(1);
tagGroup.setTag(list);

WxCpUserExternalTagGroup result = this.wxCpService.getExternalContactService().addCorpTag(tagGroup);



System.out.println(result);
assertNotNull(result);
}

@Test
public void testEditCorpTag() throws WxErrorException {

WxCpBaseResp result = this.wxCpService.getExternalContactService().editCorpTag("et2omCCwAArxYqGJQn4MNMS_zQKhIUfQ", "未知", 2);

System.out.println(result);
assertNotNull(result);
}

@Test
public void testDelCorpTag() throws WxErrorException {

String tagId[] = {"et2omCCwAArxYqGJQn4MNMS_zQKhIUfQ"};
String groupId[] = {};

WxCpBaseResp result = this.wxCpService.getExternalContactService().delCorpTag(tagId,groupId);

System.out.println(result);
assertNotNull(result);
}

@Test
public void testMarkTag() throws WxErrorException {

String userid="HuangXiaoMing";
String externalUserid="wo2omCCwAAzR0Rt1omz-90o_XJkPGXIQ";
String addTag[] = {"et2omCCwAAzdcSK-RV80YS9sbpCXlNlQ"};
String removeTag[] = {};

WxCpBaseResp result = this.wxCpService.getExternalContactService().markTag(userid,externalUserid,addTag,removeTag);

System.out.println(result);
assertNotNull(result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void testGetById() throws Exception {

@Test
public void testListByDepartment() throws Exception {
List<WxCpUser> users = this.wxCpService.getUserService().listByDepartment(1L, true, 0);
List<WxCpUser> users = this.wxCpService.getUserService().listByDepartment(2L, true, 0);
assertNotEquals(users.size(), 0);
for (WxCpUser user : users) {
System.out.println(ToStringBuilder.reflectionToString(user, ToStringStyle.MULTI_LINE_STYLE));
Expand Down

0 comments on commit 694f2c2

Please sign in to comment.