🎨 #2811 【公众号】用户管理增加可一次性拉取所有用户数据的接口

This commit is contained in:
Cocowwy 2022-09-13 21:41:49 +08:00 committed by GitHub
parent 310e1d91be
commit 286596f8a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -93,6 +93,19 @@ public interface WxMpUserService {
*/
WxMpUserList userList(String nextOpenid) throws WxErrorException;
/**
* <pre>
* 获取用户列表全部
* 公众号可通过本接口来获取帐号的关注者列表
* 关注者列表由一串OpenID加密后的微信号每个用户对每个公众号的OpenID是唯一的组成
* @see #userList(java.lang.String) 的增强内部进行了多次数据拉取的汇总
* 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140840&token=&lang=zh_CN
* http请求方式: GET请使用https协议
* 接口地址https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID
* </pre>
*/
WxMpUserList userList() throws WxErrorException;
/**
* <pre>
* 微信公众号主体变更迁移用户 openid

View File

@ -10,6 +10,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.List;
@ -52,6 +53,25 @@ public class WxMpUserServiceImpl implements WxMpUserService {
return WxMpUserList.fromJson(responseContent);
}
@Override
public WxMpUserList userList() throws WxErrorException {
String responseContent = this.wxMpService.get(USER_GET_URL, null);
WxMpUserList mergeList = new WxMpUserList();
WxMpUserList wxMpUserList = WxMpUserList.fromJson(responseContent);
mergeList.getOpenids().addAll(wxMpUserList.getOpenids());
mergeList.setCount(wxMpUserList.getCount());
mergeList.setTotal(wxMpUserList.getTotal());
while (StringUtils.isNotEmpty(wxMpUserList.getNextOpenid())) {
WxMpUserList nextReqUserList = userList(wxMpUserList.getNextOpenid());
mergeList.getOpenids().addAll(nextReqUserList.getOpenids());
mergeList.setCount(mergeList.getCount() + nextReqUserList.getCount());
wxMpUserList = nextReqUserList;
}
return mergeList;
}
@Override
public List<WxMpChangeOpenid> changeOpenid(String fromAppid, List<String> openidList) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);