| @@ -1,10 +1,11 @@ | |||||
| package me.chanjar.weixin.mp.api; | package me.chanjar.weixin.mp.api; | ||||
| import java.util.List; | |||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||
| 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 java.util.List; | |||||
| /** | /** | ||||
| * 用户标签管理相关接口 | * 用户标签管理相关接口 | ||||
| * Created by Binary Wang on 2016/9/2. | * Created by Binary Wang on 2016/9/2. | ||||
| @@ -55,4 +56,14 @@ public interface WxMpUserTagService { | |||||
| */ | */ | ||||
| Boolean tagDelete(Integer id) throws WxErrorException; | Boolean tagDelete(Integer id) 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/user/tag/get?access_token=ACCESS_TOKEN | |||||
| * </pre> | |||||
| * | |||||
| */ | |||||
| WxTagListUser tagListUser(Integer tagId, String nextOpenid) throws WxErrorException; | |||||
| } | } | ||||
| @@ -1,17 +1,17 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import java.util.List; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| 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.WxUserTag; | import me.chanjar.weixin.mp.bean.tag.WxUserTag; | ||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import java.util.List; | |||||
| /** | /** | ||||
| * | * | ||||
| @@ -92,4 +92,18 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { | |||||
| throw new WxErrorException(wxError); | throw new WxErrorException(wxError); | ||||
| } | } | ||||
| @Override | |||||
| public WxTagListUser tagListUser(Integer tagId, String nextOpenid) throws WxErrorException { | |||||
| String url = "https://api.weixin.qq.com/cgi-bin/user/tag/get"; | |||||
| JsonObject json = new JsonObject(); | |||||
| json.addProperty("tagid", tagId); | |||||
| json.addProperty("next_openid", StringUtils.trimToEmpty(nextOpenid)); | |||||
| String responseContent = this.wxMpService.post(url, json.toString()); | |||||
| this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(), | |||||
| responseContent); | |||||
| return WxTagListUser.fromJson(responseContent); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,92 @@ | |||||
| package me.chanjar.weixin.mp.bean.tag; | |||||
| import com.google.gson.annotations.SerializedName; | |||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | |||||
| import org.apache.commons.lang3.builder.ToStringStyle; | |||||
| import java.util.List; | |||||
| /** | |||||
| * 获取标签下粉丝列表的结果对象 | |||||
| * @author binarywang(https://github.com/binarywang) | |||||
| * Created by Binary Wang on 2016-09-19. | |||||
| */ | |||||
| public class WxTagListUser { | |||||
| public static WxTagListUser fromJson(String json) { | |||||
| return WxMpGsonBuilder.create().fromJson(json,WxTagListUser.class); | |||||
| } | |||||
| public String toJson() { | |||||
| return WxMpGsonBuilder.create().toJson(this); | |||||
| } | |||||
| @Override | |||||
| public String toString() { | |||||
| return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); | |||||
| } | |||||
| /** | |||||
| *"count":2,这次获取的粉丝数量 | |||||
| */ | |||||
| @SerializedName("count") | |||||
| private Integer count; | |||||
| /** | |||||
| *"data" 粉丝列表 | |||||
| */ | |||||
| @SerializedName("data") | |||||
| private WxTagListUserData data; | |||||
| /** | |||||
| *"next_openid" 拉取列表最后一个用户的openid | |||||
| */ | |||||
| @SerializedName("next_openid") | |||||
| private String nextOpenid; | |||||
| public Integer getCount() { | |||||
| return count; | |||||
| } | |||||
| public void setCount(Integer count) { | |||||
| this.count = count; | |||||
| } | |||||
| public WxTagListUserData getData() { | |||||
| return data; | |||||
| } | |||||
| public void setData(WxTagListUserData data) { | |||||
| this.data = data; | |||||
| } | |||||
| public String getNextOpenid() { | |||||
| return nextOpenid; | |||||
| } | |||||
| public void setNextOpenid(String nextOpenid) { | |||||
| this.nextOpenid = nextOpenid; | |||||
| } | |||||
| public static class WxTagListUserData { | |||||
| @Override | |||||
| public String toString() { | |||||
| return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); | |||||
| } | |||||
| /** | |||||
| * openid 列表 | |||||
| */ | |||||
| @SerializedName("openid") | |||||
| private List<String> openidList; | |||||
| public List<String> getOpenidList() { | |||||
| return openidList; | |||||
| } | |||||
| public void setOpenidList(List<String> openidList) { | |||||
| this.openidList = openidList; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,15 +1,14 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import java.util.List; | |||||
| import com.google.inject.Inject; | |||||
| import me.chanjar.weixin.mp.api.ApiTestModule; | |||||
| import me.chanjar.weixin.mp.bean.tag.WxTagListUser; | |||||
| import me.chanjar.weixin.mp.bean.tag.WxUserTag; | |||||
| import org.testng.Assert; | import org.testng.Assert; | ||||
| import org.testng.annotations.Guice; | import org.testng.annotations.Guice; | ||||
| import org.testng.annotations.Test; | import org.testng.annotations.Test; | ||||
| import com.google.inject.Inject; | |||||
| import me.chanjar.weixin.mp.api.ApiTestModule; | |||||
| import me.chanjar.weixin.mp.bean.tag.WxUserTag; | |||||
| import java.util.List; | |||||
| /** | /** | ||||
| * | * | ||||
| @@ -22,7 +21,7 @@ public class WxMpUserTagServiceImplTest { | |||||
| @Inject | @Inject | ||||
| protected WxMpServiceImpl wxService; | protected WxMpServiceImpl wxService; | ||||
| private Integer tagId; | |||||
| private Integer tagId = 2; | |||||
| @Test | @Test | ||||
| public void testTagCreate() throws Exception { | public void testTagCreate() throws Exception { | ||||
| @@ -55,4 +54,10 @@ public class WxMpUserTagServiceImplTest { | |||||
| Assert.assertTrue(res); | Assert.assertTrue(res); | ||||
| } | } | ||||
| } | |||||
| @Test | |||||
| public void testTagListUser() throws Exception { | |||||
| WxTagListUser res = this.wxService.getUserTagService().tagListUser(this.tagId, null); | |||||
| System.out.println(res); | |||||
| Assert.assertNotNull(res); | |||||
| } | |||||
| } | |||||