公众号用户管理

洛塔服务号回复020获取代码。

前置条件

公众号后台设置IP白名单。

说明

用户管理这部分主要围绕三部分,分别是粉丝信息、黑名单、标签。

获取用户列表

这个接口一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。
每次请求的返回结果中,都有next_openid这个值,作为下一次请求的参数。如果该值为空,默认从头开始拉取。

		// 先获取access_token,这部分正式环境需要配置定时获取,每天2000次调用限制
		String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + APPID + "&secret=" + SECRET;
		String result = Jsoup.connect(url).ignoreContentType(true).method(Method.GET).execute().body();
		System.out.println(result);
		String accessToken = JSON.parseObject(result).getString("access_token");
		
		// 获取用户列表
		url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + accessToken + "&next_openid=";
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.GET).execute().body();
		// {"total":34,"count":34,"data":{"openid":["ohUHp6vAGcGO94Taxc_0oSnYUBPE","ohUHp6qmSOHeV5usTrtnD0w7tVnk","ohUHp6vnPi4ARLNtArgwB4w4VVig","ohUHp6rVTI71RrgbWF6qWWpqEtCY","ohUHp6pwjwmQaAGetOnPUS3AAbsk","ohUHp6r8i3LiIFvmKJgmIZCIzlMM","ohUHp6v0fKwY79yMwzlwN0ZHmsgE","ohUHp6hVRwrA9k8_brKmAwzEvlsQ","ohUHp6uAOC3sGKMqrHuZNAgLuv_E","ohUHp6n9OzbG7jcdw3aOyr5KqUIo","ohUHp6rtvLgqkS662YYNLQZRIpSE","ohUHp6iaFJq6SISTVwHS5lkb9Pb8","ohUHp6sXhGBEsSKs0Vfh_7cBoPM4","ohUHp6rmF2nUFQDNSUafBs3V629w","ohUHp6h5ZBih0XaH52VD5TT5LOMs","ohUHp6rkOiYFSqmqL3oW6k9ZZ-g4","ohUHp6lEFhbaE5TVP6Zsg-4-bhDQ","ohUHp6rATvuWnMrCy0TmT7l0S4xc","ohUHp6tjUIApeIN_OHio4KriTw4c","ohUHp6pU2OghKgBHv4p3eI0kQYBw","ohUHp6oKm1jbfCt51rxfagajAB2M","ohUHp6jWQ-ViDBoomB_3kId77lsg","ohUHp6jM9PSb8fdexNcZWkm9pH9M","ohUHp6tyhhY2munrSDeDVVWuBhwY","ohUHp6oJLFW8_lbzqtBD-LCwVc7Y","ohUHp6lOqgBpqMHsA8jEe4cGMxVw","ohUHp6oURwmnSFlIvFKuQRboB4C4","ohUHp6nxXyQaBDlXGcgYn9vHjcEc","ohUHp6q_iq2jONH3CSiq98Wd5H1w","ohUHp6tQGQMqM-WuHMaCiR5AkY2Q","ohUHp6vyInrTn1HPrVPSewLd1AA8","ohUHp6mFVMqSmjealNUblJA_ict8","ohUHp6uSohgIphGzkZMp3xxCdQtI","ohUHp6ik6cmQN7g5aT4GIw9CrnrY"]},"next_openid":"ohUHp6ik6cmQN7g5aT4GIw9CrnrY"}
		System.out.println(result);

获取用户基本信息

		// 获取用户基本信息
		url = " https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + accessToken + "&openid=" + "ohUHp6vAGcGO94Taxc_0oSnYUBPE"  + "&lang=zh_CN";
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.GET).execute().body();
		// {"subscribe":1,"openid":"ohUHp6vAGcGO94Taxc_0oSnYUBPE","nickname":"","sex":0,"language":"zh_CN","city":"","province":"","country":"","headimgurl":"","subscribe_time":1603356138,"unionid":"oxayv6pIPFw50JuJG0K0UbFLa5dI","remark":"","groupid":0,"tagid_list":[],"subscribe_scene":"ADD_SCENE_QR_CODE","qr_scene":0,"qr_scene_str":""}
		System.out.println(result);

批量获取用户基本信息

