Skip to content

Commit 694f2c2

Browse files
authored
🆕 #1493 企业微信增加管理企业客户标签的相关接口
1 parent 0758049 commit 694f2c2

File tree

7 files changed

+272
-1
lines changed

7 files changed

+272
-1
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
9090
<email>[email protected]</email>
9191
<url>https://github.com/howardliu-cn</url>
9292
</developer>
93+
<developer>
94+
<name>huangxiaoming</name>
95+
<email>[email protected]</email>
96+
<url>https://github.com/huangxm129</url>
97+
</developer>
9398
</developers>
9499

95100
<scm>

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,61 @@ public interface WxCpExternalContactService {
246246
WxCpUserExternalGroupChatStatistic getGroupChatStatistic(Date startTime, Integer orderBy, Integer orderAsc, Integer pageIndex, Integer pageSize, String[] userIds, String[] partyIds) throws WxErrorException;
247247

248248
WxCpMsgTemplateAddResult addMsgTemplate(WxCpMsgTemplate wxCpMsgTemplate) throws WxErrorException;
249+
250+
251+
/**
252+
* <pre>
253+
* 企业可通过此接口获取企业客户标签详情。
254+
* </pre>
255+
* @param tagId
256+
* @return
257+
*/
258+
WxCpUserExternalTagGroup getCorpTagList(String [] tagId) throws WxErrorException;
259+
260+
261+
/**
262+
* <pre>
263+
* 企业可通过此接口向客户标签库中添加新的标签组和标签,每个企业最多可配置3000个企业标签。
264+
* 暂不支持第三方调用。
265+
* </pre>
266+
* @param tagGroup
267+
* @return
268+
*/
269+
WxCpUserExternalTagGroup addCorpTag(WxCpUserExternalTagGroup tagGroup)throws WxErrorException;
270+
271+
/**
272+
* <pre>
273+
* 企业可通过此接口编辑客户标签/标签组的名称或次序值。
274+
* 暂不支持第三方调用。
275+
* </pre>
276+
* @param id
277+
* @param name
278+
* @param order
279+
* @return
280+
*/
281+
WxCpBaseResp editCorpTag(String id,String name,Integer order)throws WxErrorException;
282+
283+
/**
284+
* <pre>
285+
* 企业可通过此接口删除客户标签库中的标签,或删除整个标签组。
286+
* 暂不支持第三方调用。
287+
* </pre>
288+
* @param tagId
289+
* @param groupId
290+
* @return
291+
*/
292+
WxCpBaseResp delCorpTag(String [] tagId,String[] groupId)throws WxErrorException;
293+
294+
/**
295+
* <pre>
296+
* 企业可通过此接口为指定成员的客户添加上由企业统一配置的标签。
297+
* https://work.weixin.qq.com/api/doc/90000/90135/92117
298+
* </pre>
299+
* @param userid
300+
* @param externalUserid
301+
* @param addTag
302+
* @param removeTag
303+
* @return
304+
*/
305+
WxCpBaseResp markTag(String userid,String externalUserid,String[] addTag,String [] removeTag)throws WxErrorException;
249306
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,70 @@ public WxCpMsgTemplateAddResult addMsgTemplate(WxCpMsgTemplate wxCpMsgTemplate)
223223
final String result = this.mainService.post(url, wxCpMsgTemplate.toJson());
224224
return WxCpMsgTemplateAddResult.fromJson(result);
225225
}
226+
227+
@Override
228+
public WxCpUserExternalTagGroup getCorpTagList(String[] tagId) throws WxErrorException {
229+
JsonObject json = new JsonObject();
230+
if(ArrayUtils.isNotEmpty(tagId)){
231+
json.add("tag_id",new Gson().toJsonTree(tagId).getAsJsonArray());
232+
}
233+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CORP_TAG_LIST);
234+
final String result = this.mainService.post(url,json.toString());
235+
return WxCpUserExternalTagGroup.fromJson(result);
236+
}
237+
238+
@Override
239+
public WxCpUserExternalTagGroup addCorpTag(WxCpUserExternalTagGroup tagGroup) throws WxErrorException{
240+
241+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_CORP_TAG);
242+
final String result = this.mainService.post(url,tagGroup.toJson());
243+
return WxCpUserExternalTagGroup.fromJson(result);
244+
}
245+
246+
@Override
247+
public WxCpBaseResp editCorpTag(String id, String name, Integer order) throws WxErrorException{
248+
249+
JsonObject json = new JsonObject();
250+
json.addProperty("id",id);
251+
json.addProperty("name",name);
252+
json.addProperty("order",order);
253+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(EDIT_CORP_TAG);
254+
final String result = this.mainService.post(url,json.toString());
255+
return WxCpBaseResp.fromJson(result);
256+
}
257+
258+
@Override
259+
public WxCpBaseResp delCorpTag(String[] tagId, String[] groupId) throws WxErrorException{
260+
JsonObject json = new JsonObject();
261+
if(ArrayUtils.isNotEmpty(tagId)){
262+
json.add("tag_id",new Gson().toJsonTree(tagId).getAsJsonArray());
263+
}
264+
if(ArrayUtils.isNotEmpty(groupId)){
265+
json.add("group_id",new Gson().toJsonTree(tagId).getAsJsonArray());
266+
}
267+
268+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEL_CORP_TAG);
269+
final String result = this.mainService.post(url,json.toString());
270+
return WxCpBaseResp.fromJson(result);
271+
}
272+
273+
@Override
274+
public WxCpBaseResp markTag(String userid, String externalUserid, String[] addTag, String[] removeTag)throws WxErrorException{
275+
276+
277+
JsonObject json = new JsonObject();
278+
json.addProperty("userid",userid);
279+
json.addProperty("external_userid",externalUserid);
280+
281+
if(ArrayUtils.isNotEmpty(addTag)){
282+
json.add("add_tag",new Gson().toJsonTree(addTag).getAsJsonArray());
283+
}
284+
if(ArrayUtils.isNotEmpty(removeTag)){
285+
json.add("remove_tag",new Gson().toJsonTree(removeTag).getAsJsonArray());
286+
}
287+
288+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(MARK_TAG);
289+
final String result = this.mainService.post(url,json.toString());
290+
return WxCpBaseResp.fromJson(result);
291+
}
226292
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package me.chanjar.weixin.cp.bean;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
7+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
8+
9+
import java.util.List;
10+
11+
/**
12+
*
13+
*/
14+
@Getter
15+
@Setter
16+
public class WxCpUserExternalTagGroup extends WxCpBaseResp {
17+
18+
@SerializedName("group_id")
19+
private String groupId;
20+
21+
@SerializedName("group_name")
22+
private String groupName;
23+
24+
@SerializedName("create_time")
25+
private Long createTime;
26+
27+
@SerializedName("order")
28+
private Integer order;
29+
30+
@SerializedName("deleted")
31+
private Boolean deleted;
32+
33+
34+
@SerializedName("tag")
35+
private List<Tag> tag;
36+
37+
@Getter
38+
@Setter
39+
public static class Tag {
40+
41+
/**
42+
* 客户群ID
43+
*/
44+
@SerializedName("id")
45+
private String id;
46+
47+
48+
@SerializedName("name")
49+
private String name;
50+
51+
@SerializedName("create_time")
52+
private Long createTime;
53+
54+
@SerializedName("order")
55+
private Integer order;
56+
57+
@SerializedName("deleted")
58+
private Boolean deleted;
59+
60+
}
61+
62+
public String toJson() {
63+
return WxGsonBuilder.create().toJson(this);
64+
}
65+
66+
public static WxCpUserExternalTagGroup fromJson(String json) {
67+
return WxCpGsonBuilder.create().fromJson(json, WxCpUserExternalTagGroup.class);
68+
}
69+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,11 @@ public static class ExternalContact {
132132
public static final String LIST_USER_BEHAVIOR_DATA = "/cgi-bin/externalcontact/get_user_behavior_data";
133133
public static final String LIST_GROUP_CHAT_DATA = "/cgi-bin/externalcontact/groupchat/statistic";
134134
public static final String ADD_MSG_TEMPLATE = "/cgi-bin/externalcontact/add_msg_template";
135+
136+
public static final String GET_CORP_TAG_LIST = "/cgi-bin/externalcontact/get_corp_tag_list";
137+
public static final String ADD_CORP_TAG = "/cgi-bin/externalcontact/add_corp_tag";
138+
public static final String EDIT_CORP_TAG = "/cgi-bin/externalcontact/edit_corp_tag";
139+
public static final String DEL_CORP_TAG = "/cgi-bin/externalcontact/del_corp_tag";
140+
public static final String MARK_TAG = "/cgi-bin/externalcontact/mark_tag";
135141
}
136142
}

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
99
import me.chanjar.weixin.cp.bean.WxCpContactWayInfo;
1010
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
11+
import me.chanjar.weixin.cp.bean.WxCpUserExternalTagGroup;
1112
import org.apache.commons.lang3.time.DateFormatUtils;
1213
import org.testng.annotations.Guice;
1314
import org.testng.annotations.Test;
1415

