Skip to content

Commit f13dcaa

Browse files
committed
增加删除标签的接口
1 parent ede2496 commit f13dcaa

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

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
@@ -45,4 +45,14 @@ public interface WxMpUserTagService {
4545
*/
4646
Boolean tagUpdate(Integer id, String name) throws WxErrorException;
4747

48+
/**
49+
* <pre>
50+
* 删除标签
51+
* 详情请见:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">用户标签管理</a>
52+
* 接口url格式: https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=ACCESS_TOKEN
53+
* </pre>
54+
*
55+
*/
56+
Boolean tagDelete(Integer id) throws WxErrorException;
57+
4858
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,24 @@ public Boolean tagUpdate(Integer id, String name) throws WxErrorException {
7272

7373
throw new WxErrorException(wxError);
7474
}
75+
76+
@Override
77+
public Boolean tagDelete(Integer id) throws WxErrorException {
78+
String url = API_URL_PREFIX + "/delete";
79+
80+
JsonObject json = new JsonObject();
81+
JsonObject tagJson = new JsonObject();
82+
tagJson.addProperty("id", id);
83+
json.add("tag", tagJson);
84+
85+
String responseContent = this.wxMpService.post(url, json.toString());
86+
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(),
87+
responseContent);
88+
WxError wxError = WxError.fromJson(responseContent);
89+
if (wxError.getErrorCode() == 0) {
90+
return true;
91+
}
92+
93+
throw new WxErrorException(wxError);
94+
}
7595
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,11 @@ public void testTagUpdate() throws Exception {
4848
Assert.assertTrue(res);
4949
}
5050

51+
@Test(dependsOnMethods = { "testTagCreate" })
52+
public void testTagDelete() throws Exception {
53+
Boolean res = this.wxService.getUserTagService().tagDelete(this.tagId);
54+
System.out.println(res);
55+
Assert.assertTrue(res);
56+
}
57+
5158
}

0 commit comments

Comments
 (0)