mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🆕 #1493 企业微信增加管理企业客户标签的相关接口
This commit is contained in:
parent
0758049ea9
commit
694f2c2b96
5
pom.xml
5
pom.xml
@ -90,6 +90,11 @@
|
||||
<email>liuxinghao1988@gmail.com</email>
|
||||
<url>https://github.com/howardliu-cn</url>
|
||||
</developer>
|
||||
<developer>
|
||||
<name>huangxiaoming</name>
|
||||
<email>huangxiaoming@163.com</email>
|
||||
<url>https://github.com/huangxm129</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -223,4 +223,70 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -132,5 +132,11 @@ public final class WxCpApiPathConsts {
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,12 @@ import me.chanjar.weixin.cp.api.WxCpService;
|
||||
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;
|
||||
|
||||
@ -105,4 +107,70 @@ public class WxCpExternalContactServiceImplTest {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class WxCpUserServiceImplTest {
|
||||
|
||||
@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));
|
||||
|
Loading…
Reference in New Issue
Block a user