mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
添加批量查询用户基本信息功能,没有测试,没有添加超过100验证
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.WxMpUserQuery;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
|
||||
@@ -11,35 +14,55 @@ import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
*/
|
||||
public interface WxMpUserService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 设置用户备注名接口
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=设置用户备注名接口
|
||||
* </pre>
|
||||
*
|
||||
* @param openid 用户openid
|
||||
* @param remark 备注名
|
||||
*/
|
||||
void userUpdateRemark(String openid, String remark) throws WxErrorException;
|
||||
/**
|
||||
* <pre>
|
||||
* 设置用户备注名接口
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=设置用户备注名接口
|
||||
* </pre>
|
||||
*
|
||||
* @param openid 用户openid
|
||||
* @param remark 备注名
|
||||
*/
|
||||
void userUpdateRemark(String openid, String remark) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取用户基本信息
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取用户基本信息
|
||||
* </pre>
|
||||
*
|
||||
* @param openid 用户openid
|
||||
* @param lang 语言,zh_CN 简体(默认),zh_TW 繁体,en 英语
|
||||
*/
|
||||
WxMpUser userInfo(String openid, String lang) throws WxErrorException;
|
||||
/**
|
||||
* <pre>
|
||||
* 获取用户基本信息
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取用户基本信息
|
||||
* </pre>
|
||||
*
|
||||
* @param openid 用户openid
|
||||
* @param lang 语言,zh_CN 简体(默认),zh_TW 繁体,en 英语
|
||||
*/
|
||||
WxMpUser userInfo(String openid, String lang) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取关注者列表
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取关注者列表
|
||||
* </pre>
|
||||
*
|
||||
* @param next_openid 可选,第一个拉取的OPENID,null为从头开始拉取
|
||||
*/
|
||||
WxMpUserList userList(String next_openid) throws WxErrorException;
|
||||
/**
|
||||
* <pre>
|
||||
* 获取用户基本信息列表
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=批量获取用户基本信息
|
||||
* </pre>
|
||||
*
|
||||
* @param openid 用户openid, lang 使用默认(zh_CN 简体)
|
||||
*/
|
||||
List<WxMpUser> userInfoList(List<String> openidList) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取用户基本信息列表
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=批量获取用户基本信息
|
||||
* </pre>
|
||||
*
|
||||
* @param userQuery 详细查询参数
|
||||
*/
|
||||
List<WxMpUser> userInfoList(WxMpUserQuery userQuery) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取关注者列表
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取关注者列表
|
||||
* </pre>
|
||||
*
|
||||
* @param nextOpenid 可选,第一个拉取的OPENID,null为从头开始拉取
|
||||
*/
|
||||
WxMpUserList userList(String nextOpenid) throws WxErrorException;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
@@ -7,6 +9,7 @@ import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserService;
|
||||
import me.chanjar.weixin.mp.bean.WxMpUserQuery;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
|
||||
@@ -14,35 +17,47 @@ import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
* Created by Binary Wang on 2016/7/21.
|
||||
*/
|
||||
public class WxMpUserServiceImpl implements WxMpUserService {
|
||||
private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/user";
|
||||
private WxMpService wxMpService;
|
||||
private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/user";
|
||||
private WxMpService wxMpService;
|
||||
|
||||
public WxMpUserServiceImpl(WxMpService wxMpService) {
|
||||
this.wxMpService = wxMpService;
|
||||
}
|
||||
public WxMpUserServiceImpl(WxMpService wxMpService) {
|
||||
this.wxMpService = wxMpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userUpdateRemark(String openid, String remark) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/info/updateremark";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("openid", openid);
|
||||
json.addProperty("remark", remark);
|
||||
this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
}
|
||||
@Override
|
||||
public void userUpdateRemark(String openid, String remark) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/info/updateremark";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("openid", openid);
|
||||
json.addProperty("remark", remark);
|
||||
this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpUser userInfo(String openid, String lang) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/info";
|
||||
lang = lang == null ? "zh_CN" : lang;
|
||||
String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, "openid=" + openid + "&lang=" + lang);
|
||||
return WxMpUser.fromJson(responseContent);
|
||||
}
|
||||
@Override
|
||||
public WxMpUser userInfo(String openid, String lang) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/info";
|
||||
lang = lang == null ? "zh_CN" : lang;
|
||||
String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, "openid=" + openid + "&lang=" + lang);
|
||||
return WxMpUser.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpUserList userList(String next_openid) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/get";
|
||||
String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, next_openid == null ? null : "next_openid=" + next_openid);
|
||||
return WxMpUserList.fromJson(responseContent);
|
||||
}
|
||||
@Override
|
||||
public WxMpUserList userList(String next_openid) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/get";
|
||||
String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, next_openid == null ? null : "next_openid=" + next_openid);
|
||||
return WxMpUserList.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxMpUser> userInfoList(List<String> openidList) throws WxErrorException {
|
||||
return userInfoList(new WxMpUserQuery(openidList));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxMpUser> userInfoList(WxMpUserQuery userQuery) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/info/batchget";
|
||||
String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, userQuery.toJsonString());
|
||||
return WxMpUser.fromJsonList(responseContent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user