mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-23 22:11:40 +08:00
添加获取用户身上的标签列表的接口
This commit is contained in:
parent
6e32028c50
commit
7e21f4692b
@ -86,4 +86,15 @@ public interface WxMpUserTagService {
|
|||||||
*/
|
*/
|
||||||
boolean batchUntagging(Integer tagId, String[] openids) throws WxErrorException;
|
boolean batchUntagging(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/getidlist?access_token=ACCESS_TOKEN
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
List<Integer> userTagList(String openid) throws WxErrorException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,15 @@ package me.chanjar.weixin.mp.api.impl;
|
|||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
import me.chanjar.weixin.common.bean.result.WxError;
|
import me.chanjar.weixin.common.bean.result.WxError;
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
import me.chanjar.weixin.mp.api.WxMpUserTagService;
|
import me.chanjar.weixin.mp.api.WxMpUserTagService;
|
||||||
import me.chanjar.weixin.mp.bean.tag.WxTagListUser;
|
import me.chanjar.weixin.mp.bean.tag.WxTagListUser;
|
||||||
import me.chanjar.weixin.mp.bean.tag.WxUserTag;
|
import me.chanjar.weixin.mp.bean.tag.WxUserTag;
|
||||||
|
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -153,4 +156,21 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
|
|||||||
|
|
||||||
throw new WxErrorException(wxError);
|
throw new WxErrorException(wxError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Integer> userTagList(String openid) throws WxErrorException {
|
||||||
|
String url = "https://api.weixin.qq.com/cgi-bin/tags/getidlist";
|
||||||
|
|
||||||
|
JsonObject json = new JsonObject();
|
||||||
|
json.addProperty("openid", openid);
|
||||||
|
|
||||||
|
String responseContent = this.wxMpService.post(url, json.toString());
|
||||||
|
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(),
|
||||||
|
responseContent);
|
||||||
|
|
||||||
|
return WxMpGsonBuilder.create().fromJson(
|
||||||
|
new JsonParser().parse(responseContent).getAsJsonObject().get("tagid_list"),
|
||||||
|
new TypeToken<List<Integer>>() {
|
||||||
|
}.getType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,4 +68,12 @@ public class WxMpUserTagServiceImplTest {
|
|||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assert.assertTrue(res);
|
Assert.assertTrue(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUserTagList() throws Exception {
|
||||||
|
List<Integer> res = this.wxService.getUserTagService().userTagList(
|
||||||
|
((ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid());
|
||||||
|
System.out.println(res);
|
||||||
|
Assert.assertNotNull(res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user