当前位置:网站首页>微信:获取单个标签所有人
微信:获取单个标签所有人
2022-04-23 08:39:00 【HezhezhiyuLe】
前言
实际业务场景可能需要一个标签下的所有人,做一些指定操作,所以出一个工具类获取所有标签下的人
代码
@Autowired
private RestTemplate restTemplate;
private String smSpToken;
/** * 查询标签下所有人 * @param tag 标签ID必填 * @return 标签内人员openid */
public List<String> findUserByTag(int tag){
ArrayList<String> openids = new ArrayList<>();
// 微信token
String smSpToken="";
// 下一个ID默认第一个为空
String openid="";
// 循环次数更具你标签有多少人写多少 一次循环一万人
for (int i = 0; i < 40; i++) {
System.out.println("第"+i);
String url="https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token="+smSpToken;
TagWxUser tagWxUser = new TagWxUser();
tagWxUser.setTagid(tag);
tagWxUser.setNext_openid(openid);
String param=JSON.toJSONString(tagWxUser);;
System.out.println(param);
//发送方式自定义
String body = restTemplate.postForEntity(url, param, String.class).getBody();
if(body.contains("errcode")){
System.out.println(body);
continue;
}
if(body!=null&&!"".equals(body)){
JSONObject jsonObject = JSONObject.fromObject(body);
int count = jsonObject.getInt("count");
if(count==0){
// 最后一个ID返回值是0
System.out.println(body);
System.out.println("获取结束 "+i+" "+openids.size()+" %%"+" "+body);
break;
}
// 解析返回值
String next_openid = jsonObject.getString("next_openid");
if(next_openid!=null&&!"".equals(next_openid)){
System.out.println("下一个:"+next_openid);
openid=next_openid;
String data = jsonObject.getString("data");
if(data!=null&&!"".equals(data)){
JSONObject jsonObject2 = JSONObject.fromObject(data);
String tagopenid = jsonObject2.getString("openid");
if(tagopenid!=null&&!"".equals(tagopenid)){
List<String> arr = JSON.parseArray(tagopenid, String.class);
if(arr!=null&&arr.size()>0){
openids.addAll(arr);
}
}
}
}
}
}
return openids;
}
版权声明
本文为[HezhezhiyuLe]所创,转载请带上原文链接,感谢
https://blog.csdn.net/HezhezhiyuLe/article/details/112647693
边栏推荐
- ajax防止缓存方法
- How to encrypt devices under the interconnection of all things
- 求简单类型的矩阵和
- Word plus watermark
- Detailed description of self feeling of auricular point weight loss 0422
- Kubernetes如何使用harbor拉去私有镜像
- HAL库的RCC简介
- Queue (C language / linked list)
- 【58】最后一个单词的长度【LeetCode】
- Knowledge points and problem solutions related to information collection
猜你喜欢
K210学习笔记(二) K210与STM32进行串口通信
Shell脚本进阶
Get the absolute path of the class according to the bytecode
L2-3 浪漫侧影 (25 分)
四张图弄懂matplotlib的一些基本用法
Shell script advanced
Transformer XL: attention language modelsbbeyond a fixed length context paper summary
'恶霸' Oracle 又放大招,各大企业连夜删除 JDK。。。
[explanation] get ora-12838: cannot read / modify an object after modifying it in parallel
MATLAB 画五星红旗
随机推荐
汇编语言与逆向工程 栈溢出漏洞逆向分析实验报告
Transformer XL: attention language modelsbbeyond a fixed length context paper summary
是否同一棵二叉搜索树 (25 分)
How much inventory recording does the intelligent system of external call system of okcc call center need?
洋桃电子STM32物联网入门30步笔记四、工程编译和下载
对OutputStream类的flush()方法的误解
DOM学习笔记---遍历页面所有元素节点
扣缴义务人
Consensus Token:web3.0生态流量的超级入口
ESP32程序下载失败,提示超时
Protobuf简介
Notes on English class (4)
Record: JS several methods to delete one or more items in the array
STM32使用HAL库,整体结构和函数原理介绍
[explanation] get ora-12838: cannot read / modify an object after modifying it in parallel
第一性原理 思维导图
How to generate assembly file
正点原子携手OneOS直播 OneOS系统教程全面上线
okcc呼叫中心外呼系统智能系统需要用多大的盘存录音?
SYS_CONNECT_BY_PATH(column,'char') 结合 start with ... connect by prior