当前位置:网站首页>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
边栏推荐
- 计算神经网络推理时间的正确方法
- 洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解
- Play with binary tree (25 points)
- 关于数组复制问题
- Go语言自学系列 | golang结构体的初始化
- Illegal character in scheme name at index 0:
- 还原二叉树 (25 分)
- L2-023 图着色问题 (25 分)(图的遍历)
- 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
- Noyer électronique stm32 Introduction à l'Internet des objets 30 étapes notes I. différences entre la Bibliothèque Hal et la Bibliothèque standard
猜你喜欢

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

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

Star Trek's strong attack opens the dream linkage between metacosmic virtual reality

正点原子携手OneOS直播 OneOS系统教程全面上线

DJ音乐管理软件Pioneer DJ rekordbox

'恶霸' Oracle 又放大招,各大企业连夜删除 JDK。。。

MATLAB 画五星红旗

RCC introduction of Hal Library

增强现实技术是什么?能用在哪些地方?

LaTeX论文排版操作
随机推荐
Idea is configured to connect to the remote database mysql, or Navicat fails to connect to the remote database (solved)
K210学习笔记(二) K210与STM32进行串口通信
Output first order traversal according to second order and middle order traversal (25 points)
L2-3 浪漫侧影 (25 分)
JVM工具之Arthas使用
Idea package jar file
rembg 分割mask
2022-04-22 OpenEBS云原生存储
idea打包 jar文件
计算神经网络推理时间的正确方法
Harbor企业级镜像管理系统实战
MATLAB入门资料
Chris LATTNER, father of llvm: the golden age of compilers
Large amount of data submitted by form post
Star Trek's strong attack opens the dream linkage between metacosmic virtual reality
STM32 uses Hal library. The overall structure and function principle are introduced
'bully' Oracle enlarged its move again, and major enterprises deleted JDK overnight...
根据后序和中序遍历输出先序遍历 (25 分)
测试你的机器学习流水线
2022-04-22 openebs cloud native storage