Skip to content

Commit 74faa2a

Browse files
huansinhobinarywang
authored andcommitted
#541 企业号增加实现管理标签的(获取标签成员)接口
* 定义《企业号应用》的bean * 增加《获取企业号应用》接口实现 * 增加获取测试企业号应用信息测试类 * tag service增加获取标签成员方法 http://qydev.weixin.qq.com/wiki/index.php?title=管理标签
1 parent 558f4e7 commit 74faa2a

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import me.chanjar.weixin.common.exception.WxErrorException;
44
import me.chanjar.weixin.cp.bean.WxCpTag;
55
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
6+
import me.chanjar.weixin.cp.bean.WxCpTagGetResult;
67
import me.chanjar.weixin.cp.bean.WxCpUser;
78

89
import java.util.List;
@@ -63,4 +64,16 @@ public interface WxCpTagService {
6364
* @param userIds 用户id列表
6465
*/
6566
WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds) throws WxErrorException;
67+
68+
69+
/**
70+
* 获取标签成员
71+
* 对应: http://qydev.weixin.qq.com/wiki/index.php?title=管理标签 中的get接口
72+
*
73+
* @param tagId
74+
* @return
75+
* @throws WxErrorException
76+
*/
77+
WxCpTagGetResult get(String tagId) throws WxErrorException;
78+
6679
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import me.chanjar.weixin.cp.api.WxCpTagService;
88
import me.chanjar.weixin.cp.bean.WxCpTag;
99
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
10+
import me.chanjar.weixin.cp.bean.WxCpTagGetResult;
1011
import me.chanjar.weixin.cp.bean.WxCpUser;
1112
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
1213

@@ -113,4 +114,18 @@ public WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<Strin
113114

114115
return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
115116
}
117+
118+
@Override
119+
public WxCpTagGetResult get(String tagId) throws WxErrorException {
120+
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/get";
121+
if (tagId != null) {
122+
url += "?tagId=" + tagId;
123+
} else {
124+
throw new IllegalArgumentException("缺少tagId参数");
125+
}
126+
127+
String responseContent = this.mainService.get(url, null);
128+
129+
return WxCpTagGetResult.fromJson(responseContent);
130+
}
116131
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package me.chanjar.weixin.cp.bean;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
8+
9+
import java.io.Serializable;
10+
import java.util.List;
11+
12+
/**
13+
* <pre>
14+
* 管理企业号应用-测试
15+
* Created by huansinho on 2018/4/16.
16+
* </pre>
17+
*
18+
* @author <a href="https://github.com/huansinho">huansinho</a>
19+
*/
20+
@Data
21+
@AllArgsConstructor
22+
@NoArgsConstructor
23+
public class WxCpTagGetResult implements Serializable {
24+
25+
@SerializedName("errcode")
26+
private Integer errcode;
27+
28+
@SerializedName("errmsg")
29+
private String errmsg;
30+
31+
/**
32+
* 用户列表
33+
*/
34+
@SerializedName("userlist")
35+
private List<WxCpUser> userlist;
36+
37+
/**
38+
* 部门列表
39+
*/
40+
@SerializedName("partylist")
41+
private List<Integer> partylist;
42+
43+
/**
44+
* 标签名称
45+
*/
46+
@SerializedName("tagname")
47+
private String tagname;
48+
49+
public static WxCpTagGetResult fromJson(String json) {
50+
return WxCpGsonBuilder.create().fromJson(json, WxCpTagGetResult.class);
51+
}
52+
53+
public String toJson() {
54+
return WxCpGsonBuilder.create().toJson(this);
55+
}
56+
57+
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22

33
import com.google.common.base.Splitter;
44
import com.google.inject.Inject;
5+
import me.chanjar.weixin.common.exception.WxErrorException;
56
import me.chanjar.weixin.cp.api.ApiTestModule;
67
import me.chanjar.weixin.cp.api.WxCpService;
8+
import me.chanjar.weixin.cp.api.WxCpTagService;
79
import me.chanjar.weixin.cp.bean.WxCpTag;
810
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
11+
import me.chanjar.weixin.cp.bean.WxCpTagGetResult;
912
import me.chanjar.weixin.cp.bean.WxCpUser;
1013
import org.testng.annotations.*;
1114

1215
import java.util.List;
1316

17+
import static org.mockito.Mockito.mock;
18+
import static org.mockito.Mockito.when;
1419
import static org.testng.Assert.*;
1520

1621
/**
@@ -72,4 +77,24 @@ public void testDelete() throws Exception {
7277
this.wxService.getTagService().delete(this.tagId);
7378
}
7479

80+
@Test
81+
public void testGet() throws WxErrorException {
82+
String apiResultJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"userlist\": [{\"userid\": \"0124035\",\"name\": \"王五\"},{\"userid\": \"0114035\",\"name\": \"梦雪\"}],\"partylist\": [9576,9567,9566],\"tagname\": \"测试标签-001\"}";
83+
WxCpService wxService = mock(WxCpService.class);
84+
when(wxService.get("https://qyapi.weixin.qq.com/cgi-bin/tag/get?tagId=150", null)).thenReturn(apiResultJson);
85+
when(wxService.getTagService()).thenReturn(new WxCpTagServiceImpl(wxService));
86+
87+
WxCpTagService wxCpTagService = wxService.getTagService();
88+
89+
WxCpTagGetResult wxCpTagGetResult = wxCpTagService.get(String.valueOf(150));
90+
91+
assertEquals(0, wxCpTagGetResult.getErrcode().intValue());
92+
93+
assertEquals(2, wxCpTagGetResult.getUserlist().size());
94+
assertEquals(3, wxCpTagGetResult.getPartylist().size());
95+
assertEquals("测试标签-001", wxCpTagGetResult.getTagname());
96+
97+
98+
}
99+
75100
}

0 commit comments

Comments
 (0)