16+
import java.util.ArrayList;
1517
import java.util.Date;
1618
import java.util.List;
1719

@@ -105,4 +107,70 @@ public void testGetContactDetail() throws WxErrorException {
105107
assertNotNull(result);
106108
}
107109

110+
@Test
111+
public void testGetCorpTagList() throws WxErrorException {
112+
String tag[]={};
113+
WxCpUserExternalTagGroup result = this.wxCpService.getExternalContactService().getCorpTagList(null);
114+
System.out.println(result);
115+
assertNotNull(result);
116+
}
117+
118+
@Test
119+
public void testAddCorpTag() throws WxErrorException {
120+
121+
List<WxCpUserExternalTagGroup.Tag> list = new ArrayList<>();
122+
123+
WxCpUserExternalTagGroup.Tag tag = new WxCpUserExternalTagGroup.Tag();
124+
tag.setName("测试标签1");
125+
tag.setOrder(1);
126+
list.add(tag);
127+
128+
WxCpUserExternalTagGroup tagGroup = new WxCpUserExternalTagGroup();
129+
tagGroup.setGroupName("其他");
130+
tagGroup.setOrder(1);
131+
tagGroup.setTag(list);
132+
133+
WxCpUserExternalTagGroup result = this.wxCpService.getExternalContactService().addCorpTag(tagGroup);
134+
135+
136+
137+
System.out.println(result);
138+
assertNotNull(result);
139+
}
140+
141+
@Test
142+
public void testEditCorpTag() throws WxErrorException {
143+
144+
WxCpBaseResp result = this.wxCpService.getExternalContactService().editCorpTag("et2omCCwAArxYqGJQn4MNMS_zQKhIUfQ", "未知", 2);
145+
146+
System.out.println(result);
147+
assertNotNull(result);
148+
}
149+
150+
@Test
151+
public void testDelCorpTag() throws WxErrorException {
152+
153+
String tagId[] = {"et2omCCwAArxYqGJQn4MNMS_zQKhIUfQ"};
154+
String groupId[] = {};
155+
156+
WxCpBaseResp result = this.wxCpService.getExternalContactService().delCorpTag(tagId,groupId);
157+
158+
System.out.println(result);
159+
assertNotNull(result);
160+
}
161+
162+
@Test
163+
public void testMarkTag() throws WxErrorException {
164+
165+
String userid="HuangXiaoMing";
166+
String externalUserid="wo2omCCwAAzR0Rt1omz-90o_XJkPGXIQ";
167+
String addTag[] = {"et2omCCwAAzdcSK-RV80YS9sbpCXlNlQ"};
168+
String removeTag[] = {};
169+
170+
WxCpBaseResp result = this.wxCpService.getExternalContactService().markTag(userid,externalUserid,addTag,removeTag);
171+
172+
System.out.println(result);
173+
assertNotNull(result);
174+
}
175+
108176
}

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void testGetById() throws Exception {
7373

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

0 commit comments

Comments
 (0)