mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 07:23:01 +08:00
#550 企业微信删除标签成员接口增加部门列表参数
This commit is contained in:
parent
94b2803842
commit
b5c3b5e59a
@ -10,7 +10,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 标签管理接口
|
||||
* 标签管理接口.
|
||||
* Created by BinaryWang on 2017/6/24.
|
||||
* </pre>
|
||||
*
|
||||
@ -18,14 +18,14 @@ import java.util.List;
|
||||
*/
|
||||
public interface WxCpTagService {
|
||||
/**
|
||||
* 创建标签
|
||||
* 创建标签.
|
||||
*
|
||||
* @param tagName 标签名
|
||||
*/
|
||||
String create(String tagName) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 更新标签
|
||||
* 更新标签.
|
||||
*
|
||||
* @param tagId 标签id
|
||||
* @param tagName 标签名
|
||||
@ -33,46 +33,48 @@ public interface WxCpTagService {
|
||||
void update(String tagId, String tagName) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 删除标签
|
||||
* 删除标签.
|
||||
*
|
||||
* @param tagId 标签id
|
||||
*/
|
||||
void delete(String tagId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获得标签列表
|
||||
* 获得标签列表.
|
||||
*/
|
||||
List<WxCpTag> listAll() throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取标签成员
|
||||
* 获取标签成员.
|
||||
*
|
||||
* @param tagId 标签ID
|
||||
*/
|
||||
List<WxCpUser> listUsersByTagId(String tagId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 增加标签成员
|
||||
* 增加标签成员.
|
||||
*
|
||||
* @param tagId 标签id
|
||||
* @param userIds 用户ID 列表
|
||||
* @param partyIds 企业部门ID列表
|
||||
*/
|
||||
WxCpTagAddOrRemoveUsersResult addUsers2Tag(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 移除标签成员
|
||||
* 移除标签成员.
|
||||
*
|
||||
* @param tagId 标签id
|
||||
* @param userIds 用户id列表
|
||||
* @param partyIds 企业部门ID列表
|
||||
*/
|
||||
WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds) throws WxErrorException;
|
||||
WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException;
|
||||
|
||||
|
||||
/**
|
||||
* 获取标签成员
|
||||
* 获取标签成员.
|
||||
* 对应: http://qydev.weixin.qq.com/wiki/index.php?title=管理标签 中的get接口
|
||||
*
|
||||
* @param tagId
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
* @param tagId 标签id
|
||||
*/
|
||||
WxCpTagGetResult get(String tagId) throws WxErrorException;
|
||||
|
||||
|
@ -83,6 +83,22 @@ public class WxCpTagServiceImpl implements WxCpTagService {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("tagid", tagId);
|
||||
this.addUserIdsAndPartyIdsToJson(userIds, partyIds, jsonObject);
|
||||
|
||||
return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers";
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("tagid", tagId);
|
||||
this.addUserIdsAndPartyIdsToJson(userIds, partyIds, jsonObject);
|
||||
|
||||
return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
|
||||
}
|
||||
|
||||
private void addUserIdsAndPartyIdsToJson(List<String> userIds, List<String> partyIds, JsonObject jsonObject) {
|
||||
if (userIds != null) {
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
for (String userId : userIds) {
|
||||
@ -90,6 +106,7 @@ public class WxCpTagServiceImpl implements WxCpTagService {
|
||||
}
|
||||
jsonObject.add("userlist", jsonArray);
|
||||
}
|
||||
|
||||
if (partyIds != null) {
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
for (String userId : partyIds) {
|
||||
@ -97,22 +114,6 @@ public class WxCpTagServiceImpl implements WxCpTagService {
|
||||
}
|
||||
jsonObject.add("partylist", jsonArray);
|
||||
}
|
||||
|
||||
return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers";
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("tagid", tagId);
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
for (String userId : userIds) {
|
||||
jsonArray.add(new JsonPrimitive(userId));
|
||||
}
|
||||
jsonObject.add("userlist", jsonArray);
|
||||
|
||||
return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,13 +10,15 @@ import me.chanjar.weixin.cp.bean.WxCpTag;
|
||||
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
|
||||
import me.chanjar.weixin.cp.bean.WxCpTagGetResult;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import org.testng.annotations.*;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.testng.Assert.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@ -68,7 +70,7 @@ public class WxCpTagServiceImplTest {
|
||||
@Test(dependsOnMethods = {"testListUsersByTagId", "testAddUsers2Tag", "testListAll", "testUpdate", "testCreate"})
|
||||
public void testRemoveUsersFromTag() throws Exception {
|
||||
List<String> userIds = Splitter.on("|").splitToList(this.configStorage.getUserId());
|
||||
WxCpTagAddOrRemoveUsersResult result = this.wxService.getTagService().removeUsersFromTag(this.tagId, userIds);
|
||||
WxCpTagAddOrRemoveUsersResult result = this.wxService.getTagService().removeUsersFromTag(this.tagId, userIds, null);
|
||||
assertEquals(result.getErrCode(), Integer.valueOf(0));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user