根据用户是否还关注着公众号,返回的结果格式是不相同的。subscribe是0表示没有关注公众号,1表示该用户是对应公众号的粉丝。

{
   "user_info_list": [
       {
           "subscribe": 1, 
           "openid": "otvxTs4dckWG7imySrJd6jSi0CWE", 
           "language": "zh_CN", 
          
          "subscribe_time": 1434093047, 
           "unionid": "oR5GjjgEhCMJFyzaVZdrxZ2zRRF4", 
           "remark": "", 

           "groupid": 0,
           "tagid_list":[128,2],
           "subscribe_scene": "ADD_SCENE_QR_CODE",
           "qr_scene": 98765,
           "qr_scene_str": ""

      }, 
       {
           "subscribe": 0, 
           "openid": "otvxTs_JZ6SEiP0imdhpi50fuSZg"
       }
   ]
}

请求代码为:

		// 批量获取用户基本信息
		JSONArray userArray = new JSONArray();
		JSONObject userObj = new JSONObject();
		userObj.put("openid", "ohUHp6tQGQMqM-WuHMaCiR5AkY2Q");
		userObj.put("lang", "zh_CN");
		userArray.add(userObj);
		userObj = new JSONObject();
		userObj.put("openid", "ohUHp6vyInrTn1HPrVPSewLd1AA8");
		userObj.put("lang", "zh_CN");
		userArray.add(userObj);
		JSONObject param = new JSONObject();
		param.put("user_list", userArray);
		url = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"user_info_list":[{"subscribe":1,"openid":"ohUHp6tQGQMqM-WuHMaCiR5AkY2Q","nickname":"","sex":0,"language":"zh_CN","city":"","province":"","country":"","headimgurl":"","subscribe_time":1632151818,"unionid":"oxayv6jAmsiSJYFeK0nSq6e7arVw","remark":"我自己","groupid":2,"tagid_list":[2],"subscribe_scene":"ADD_SCENE_QR_CODE","qr_scene":0,"qr_scene_str":""},{"subscribe":1,"openid":"ohUHp6vyInrTn1HPrVPSewLd1AA8","nickname":"","sex":0,"language":"zh_CN","city":"","province":"","country":"","headimgurl":"","subscribe_time":1665213460,"unionid":"oxayv6nRy9ATR4Q1Tn1VFG3N4mPo","remark":"","groupid":2,"tagid_list":[2],"subscribe_scene":"ADD_SCENE_SEARCH","qr_scene":0,"qr_scene_str":""}]}
		System.out.println(result);

创建标签

一个公众号,最多可以创建100个标签。

		// 创建标签
		JSONObject paramTag = new JSONObject();
		paramTag.put("name", "测试标签");
		param = new JSONObject();
		param.put("tag", paramTag);
		url = "https://api.weixin.qq.com/cgi-bin/tags/create?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"tag":{"id":101,"name":"测试标签"}}
		System.out.println(result);

标签列表

		// 标签列表
		url = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.GET).execute().body();
		// {"tags":[{"id":2,"name":"星标组","count":2},{"id":101,"name":"测试标签","count":0}]}
		System.out.println(result);

编辑标签

		// 编辑标签
		paramTag = new JSONObject();
		paramTag.put("name", "测试标签-变更后");
		paramTag.put("id", 101);
		param = new JSONObject();
		param.put("tag", paramTag);
		url = "https://api.weixin.qq.com/cgi-bin/tags/update?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);

删除标签

		// 删除标签
		paramTag = new JSONObject();
		paramTag.put("id", 101);
		param = new JSONObject();
		param.put("tag", paramTag);
		url = "https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);

获取标签下粉丝列表

和获取公众号粉丝列表一样,next_openid用来表示返回结果开始的粉丝,如果为空则从头开始请求。

		// 获取标签下粉丝列表
		param = new JSONObject();
		param.put("tagid", 2);
		param.put("next_openid", ""); // 第一个拉取的OPENID,不填默认从头开始拉取
		url = "https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"count":2,"data":{"openid":["ohUHp6tQGQMqM-WuHMaCiR5AkY2Q","ohUHp6vyInrTn1HPrVPSewLd1AA8"]},"next_openid":"ohUHp6vyInrTn1HPrVPSewLd1AA8"}
		System.out.println(result);

