From e1907e6a2ff4c1f3b796da8139ac15162a7736a2 Mon Sep 17 00:00:00 2001 From: Cocowwy <514658459@qq.com> Date: Wed, 7 Sep 2022 17:42:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90feat=E3=80=91me.chanjar.weixin.mp.?= =?UTF-8?q?api.WxMpUserService.userList(java.lang.String)=20=E9=87=8D?= =?UTF-8?q?=E8=BD=BD=E4=BA=86=E4=B8=80=E4=B8=AA=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=B1=8F=E8=94=BD=E5=A4=9A=E6=AC=A1=E9=9C=80=E8=A6=81=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E6=8B=89=E5=8F=96=EF=BC=8C=E5=AF=B9=E4=BA=8E=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=96=B9=EF=BC=8C=E5=8F=AF=E4=B8=80=E6=AC=A1=E6=80=A7?= =?UTF-8?q?=E6=8B=89=E5=8F=96=E6=89=80=E6=9C=89=E7=94=A8=E6=88=B7=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpUserService.java | 13 ++++++++++++ .../mp/api/impl/WxMpUserServiceImpl.java | 20 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java index 00eea89e74..d347864cba 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserService.java @@ -93,6 +93,19 @@ public interface WxMpUserService { */ WxMpUserList userList(String nextOpenid) throws WxErrorException; + /** + *
+ * 获取用户列表(全部) + * 公众号可通过本接口来获取帐号的关注者列表, + * 关注者列表由一串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 + *+ */ + WxMpUserList userList() throws WxErrorException; + /** *
* 微信公众号主体变更迁移用户 openid diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java index 03c83e3b45..02ef002f99 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java @@ -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; @@ -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 merageList = new WxMpUserList(); + + WxMpUserList wxMpUserList = WxMpUserList.fromJson(responseContent); + merageList.getOpenids().addAll(wxMpUserList.getOpenids()); + merageList.setCount(wxMpUserList.getCount()); + merageList.setTotal(wxMpUserList.getTotal()); + + while (StringUtils.isNotEmpty(wxMpUserList.getNextOpenid())) { + WxMpUserList nextReqUserList = userList(wxMpUserList.getNextOpenid()); + merageList.getOpenids().addAll(nextReqUserList.getOpenids()); + merageList.setCount(merageList.getCount() + nextReqUserList.getCount()); + wxMpUserList = nextReqUserList; + } + return merageList; + } + @Override public ListchangeOpenid(String fromAppid, List openidList) throws WxErrorException { Map map = new HashMap<>(2); From 015ce09ead2b278e3e56eb487f7dd53492daa33e Mon Sep 17 00:00:00 2001 From: Cocowwy <514658459@qq.com> Date: Tue, 13 Sep 2022 14:51:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?:art:=20merageList=E5=8D=95=E8=AF=8D?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=AE=E6=94=B9=E4=B8=BAmergeList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/impl/WxMpUserServiceImpl.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java index 02ef002f99..8308f6df8d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImpl.java @@ -56,20 +56,20 @@ public WxMpUserList userList(String nextOpenid) throws WxErrorException { @Override public WxMpUserList userList() throws WxErrorException { String responseContent = this.wxMpService.get(USER_GET_URL, null); - WxMpUserList merageList = new WxMpUserList(); + WxMpUserList mergeList = new WxMpUserList(); WxMpUserList wxMpUserList = WxMpUserList.fromJson(responseContent); - merageList.getOpenids().addAll(wxMpUserList.getOpenids()); - merageList.setCount(wxMpUserList.getCount()); - merageList.setTotal(wxMpUserList.getTotal()); + mergeList.getOpenids().addAll(wxMpUserList.getOpenids()); + mergeList.setCount(wxMpUserList.getCount()); + mergeList.setTotal(wxMpUserList.getTotal()); while (StringUtils.isNotEmpty(wxMpUserList.getNextOpenid())) { WxMpUserList nextReqUserList = userList(wxMpUserList.getNextOpenid()); - merageList.getOpenids().addAll(nextReqUserList.getOpenids()); - merageList.setCount(merageList.getCount() + nextReqUserList.getCount()); + mergeList.getOpenids().addAll(nextReqUserList.getOpenids()); + mergeList.setCount(mergeList.getCount() + nextReqUserList.getCount()); wxMpUserList = nextReqUserList; } - return merageList; + return mergeList; } @Override