Browse Source

增加删除标签的接口

master
BinaryWang 8 years ago
parent
commit
f13dcaa1fc
3 changed files with 37 additions and 0 deletions
  1. +10
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java
  2. +20
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java
  3. +7
    -0
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java

+ 10
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java View File

@@ -45,4 +45,14 @@ public interface WxMpUserTagService {
*/
Boolean tagUpdate(Integer id, String name) throws WxErrorException;

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

}

+ 20
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java View File

@@ -72,4 +72,24 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {

throw new WxErrorException(wxError);
}

@Override
public Boolean tagDelete(Integer id) throws WxErrorException {
String url = API_URL_PREFIX + "/delete";

JsonObject json = new JsonObject();
JsonObject tagJson = new JsonObject();
tagJson.addProperty("id", id);
json.add("tag", tagJson);

String responseContent = this.wxMpService.post(url, json.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(),
responseContent);
WxError wxError = WxError.fromJson(responseContent);
if (wxError.getErrorCode() == 0) {
return true;
}

throw new WxErrorException(wxError);
}
}

+ 7
- 0
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java View File

@@ -48,4 +48,11 @@ public class WxMpUserTagServiceImplTest {
Assert.assertTrue(res);
}

@Test(dependsOnMethods = { "testTagCreate" })
public void testTagDelete() throws Exception {
Boolean res = this.wxService.getUserTagService().tagDelete(this.tagId);
System.out.println(res);
Assert.assertTrue(res);
}

}

Loading…
Cancel
Save