diff --git a/pom.xml b/pom.xml
index 6369ec1f..93eae48a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -96,6 +96,12 @@
emoji-java
3.1.1
+
+ junit
+ junit
+ 4.12
+ test
+
diff --git a/src/main/java/weixin/popular/api/BaseAPI.java b/src/main/java/weixin/popular/api/BaseAPI.java
index 5be00664..8acb9f85 100644
--- a/src/main/java/weixin/popular/api/BaseAPI.java
+++ b/src/main/java/weixin/popular/api/BaseAPI.java
@@ -11,13 +11,7 @@ public abstract class BaseAPI {
protected static final String MP_URI = "https://mp.weixin.qq.com";
protected static final String MCH_URI = "https://api.mch.weixin.qq.com";
protected static final String OPEN_URI = "https://open.weixin.qq.com";
- /*
- protected static final String BASE_URI = "http://192.168.16.83:8888/weixin";
- protected static final String MEDIA_URI = "http://192.168.16.83:8888/weixin";
- protected static final String MP_URI = "http://192.168.16.83:8888/weixin";
- protected static final String MCH_URI = "http://192.168.16.83:8888/weixin";
- protected static final String OPEN_URI = "http://192.168.16.83:8888/weixin";
- */
+
protected static Header jsonHeader = new BasicHeader(HttpHeaders.CONTENT_TYPE,ContentType.APPLICATION_JSON.toString());
protected static Header xmlHeader = new BasicHeader(HttpHeaders.CONTENT_TYPE,ContentType.APPLICATION_XML.toString());
diff --git a/src/main/java/weixin/popular/api/UserAPI.java b/src/main/java/weixin/popular/api/UserAPI.java
index 12da8d3c..b61dff18 100644
--- a/src/main/java/weixin/popular/api/UserAPI.java
+++ b/src/main/java/weixin/popular/api/UserAPI.java
@@ -9,9 +9,14 @@
import weixin.popular.bean.BaseResult;
import weixin.popular.bean.user.FollowResult;
+import weixin.popular.bean.user.GetblacklistResult;
import weixin.popular.bean.user.Group;
+import weixin.popular.bean.user.TagsCreatResult;
+import weixin.popular.bean.user.TagsGetResult;
+import weixin.popular.bean.user.TagsGetidlistResult;
import weixin.popular.bean.user.User;
import weixin.popular.bean.user.UserInfoList;
+import weixin.popular.bean.user.UserTagGetResult;
import weixin.popular.client.LocalHttpClient;
import weixin.popular.util.EmojiUtil;
import weixin.popular.util.JsonUtil;
@@ -267,4 +272,206 @@ public static BaseResult groupsDelete(String access_token,String id){
return LocalHttpClient.executeJsonResult(httpUriRequest,BaseResult.class);
}
+ /**
+ * 标签管理 创建标签
+ * 一个公众号,最多可以创建100个标签。
+ * @since 2.8.1
+ * @param access_token access_token
+ * @param name name 标签名长度超过30个字节
+ * @return result
+ */
+ public TagsCreatResult tagsCreate(String access_token,String name){
+ String json = String.format("{\"tag\":{\"name\":\"%s\"}}",name);
+ HttpUriRequest httpUriRequest = RequestBuilder.post()
+ .setHeader(jsonHeader)
+ .setUri(BASE_URI+"/cgi-bin/tags/create")
+ .addParameter(getATPN(), access_token)
+ .setEntity(new StringEntity(json,Charset.forName("utf-8")))
+ .build();
+ return LocalHttpClient.executeJsonResult(httpUriRequest,TagsCreatResult.class);
+ }
+
+ /**
+ * 标签管理 获取公众号已创建的标签
+ * @since 2.8.1
+ * @param access_token access_token
+ * @return result
+ */
+ public static TagsGetResult tagsGet(String access_token){
+ HttpUriRequest httpUriRequest = RequestBuilder.get()
+ .setUri(BASE_URI+"/cgi-bin/tags/get")
+ .addParameter(getATPN(), access_token)
+ .build();
+ return LocalHttpClient.executeJsonResult(httpUriRequest,TagsGetResult.class);
+ }
+
+ /**
+ * 标签管理 编辑标签
+ * @since 2.8.1
+ * @param access_token access_token
+ * @param id id
+ * @param name name 标签名长度超过30个字节
+ * @return result
+ */
+ public BaseResult tagsUpdate(String access_token,Integer id,String name){
+ String json = String.format("{\"tag\":{\"id\":%d,\"name\":\"%s\"}}",id,name);
+ HttpUriRequest httpUriRequest = RequestBuilder.post()
+ .setHeader(jsonHeader)
+ .setUri(BASE_URI+"/cgi-bin/tags/update")
+ .addParameter(getATPN(), access_token)
+ .setEntity(new StringEntity(json,Charset.forName("utf-8")))
+ .build();
+ return LocalHttpClient.executeJsonResult(httpUriRequest,BaseResult.class);
+ }
+
+ /**
+ * 标签管理 删除标签
+ * 请注意,当某个标签下的粉丝超过10w时,后台不可直接删除标签。
+ * 此时,开发者可以对该标签下的openid列表,先进行取消标签的操作,直到粉丝数不超过10w后,才可直接删除该标签。
+ * @since 2.8.1
+ * @param access_token access_token
+ * @param id id
+ * @return result
+ */
+ public BaseResult tagsDelete(String access_token,Integer id){
+ String json = String.format("{\"tag\":{\"id\":%d}}",id);
+ HttpUriRequest httpUriRequest = RequestBuilder.post()
+ .setHeader(jsonHeader)
+ .setUri(BASE_URI+"/cgi-bin/tags/delete")
+ .addParameter(getATPN(), access_token)
+ .setEntity(new StringEntity(json,Charset.forName("utf-8")))
+ .build();
+ return LocalHttpClient.executeJsonResult(httpUriRequest,BaseResult.class);
+ }
+
+ /**
+ * 标签管理 获取标签下粉丝列表
+ * @since 2.8.1
+ * @param access_token access_token
+ * @param tagid tagid
+ * @param next_openid 第一个拉取的OPENID,不填默认从头开始拉取
+ * @return result
+ */
+ public UserTagGetResult userTagGet(String access_token,Integer tagid,String next_openid){
+ String json = String.format("{\"tagid\":%d,\"next_openid\":\"%s\"}",tagid,next_openid==null?"":next_openid);
+ HttpUriRequest httpUriRequest = RequestBuilder.get()
+ .setHeader(jsonHeader)
+ .setUri(BASE_URI+"/cgi-bin/user/tag/get")
+ .addParameter(getATPN(), access_token)
+ .setEntity(new StringEntity(json,Charset.forName("utf-8")))
+ .build();
+ return LocalHttpClient.executeJsonResult(httpUriRequest,UserTagGetResult.class);
+ }
+
+ /**
+ * 用户管理 批量为用户打标签
+ * 标签功能目前支持公众号为用户打上最多三个标签。
+ * @since 2.8.1
+ * @param access_token access_token
+ * @param tagid tagid
+ * @param openids openids
+ * @return result
+ */
+ public BaseResult tagsMembersBatchtagging(String access_token,Integer tagid,String[] openids){
+ String json = String.format("{\"tagid\":%d,\"openid_list\":%s}",tagid,JsonUtil.toJSONString(openids));
+ HttpUriRequest httpUriRequest = RequestBuilder.post()
+ .setHeader(jsonHeader)
+ .setUri(BASE_URI+"/cgi-bin/tags/members/batchtagging")
+ .addParameter(getATPN(), access_token)
+ .setEntity(new StringEntity(json,Charset.forName("utf-8")))
+ .build();
+ return LocalHttpClient.executeJsonResult(httpUriRequest,BaseResult.class);
+ }
+
+ /**
+ * 用户管理 批量为用户取消标签
+ * @since 2.8.1
+ * @param access_token access_token
+ * @param tagid tagid
+ * @param openids openids
+ * @return result
+ */
+ public BaseResult tagsMembersBatchuntagging(String access_token,Integer tagid,String[] openids){
+ String json = String.format("{\"tagid\":%d,\"openid_list\":%s}",tagid,JsonUtil.toJSONString(openids));
+ HttpUriRequest httpUriRequest = RequestBuilder.post()
+ .setHeader(jsonHeader)
+ .setUri(BASE_URI+"/cgi-bin/tags/members/batchtagging")
+ .addParameter(getATPN(), access_token)
+ .setEntity(new StringEntity(json,Charset.forName("utf-8")))
+ .build();
+ return LocalHttpClient.executeJsonResult(httpUriRequest,BaseResult.class);
+ }
+
+ /**
+ * 用户管理 获取用户身上的标签列表
+ * @since 2.8.1
+ * @param access_token access_token
+ * @param openid openid
+ * @return result
+ */
+ public TagsGetidlistResult tagsGetidlist(String access_token,String openid){
+ String json = String.format("{\"openid\":\"%s\"}",openid);
+ HttpUriRequest httpUriRequest = RequestBuilder.post()
+ .setHeader(jsonHeader)
+ .setUri(BASE_URI+"/cgi-bin/tags/getidlist")
+ .addParameter(getATPN(), access_token)
+ .setEntity(new StringEntity(json,Charset.forName("utf-8")))
+ .build();
+ return LocalHttpClient.executeJsonResult(httpUriRequest,TagsGetidlistResult.class);
+ }
+
+ /**
+ * 黑名单管理 获取公众号的黑名单列表
+ * 该接口每次调用最多可拉取 10000 个OpenID,当列表数较多时,可以通过多次拉取的方式来满足需求。
+ * @since 2.8.1
+ * @param access_token access_token
+ * @param begin_openid 当 begin_openid 为空时,默认从开头拉取。
+ * @return result
+ */
+ public GetblacklistResult tagsMembersGetblacklist(String access_token,String begin_openid){
+ String json = String.format("{\"begin_openid\":\"%s\"}",begin_openid == null?"":begin_openid);
+ HttpUriRequest httpUriRequest = RequestBuilder.post()
+ .setHeader(jsonHeader)
+ .setUri(BASE_URI+"/cgi-bin/tags/members/getblacklist")
+ .addParameter(getATPN(), access_token)
+ .setEntity(new StringEntity(json,Charset.forName("utf-8")))
+ .build();
+ return LocalHttpClient.executeJsonResult(httpUriRequest,GetblacklistResult.class);
+ }
+
+ /**
+ * 黑名单管理 拉黑用户
+ * @since 2.8.1
+ * @param access_token access_token
+ * @param openid_list 需要拉入黑名单的用户的openid,一次拉黑最多允许20个
+ * @return result
+ */
+ public BaseResult tagsMembersBatchblacklist(String access_token,String[] openid_list){
+ String json = String.format("{\"openid_list\":%s}",JsonUtil.toJSONString(openid_list));
+ HttpUriRequest httpUriRequest = RequestBuilder.post()
+ .setHeader(jsonHeader)
+ .setUri(BASE_URI+"/cgi-bin/tags/members/batchblacklist")
+ .addParameter(getATPN(), access_token)
+ .setEntity(new StringEntity(json,Charset.forName("utf-8")))
+ .build();
+ return LocalHttpClient.executeJsonResult(httpUriRequest,BaseResult.class);
+ }
+
+ /**
+ * 黑名单管理 取消拉黑用户
+ * @since 2.8.1
+ * @param access_token access_token
+ * @param openid_list 需要取消拉入黑名单的用户的openid,一次取消拉黑最多允许20个
+ * @return result
+ */
+ public BaseResult tagsMembersBatchunblacklist(String access_token,String[] openid_list){
+ String json = String.format("{\"openid_list\":%s}",JsonUtil.toJSONString(openid_list));
+ HttpUriRequest httpUriRequest = RequestBuilder.post()
+ .setHeader(jsonHeader)
+ .setUri(BASE_URI+"/cgi-bin/tags/members/batchunblacklist")
+ .addParameter(getATPN(), access_token)
+ .setEntity(new StringEntity(json,Charset.forName("utf-8")))
+ .build();
+ return LocalHttpClient.executeJsonResult(httpUriRequest,BaseResult.class);
+ }
}
diff --git a/src/main/java/weixin/popular/bean/user/GetblacklistResult.java b/src/main/java/weixin/popular/bean/user/GetblacklistResult.java
new file mode 100644
index 00000000..c9a79259
--- /dev/null
+++ b/src/main/java/weixin/popular/bean/user/GetblacklistResult.java
@@ -0,0 +1,59 @@
+package weixin.popular.bean.user;
+
+import weixin.popular.bean.BaseResult;
+
+public class GetblacklistResult extends BaseResult {
+
+ private Integer total;
+
+ private Integer count;
+
+ private String next_openid;
+
+ private Data data;
+
+ public Integer getTotal() {
+ return total;
+ }
+
+ public void setTotal(Integer total) {
+ this.total = total;
+ }
+
+ public Integer getCount() {
+ return count;
+ }
+
+ public void setCount(Integer count) {
+ this.count = count;
+ }
+
+ public String getNext_openid() {
+ return next_openid;
+ }
+
+ public void setNext_openid(String next_openid) {
+ this.next_openid = next_openid;
+ }
+
+ public Data getData() {
+ return data;
+ }
+
+ public void setData(Data data) {
+ this.data = data;
+ }
+
+ public static class Data {
+
+ private String[] openid;
+
+ public String[] getOpenid() {
+ return openid;
+ }
+
+ public void setOpenid(String[] openid) {
+ this.openid = openid;
+ }
+ }
+}
diff --git a/src/main/java/weixin/popular/bean/user/Tag.java b/src/main/java/weixin/popular/bean/user/Tag.java
new file mode 100644
index 00000000..3021baaf
--- /dev/null
+++ b/src/main/java/weixin/popular/bean/user/Tag.java
@@ -0,0 +1,35 @@
+package weixin.popular.bean.user;
+
+public class Tag {
+
+ private Integer id;
+
+ private String name;
+
+ private Integer count;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Integer getCount() {
+ return count;
+ }
+
+ public void setCount(Integer count) {
+ this.count = count;
+ }
+
+}
diff --git a/src/main/java/weixin/popular/bean/user/TagsCreatResult.java b/src/main/java/weixin/popular/bean/user/TagsCreatResult.java
new file mode 100644
index 00000000..e4bb4ffe
--- /dev/null
+++ b/src/main/java/weixin/popular/bean/user/TagsCreatResult.java
@@ -0,0 +1,22 @@
+package weixin.popular.bean.user;
+
+import weixin.popular.bean.BaseResult;
+
+/**
+ * 标签
+ *
+ * @author SLYH
+ *
+ */
+public class TagsCreatResult extends BaseResult {
+
+ private Tag tag;
+
+ public Tag getTag() {
+ return tag;
+ }
+
+ public void setTag(Tag tag) {
+ this.tag = tag;
+ }
+}
diff --git a/src/main/java/weixin/popular/bean/user/TagsGetResult.java b/src/main/java/weixin/popular/bean/user/TagsGetResult.java
new file mode 100644
index 00000000..92610b87
--- /dev/null
+++ b/src/main/java/weixin/popular/bean/user/TagsGetResult.java
@@ -0,0 +1,25 @@
+package weixin.popular.bean.user;
+
+import java.util.List;
+
+import weixin.popular.bean.BaseResult;
+
+/**
+ * 标签
+ *
+ * @author SLYH
+ *
+ */
+public class TagsGetResult extends BaseResult {
+
+ private List tags;
+
+ public List getTags() {
+ return tags;
+ }
+
+ public void setTags(List tags) {
+ this.tags = tags;
+ }
+
+}
diff --git a/src/main/java/weixin/popular/bean/user/TagsGetidlistResult.java b/src/main/java/weixin/popular/bean/user/TagsGetidlistResult.java
new file mode 100644
index 00000000..1250f8b6
--- /dev/null
+++ b/src/main/java/weixin/popular/bean/user/TagsGetidlistResult.java
@@ -0,0 +1,17 @@
+package weixin.popular.bean.user;
+
+import weixin.popular.bean.BaseResult;
+
+public class TagsGetidlistResult extends BaseResult{
+
+ private Integer[] tagid_list;
+
+ public Integer[] getTagid_list() {
+ return tagid_list;
+ }
+
+ public void setTagid_list(Integer[] tagid_list) {
+ this.tagid_list = tagid_list;
+ }
+
+}
diff --git a/src/main/java/weixin/popular/bean/user/UserTagGetResult.java b/src/main/java/weixin/popular/bean/user/UserTagGetResult.java
new file mode 100644
index 00000000..61a095f2
--- /dev/null
+++ b/src/main/java/weixin/popular/bean/user/UserTagGetResult.java
@@ -0,0 +1,49 @@
+package weixin.popular.bean.user;
+
+import weixin.popular.bean.BaseResult;
+
+public class UserTagGetResult extends BaseResult {
+
+ private Integer count;
+
+ private Data data;
+
+ private String next_openid;
+
+ public Integer getCount() {
+ return count;
+ }
+
+ public void setCount(Integer count) {
+ this.count = count;
+ }
+
+ public Data getData() {
+ return data;
+ }
+
+ public void setData(Data data) {
+ this.data = data;
+ }
+
+ public String getNext_openid() {
+ return next_openid;
+ }
+
+ public void setNext_openid(String next_openid) {
+ this.next_openid = next_openid;
+ }
+
+ public static class Data {
+
+ private String[] openid;
+
+ public String[] getOpenid() {
+ return openid;
+ }
+
+ public void setOpenid(String[] openid) {
+ this.openid = openid;
+ }
+ }
+}