Skip to content

Commit b5c3b5e

Browse files
committed
binarywang#550 企业微信删除标签成员接口增加部门列表参数
1 parent 94b2803 commit b5c3b5e

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,71 @@
1010

1111
/**
1212
* <pre>
13-
* 标签管理接口
13+
* 标签管理接口.
1414
* Created by BinaryWang on 2017/6/24.
1515
* </pre>
1616
*
1717
* @author <a href="https://github.com/binarywang">Binary Wang</a>
1818
*/
1919
public interface WxCpTagService {
2020
/**
21-
* 创建标签
21+
* 创建标签.
2222
*
2323
* @param tagName 标签名
2424
*/
2525
String create(String tagName) throws WxErrorException;
2626

2727
/**
28-
* 更新标签
28+
* 更新标签.
2929
*
3030
* @param tagId 标签id
3131
* @param tagName 标签名
3232
*/
3333
void update(String tagId, String tagName) throws WxErrorException;
3434

3535
/**
36-
* 删除标签
36+
* 删除标签.
3737
*
3838
* @param tagId 标签id
3939
*/
4040
void delete(String tagId) throws WxErrorException;
4141

4242
/**
43-
* 获得标签列表
43+
* 获得标签列表.
4444
*/
4545
List<WxCpTag> listAll() throws WxErrorException;
4646

4747
/**
48-
* 获取标签成员
48+
* 获取标签成员.
4949
*
5050
* @param tagId 标签ID
5151
*/
5252
List<WxCpUser> listUsersByTagId(String tagId) throws WxErrorException;
5353

5454
/**
55-
* 增加标签成员
56-
* @param tagId 标签id
57-
* @param userIds 用户ID 列表
55+
* 增加标签成员.
56+
*
57+
* @param tagId 标签id
58+
* @param userIds 用户ID 列表
59+
* @param partyIds 企业部门ID列表
5860
*/
5961
WxCpTagAddOrRemoveUsersResult addUsers2Tag(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException;
6062

6163
/**
62-
* 移除标签成员
63-
* @param tagId 标签id
64-
* @param userIds 用户id列表
64+
* 移除标签成员.
65+
*
66+
* @param tagId 标签id
67+
* @param userIds 用户id列表
68+
* @param partyIds 企业部门ID列表
6569
*/
66-
WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds) throws WxErrorException;
70+
WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException;
6771

6872

6973
/**
70-
* 获取标签成员
74+
* 获取标签成员.
7175
* 对应: http://qydev.weixin.qq.com/wiki/index.php?title=管理标签 中的get接口
7276
*
73-
* @param tagId
74-
* @return
75-
* @throws WxErrorException
77+
* @param tagId 标签id
7678
*/
7779
WxCpTagGetResult get(String tagId) throws WxErrorException;
7880

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,36 +83,37 @@ public WxCpTagAddOrRemoveUsersResult addUsers2Tag(String tagId, List<String> use
8383
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
8484
JsonObject jsonObject = new JsonObject();
8585
jsonObject.addProperty("tagid", tagId);
86+
this.addUserIdsAndPartyIdsToJson(userIds, partyIds, jsonObject);
87+
88+
return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
89+
}
90+
91+
@Override
92+
public WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException {
93+
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers";
94+
JsonObject jsonObject = new JsonObject();
95+
jsonObject.addProperty("tagid", tagId);
96+
this.addUserIdsAndPartyIdsToJson(userIds, partyIds, jsonObject);
97+
98+
return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
99+
}
100+
101+
private void addUserIdsAndPartyIdsToJson(List<String> userIds, List<String> partyIds, JsonObject jsonObject) {
86102
if (userIds != null) {
87103
JsonArray jsonArray = new JsonArray();
88104
for (String userId : userIds) {
89105
jsonArray.add(new JsonPrimitive(userId));
90106
}
91107
jsonObject.add("userlist", jsonArray);
92108
}
109+
93110
if (partyIds != null) {
94111
JsonArray jsonArray = new JsonArray();
95112
for (String userId : partyIds) {
96113
jsonArray.add(new JsonPrimitive(userId));
97114
}
98115
jsonObject.add("partylist", jsonArray);
99116
}
100-
101-
return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
102-
}
103-
104-
@Override
105-
public WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds) throws WxErrorException {
106-
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers";
107-
JsonObject jsonObject = new JsonObject();
108-
jsonObject.addProperty("tagid", tagId);
109-
JsonArray jsonArray = new JsonArray();
110-
for (String userId : userIds) {
111-
jsonArray.add(new JsonPrimitive(userId));
112-
}
113-
jsonObject.add("userlist", jsonArray);
114-
115-
return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
116117
}
117118

118119
@Override

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
1111
import me.chanjar.weixin.cp.bean.WxCpTagGetResult;
1212
import me.chanjar.weixin.cp.bean.WxCpUser;
13-
import org.testng.annotations.*;
13+
import org.testng.annotations.Guice;
14+
import org.testng.annotations.Test;
1415

1516
import java.util.List;
1617

1718
import static org.mockito.Mockito.mock;
1819
import static org.mockito.Mockito.when;
19-
import static org.testng.Assert.*;
20+
import static org.testng.Assert.assertEquals;
21+
import static org.testng.Assert.assertNotEquals;
2022

2123
/**
2224
* <pre>
@@ -68,7 +70,7 @@ public void testListUsersByTagId() throws Exception {
6870
@Test(dependsOnMethods = {"testListUsersByTagId", "testAddUsers2Tag", "testListAll", "testUpdate", "testCreate"})
6971
public void testRemoveUsersFromTag() throws Exception {
7072
List<String> userIds = Splitter.on("|").splitToList(this.configStorage.getUserId());
71-
WxCpTagAddOrRemoveUsersResult result = this.wxService.getTagService().removeUsersFromTag(this.tagId, userIds);
73+
WxCpTagAddOrRemoveUsersResult result = this.wxService.getTagService().removeUsersFromTag(this.tagId, userIds, null);
7274
assertEquals(result.getErrCode(), Integer.valueOf(0));
7375
}
7476

0 commit comments

Comments
 (0)