Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用户管理相关操作接口-PR了一个重载方法,调用方无需多次调用拼接数据 #2811

Merged
merged 3 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand Down Expand Up @@ -52,6 +53,25 @@ public WxMpUserList userList(String nextOpenid) throws WxErrorException {
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);
Expand Down