当前位置:网站首页>Wechat: get the owner of a single tag
Wechat: get the owner of a single tag
2022-04-23 08:46:00 【HezhezhiyuLe】
Preface
The actual business scenario may require everyone under a label , Do some specified operations , So a tool class is created to get all the people under the tag
Code
@Autowired
private RestTemplate restTemplate;
private String smSpToken;
/** * Query everyone under the tag * @param tag label ID Required * @return Personnel in the label openid */
public List<String> findUserByTag(int tag){
ArrayList<String> openids = new ArrayList<>();
// WeChat token
String smSpToken="";
// next ID The first one is empty by default
String openid="";
// The number of cycles is more specific to how many people write your label 10000 people in a cycle
for (int i = 0; i < 40; i++) {
System.out.println(" The first "+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);
// Custom sending method
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){
// the last one ID The return value is 0
System.out.println(body);
System.out.println(" End of acquisition "+i+" "+openids.size()+" %%"+" "+body);
break;
}
// Parse the return value
String next_openid = jsonObject.getString("next_openid");
if(next_openid!=null&&!"".equals(next_openid)){
System.out.println(" next :"+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://yzsam.com/2022/04/202204230839448097.html
边栏推荐
猜你喜欢

PLC的点表(寄存器地址和点表定义)破解探测方案--方便工业互联网数据采集

使用flask和h5搭建网站/应用的简要步骤

MySQL查询两张表属性值非重复的数据

2022-04-22 openebs cloud native storage

K210学习笔记(二) K210与STM32进行串口通信

RCC introduction of Hal Library

洋桃電子STM32物聯網入門30步筆記一、HAL庫和標准庫的區別

L2-022 重排链表 (25 分)(map+结构体模拟)

洋桃电子STM32物联网入门30步笔记二、CubeIDE下载、安装、汉化、设置

Study notes of deep learning (8)
随机推荐
【58】最后一个单词的长度【LeetCode】
Go语言自学系列 | golang结构体的初始化
Idea package jar file
测试你的机器学习流水线
Misunderstanding of flush () method of OutputStream class
Idea import commons-logging-1.2 Jar package
Excle plus watermark
xctf刷题小记
Consensus Token:web3.0生态流量的超级入口
Go语言自学系列 | golang结构体作为函数参数
On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched
Notes on 30 steps of introduction to the Internet of things of yangtao electronics STM32 III. cubemx graphical programming and setting the IO port on the development board
Introduction to GUI programming swing
玩转二叉树 (25 分)
Stm32f103zet6 [development of standard library functions] - Introduction to library functions
Basic usage of synchronized locks
Solidity 问题汇总
虚拟线上展会-线上vr展馆实现24h沉浸式看展
深度学习框架中的自动微分及高阶导数
PgSQL wants to implement all kinds of column sub query operations of MySQL