批量为用户打标签

		// 批量为用户打标签
		JSONArray tagArray = new JSONArray();
		tagArray.add("ohUHp6vAGcGO94Taxc_0oSnYUBPE");
		tagArray.add("ohUHp6qmSOHeV5usTrtnD0w7tVnk");
		param = new JSONObject();
		param.put("tagid", 2);
		param.put("openid_list", tagArray);
		url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);

批量为用户取消标签

		// 批量为用户取消标签
		tagArray = new JSONArray();
		tagArray.add("ohUHp6vAGcGO94Taxc_0oSnYUBPE");
		tagArray.add("ohUHp6qmSOHeV5usTrtnD0w7tVnk");
		param = new JSONObject();
		param.put("tagid", 2);
		param.put("openid_list", tagArray);
		url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);

获取用户身上的标签列表

		// 获取用户身上的标签列表
		param = new JSONObject();
		param.put("openid", "ohUHp6tQGQMqM-WuHMaCiR5AkY2Q");
		url = "https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"tagid_list":[2]}
		System.out.println(result);

设置用户备注名

		// 设置用户备注名
		param = new JSONObject();
		param.put("openid", "ohUHp6tQGQMqM-WuHMaCiR5AkY2Q");
		param.put("remark", "我自己");
		url = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);

拉黑用户

		// 拉黑用户
		JSONArray openidArray = new JSONArray();
		openidArray.add("ohUHp6tQGQMqM-WuHMaCiR5AkY2Q");
		param = new JSONObject();
		param.put("openid_list", openidArray);
		url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchblacklist?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);

获取公众号的黑名单列表

该接口每次调用最多可拉取 1000 个OpenID,当列表数较多时,可以通过多次拉取的方式来满足需求。请求参数中begin_openid,第一次用空,从头开始拉取,后续的值就是返回结果中的next_openid

		// 获取公众号的黑名单列表
		param = new JSONObject();
		param.put("begin_openid", "");
		url = " https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"total":1,"count":1,"data":{"openid":["ohUHp6tQGQMqM-WuHMaCiR5AkY2Q"]},"next_openid":"ohUHp6tQGQMqM-WuHMaCiR5AkY2Q"}
		System.out.println(result);

取消拉黑用户

		// 取消拉黑用户
		openidArray = new JSONArray();
		openidArray.add("ohUHp6tQGQMqM-WuHMaCiR5AkY2Q");
		param = new JSONObject();
		param.put("openid_list", openidArray);
		url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);

获取用户地理位置

可查看公众号接收事件推送005部分接收方式。

			if(Objects.equals(event, "LOCATION")) {
				System.out.println("获取到用户地理位置");
				pw.write(nonce);
			}

全部Java代码


package com.lootaa.wechat;

import org.jsoup.Connection.Method;
import org.jsoup.Jsoup;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 用户管理
 * 前置条件:公众号后台设置ip白名单
 */
public class Test020 {

	public static final String APPID = "wx276049d6a7551dca";
	public static final String SECRET = "cbe109fdf6f399bd72ed3a4afafa21b1";
	
