Skip to content

Commit 6e32028

Browse files
committed
添加批量为用户取消标签的接口
1 parent 9780d65 commit 6e32028

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,14 @@ public interface WxMpUserTagService {
7676
*/
7777
boolean batchTagging(Integer tagId, String[] openids) throws WxErrorException;
7878

79+
/**
80+
* <pre>
81+
* 批量为用户取消标签
82+
* 详情请见:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">用户标签管理</a>
83+
* 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=ACCESS_TOKEN
84+
* </pre>
85+
*
86+
*/
87+
boolean batchUntagging(Integer tagId, String[] openids) throws WxErrorException;
88+
7989
}

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,27 @@ public boolean batchTagging(Integer tagId, String[] openids) throws WxErrorExcep
130130

131131
throw new WxErrorException(wxError);
132132
}
133+
134+
@Override
135+
public boolean batchUntagging(Integer tagId, String[] openids) throws WxErrorException {
136+
String url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging";
137+
138+
JsonObject json = new JsonObject();
139+
json.addProperty("tagid", tagId);
140+
JsonArray openidArrayJson = new JsonArray();
141+
for (String openid : openids) {
142+
openidArrayJson.add(openid);
143+
}
144+
json.add("openid_list", openidArrayJson);
145+
146+
String responseContent = this.wxMpService.post(url, json.toString());
147+
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(),
148+
responseContent);
149+
WxError wxError = WxError.fromJson(responseContent);
150+
if (wxError.getErrorCode() == 0) {
151+
return true;
152+
}
153+
154+
throw new WxErrorException(wxError);
155+
}
133156
}

‎weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public void testTagListUser() throws Exception {
6262
}
6363

6464
@Test
65-
public void testBatchTagging() throws Exception {
65+
public void testBatchUntagging() throws Exception {
6666
String[] openids = new String[]{((ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()};
67-
boolean res = this.wxService.getUserTagService().batchTagging(this.tagId, openids);
67+
boolean res = this.wxService.getUserTagService().batchUntagging(this.tagId, openids);
6868
System.out.println(res);
6969
Assert.assertTrue(res);
7070
}

0 commit comments

Comments
 (0)