当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
面了一圈,整理了这套面试题。。
Idea package jar file
xctf刷题小记
Go语言自学系列 | golang结构体的初始化
Latex mathematical formula
【精品】利用动态代理实现事务统一管理 二
OneFlow学习笔记:从Functor到OpExprInterpreter
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
Queue (C language / linked list)
Ear acupoint diagnosis and treatment essay 0421
idea底栏打开services
RCC introduction of Hal Library
okcc呼叫中心外呼系统智能系统需要用多大的盘存录音?
JSP page coding
Stm32f103zet6 [development of standard library functions] - Introduction to library functions
Type anonyme (Principes fondamentaux du Guide c)
1099 建立二叉搜索树 (30 分)
L2-022 重排链表 (25 分)(map+结构体模拟)
洋桃电子STM32物联网入门30步笔记四、工程编译和下载
STM32使用HAL库,整体结构和函数原理介绍