	/**
	 * 完整项目源码可关注公众号"lootaayun"(洛塔),回复020获取
	 */
	public static void main(String[] args) throws Exception {
		// 先获取access_token,这部分正式环境需要配置定时获取,每天2000次调用限制
		String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + APPID + "&secret=" + SECRET;
		String result = Jsoup.connect(url).ignoreContentType(true).method(Method.GET).execute().body();
		System.out.println(result);
		String accessToken = JSON.parseObject(result).getString("access_token");
		
		// 获取用户列表
		url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + accessToken + "&next_openid=";
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.GET).execute().body();
		// {"total":34,"count":34,"data":{"openid":["ohUHp6vAGcGO94Taxc_0oSnYUBPE","ohUHp6qmSOHeV5usTrtnD0w7tVnk","ohUHp6vnPi4ARLNtArgwB4w4VVig","ohUHp6rVTI71RrgbWF6qWWpqEtCY","ohUHp6pwjwmQaAGetOnPUS3AAbsk","ohUHp6r8i3LiIFvmKJgmIZCIzlMM","ohUHp6v0fKwY79yMwzlwN0ZHmsgE","ohUHp6hVRwrA9k8_brKmAwzEvlsQ","ohUHp6uAOC3sGKMqrHuZNAgLuv_E","ohUHp6n9OzbG7jcdw3aOyr5KqUIo","ohUHp6rtvLgqkS662YYNLQZRIpSE","ohUHp6iaFJq6SISTVwHS5lkb9Pb8","ohUHp6sXhGBEsSKs0Vfh_7cBoPM4","ohUHp6rmF2nUFQDNSUafBs3V629w","ohUHp6h5ZBih0XaH52VD5TT5LOMs","ohUHp6rkOiYFSqmqL3oW6k9ZZ-g4","ohUHp6lEFhbaE5TVP6Zsg-4-bhDQ","ohUHp6rATvuWnMrCy0TmT7l0S4xc","ohUHp6tjUIApeIN_OHio4KriTw4c","ohUHp6pU2OghKgBHv4p3eI0kQYBw","ohUHp6oKm1jbfCt51rxfagajAB2M","ohUHp6jWQ-ViDBoomB_3kId77lsg","ohUHp6jM9PSb8fdexNcZWkm9pH9M","ohUHp6tyhhY2munrSDeDVVWuBhwY","ohUHp6oJLFW8_lbzqtBD-LCwVc7Y","ohUHp6lOqgBpqMHsA8jEe4cGMxVw","ohUHp6oURwmnSFlIvFKuQRboB4C4","ohUHp6nxXyQaBDlXGcgYn9vHjcEc","ohUHp6q_iq2jONH3CSiq98Wd5H1w","ohUHp6tQGQMqM-WuHMaCiR5AkY2Q","ohUHp6vyInrTn1HPrVPSewLd1AA8","ohUHp6mFVMqSmjealNUblJA_ict8","ohUHp6uSohgIphGzkZMp3xxCdQtI","ohUHp6ik6cmQN7g5aT4GIw9CrnrY"]},"next_openid":"ohUHp6ik6cmQN7g5aT4GIw9CrnrY"}
		System.out.println(result);
		
