mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-25 01:14:36 +08:00
#541 企业号增加实现管理标签的(获取标签成员)接口
* 定义《企业号应用》的bean * 增加《获取企业号应用》接口实现 * 增加获取测试企业号应用信息测试类 * tag service增加获取标签成员方法 http://qydev.weixin.qq.com/wiki/index.php?title=管理标签
This commit is contained in:
parent
558f4e7880
commit
74faa2a03e
@ -3,6 +3,7 @@ package me.chanjar.weixin.cp.api;
|
|||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpTag;
|
import me.chanjar.weixin.cp.bean.WxCpTag;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
|
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpTagGetResult;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -63,4 +64,16 @@ public interface WxCpTagService {
|
|||||||
* @param userIds 用户id列表
|
* @param userIds 用户id列表
|
||||||
*/
|
*/
|
||||||
WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds) throws WxErrorException;
|
WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds) throws WxErrorException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取标签成员
|
||||||
|
* 对应: http://qydev.weixin.qq.com/wiki/index.php?title=管理标签 中的get接口
|
||||||
|
*
|
||||||
|
* @param tagId
|
||||||
|
* @return
|
||||||
|
* @throws WxErrorException
|
||||||
|
*/
|
||||||
|
WxCpTagGetResult get(String tagId) throws WxErrorException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import me.chanjar.weixin.cp.api.WxCpService;
|
|||||||
import me.chanjar.weixin.cp.api.WxCpTagService;
|
import me.chanjar.weixin.cp.api.WxCpTagService;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpTag;
|
import me.chanjar.weixin.cp.bean.WxCpTag;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
|
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpTagGetResult;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||||
|
|
||||||
@ -113,4 +114,18 @@ public class WxCpTagServiceImpl implements WxCpTagService {
|
|||||||
|
|
||||||
return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
|
return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxCpTagGetResult get(String tagId) throws WxErrorException {
|
||||||
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/get";
|
||||||
|
if (tagId != null) {
|
||||||
|
url += "?tagId=" + tagId;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("缺少tagId参数");
|
||||||
|
}
|
||||||
|
|
||||||
|
String responseContent = this.mainService.get(url, null);
|
||||||
|
|
||||||
|
return WxCpTagGetResult.fromJson(responseContent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
package me.chanjar.weixin.cp.bean;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 管理企业号应用-测试
|
||||||
|
* Created by huansinho on 2018/4/16.
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author <a href="https://github.com/huansinho">huansinho</a>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class WxCpTagGetResult implements Serializable {
|
||||||
|
|
||||||
|
@SerializedName("errcode")
|
||||||
|
private Integer errcode;
|
||||||
|
|
||||||
|
@SerializedName("errmsg")
|
||||||
|
private String errmsg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户列表
|
||||||
|
*/
|
||||||
|
@SerializedName("userlist")
|
||||||
|
private List<WxCpUser> userlist;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门列表
|
||||||
|
*/
|
||||||
|
@SerializedName("partylist")
|
||||||
|
private List<Integer> partylist;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签名称
|
||||||
|
*/
|
||||||
|
@SerializedName("tagname")
|
||||||
|
private String tagname;
|
||||||
|
|
||||||
|
public static WxCpTagGetResult fromJson(String json) {
|
||||||
|
return WxCpGsonBuilder.create().fromJson(json, WxCpTagGetResult.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJson() {
|
||||||
|
return WxCpGsonBuilder.create().toJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,15 +2,20 @@ package me.chanjar.weixin.cp.api.impl;
|
|||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.cp.api.ApiTestModule;
|
import me.chanjar.weixin.cp.api.ApiTestModule;
|
||||||
import me.chanjar.weixin.cp.api.WxCpService;
|
import me.chanjar.weixin.cp.api.WxCpService;
|
||||||
|
import me.chanjar.weixin.cp.api.WxCpTagService;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpTag;
|
import me.chanjar.weixin.cp.bean.WxCpTag;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
|
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpTagGetResult;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||||
import org.testng.annotations.*;
|
import org.testng.annotations.*;
|
||||||
|
|
||||||
import java.util.List;
|
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.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,4 +77,24 @@ public class WxCpTagServiceImplTest {
|
|||||||
this.wxService.getTagService().delete(this.tagId);
|
this.wxService.getTagService().delete(this.tagId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGet() throws WxErrorException {
|
||||||
|
String apiResultJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"userlist\": [{\"userid\": \"0124035\",\"name\": \"王五\"},{\"userid\": \"0114035\",\"name\": \"梦雪\"}],\"partylist\": [9576,9567,9566],\"tagname\": \"测试标签-001\"}";
|
||||||
|
WxCpService wxService = mock(WxCpService.class);
|
||||||
|
when(wxService.get("https://qyapi.weixin.qq.com/cgi-bin/tag/get?tagId=150", null)).thenReturn(apiResultJson);
|
||||||
|
when(wxService.getTagService()).thenReturn(new WxCpTagServiceImpl(wxService));
|
||||||
|
|
||||||
|
WxCpTagService wxCpTagService = wxService.getTagService();
|
||||||
|
|
||||||
|
WxCpTagGetResult wxCpTagGetResult = wxCpTagService.get(String.valueOf(150));
|
||||||
|
|
||||||
|
assertEquals(0, wxCpTagGetResult.getErrcode().intValue());
|
||||||
|
|
||||||
|
assertEquals(2, wxCpTagGetResult.getUserlist().size());
|
||||||
|
assertEquals(3, wxCpTagGetResult.getPartylist().size());
|
||||||
|
assertEquals("测试标签-001", wxCpTagGetResult.getTagname());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user