Browse Source

添加批量为用户取消标签的接口

master
BinaryWang 8 years ago
parent
commit
6e32028c50
3 changed files with 35 additions and 2 deletions
  1. +10
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java
  2. +23
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java
  3. +2
    -2
      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

@@ -76,4 +76,14 @@ public interface WxMpUserTagService {
*/ */
boolean batchTagging(Integer tagId, String[] openids) throws WxErrorException; boolean batchTagging(Integer tagId, String[] openids) 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/members/batchtagging?access_token=ACCESS_TOKEN
* </pre>
*
*/
boolean batchUntagging(Integer tagId, String[] openids) throws WxErrorException;

} }

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

@@ -130,4 +130,27 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {


throw new WxErrorException(wxError); throw new WxErrorException(wxError);
} }

@Override
public boolean batchUntagging(Integer tagId, String[] openids) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging";

JsonObject json = new JsonObject();
json.addProperty("tagid", tagId);
JsonArray openidArrayJson = new JsonArray();
for (String openid : openids) {
openidArrayJson.add(openid);
}
json.add("openid_list", openidArrayJson);

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);
}
} }

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

@@ -62,9 +62,9 @@ public class WxMpUserTagServiceImplTest {
} }


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


Loading…
Cancel
Save