		// 获取用户基本信息
		url = " https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + accessToken + "&openid=" + "ohUHp6vAGcGO94Taxc_0oSnYUBPE"  + "&lang=zh_CN";
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.GET).execute().body();
		// {"subscribe":1,"openid":"ohUHp6vAGcGO94Taxc_0oSnYUBPE","nickname":"","sex":0,"language":"zh_CN","city":"","province":"","country":"","headimgurl":"","subscribe_time":1603356138,"unionid":"oxayv6pIPFw50JuJG0K0UbFLa5dI","remark":"","groupid":0,"tagid_list":[],"subscribe_scene":"ADD_SCENE_QR_CODE","qr_scene":0,"qr_scene_str":""}
		System.out.println(result);
		
		// 批量获取用户基本信息
		JSONArray userArray = new JSONArray();
		JSONObject userObj = new JSONObject();
		userObj.put("openid", "ohUHp6tQGQMqM-WuHMaCiR5AkY2Q");
		userObj.put("lang", "zh_CN");
		userArray.add(userObj);
		userObj = new JSONObject();
		userObj.put("openid", "ohUHp6vyInrTn1HPrVPSewLd1AA8");
		userObj.put("lang", "zh_CN");
		userArray.add(userObj);
		JSONObject param = new JSONObject();
		param.put("user_list", userArray);
		url = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"user_info_list":[{"subscribe":1,"openid":"ohUHp6tQGQMqM-WuHMaCiR5AkY2Q","nickname":"","sex":0,"language":"zh_CN","city":"","province":"","country":"","headimgurl":"","subscribe_time":1632151818,"unionid":"oxayv6jAmsiSJYFeK0nSq6e7arVw","remark":"我自己","groupid":2,"tagid_list":[2],"subscribe_scene":"ADD_SCENE_QR_CODE","qr_scene":0,"qr_scene_str":""},{"subscribe":1,"openid":"ohUHp6vyInrTn1HPrVPSewLd1AA8","nickname":"","sex":0,"language":"zh_CN","city":"","province":"","country":"","headimgurl":"","subscribe_time":1665213460,"unionid":"oxayv6nRy9ATR4Q1Tn1VFG3N4mPo","remark":"","groupid":2,"tagid_list":[2],"subscribe_scene":"ADD_SCENE_SEARCH","qr_scene":0,"qr_scene_str":""}]}
		System.out.println(result);
		
		// 创建标签
		JSONObject paramTag = new JSONObject();
		paramTag.put("name", "测试标签");
		param = new JSONObject();
		param.put("tag", paramTag);
		url = "https://api.weixin.qq.com/cgi-bin/tags/create?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"tag":{"id":101,"name":"测试标签"}}
		System.out.println(result);
		
		// 标签列表
		url = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.GET).execute().body();
		// {"tags":[{"id":2,"name":"星标组","count":2},{"id":101,"name":"测试标签","count":0}]}
		System.out.println(result);
		
		// 编辑标签
		paramTag = new JSONObject();
		paramTag.put("name", "测试标签-变更后");
		paramTag.put("id", 101);
		param = new JSONObject();
		param.put("tag", paramTag);
		url = "https://api.weixin.qq.com/cgi-bin/tags/update?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);
		
		// 删除标签
		paramTag = new JSONObject();
		paramTag.put("id", 101);
		param = new JSONObject();
		param.put("tag", paramTag);
		url = "https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);
		
		// 获取标签下粉丝列表 
		param = new JSONObject();
		param.put("tagid", 2);
		param.put("next_openid", ""); // 第一个拉取的OPENID,不填默认从头开始拉取
		url = "https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"count":2,"data":{"openid":["ohUHp6tQGQMqM-WuHMaCiR5AkY2Q","ohUHp6vyInrTn1HPrVPSewLd1AA8"]},"next_openid":"ohUHp6vyInrTn1HPrVPSewLd1AA8"}
		System.out.println(result);
		
		// 批量为用户打标签
		JSONArray tagArray = new JSONArray();
		tagArray.add("ohUHp6vAGcGO94Taxc_0oSnYUBPE");
		tagArray.add("ohUHp6qmSOHeV5usTrtnD0w7tVnk");
		param = new JSONObject();
		param.put("tagid", 2);
		param.put("openid_list", tagArray);
		url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);
		
		// 批量为用户取消标签
		tagArray = new JSONArray();
		tagArray.add("ohUHp6vAGcGO94Taxc_0oSnYUBPE");
		tagArray.add("ohUHp6qmSOHeV5usTrtnD0w7tVnk");
		param = new JSONObject();
		param.put("tagid", 2);
		param.put("openid_list", tagArray);
		url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);
		
		// 获取用户身上的标签列表
		param = new JSONObject();
		param.put("openid", "ohUHp6tQGQMqM-WuHMaCiR5AkY2Q");
		url = "https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"tagid_list":[2]}
		System.out.println(result);
		
		// 设置用户备注名
		param = new JSONObject();
		param.put("openid", "ohUHp6tQGQMqM-WuHMaCiR5AkY2Q");
		param.put("remark", "我自己");
		url = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);
		
		
		// 拉黑用户
		JSONArray openidArray = new JSONArray();
		openidArray.add("ohUHp6tQGQMqM-WuHMaCiR5AkY2Q");
		param = new JSONObject();
		param.put("openid_list", openidArray);
		url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchblacklist?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);
		
		// 获取公众号的黑名单列表
		param = new JSONObject();
		param.put("begin_openid", "");
		url = " https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"total":1,"count":1,"data":{"openid":["ohUHp6tQGQMqM-WuHMaCiR5AkY2Q"]},"next_openid":"ohUHp6tQGQMqM-WuHMaCiR5AkY2Q"}
		System.out.println(result);
		
		// 取消拉黑用户
		openidArray = new JSONArray();
		openidArray.add("ohUHp6tQGQMqM-WuHMaCiR5AkY2Q");
		param = new JSONObject();
		param.put("openid_list", openidArray);
		url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist?access_token=" + accessToken;
		result = Jsoup.connect(url).ignoreContentType(true).method(Method.POST).requestBody(param.toString()).execute().body();
		// {"errcode":0,"errmsg":"ok"}
		System.out.println(result);
		
	}
	
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lootaa

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值