weixin4j-mp:新增批量获取用户信息接口
This commit is contained in:
parent
aa1d66c1f9
commit
8bef11f99b
@ -864,6 +864,43 @@ public class WeixinProxy {
|
|||||||
return userApi.getUser(openId, lang);
|
return userApi.getUser(openId, lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量获取用户信息
|
||||||
|
*
|
||||||
|
* @param openIds
|
||||||
|
* 用户ID
|
||||||
|
* @return 用户列表
|
||||||
|
* @see <a
|
||||||
|
* href="http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html">获取用户信息</a>
|
||||||
|
* @see com.foxinmy.weixin4j.mp.model.User
|
||||||
|
* @see com.foxinmy.weixin4j.mp.api.UserApi
|
||||||
|
* @throws WeixinException
|
||||||
|
* @see {@link #getUsers(Lang,String[])}
|
||||||
|
*/
|
||||||
|
public List<User> getUsers(String... openIds) throws WeixinException {
|
||||||
|
return userApi.getUsers(openIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量获取用户信息
|
||||||
|
*
|
||||||
|
* @param lang
|
||||||
|
* 国家地区语言版本
|
||||||
|
* @param openIds
|
||||||
|
* 用户ID
|
||||||
|
* @return 用户列表
|
||||||
|
* @see <a
|
||||||
|
* href="http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html">获取用户信息</a>
|
||||||
|
* @see com.foxinmy.weixin4j.mp.type.Lang
|
||||||
|
* @see com.foxinmy.weixin4j.mp.model.User
|
||||||
|
* @see com.foxinmy.weixin4j.mp.api.UserApi
|
||||||
|
* @throws WeixinException
|
||||||
|
*/
|
||||||
|
public List<User> getUsers(Lang lang, String... openIds)
|
||||||
|
throws WeixinException {
|
||||||
|
return userApi.getUsers(lang, openIds);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户一定数量(10000)的关注者列表
|
* 获取用户一定数量(10000)的关注者列表
|
||||||
*
|
*
|
||||||
|
|||||||
@ -39,9 +39,6 @@ public class UserApi extends MpApi {
|
|||||||
* 用户对应的ID
|
* 用户对应的ID
|
||||||
* @return 用户对象
|
* @return 用户对象
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
|
||||||
* href="http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html">获取用户信息</a>
|
|
||||||
* @see com.foxinmy.weixin4j.mp.model.User
|
|
||||||
* @see {@link #getUser(String,Lang)}
|
* @see {@link #getUser(String,Lang)}
|
||||||
*/
|
*/
|
||||||
public User getUser(String openId) throws WeixinException {
|
public User getUser(String openId) throws WeixinException {
|
||||||
@ -69,13 +66,64 @@ public class UserApi extends MpApi {
|
|||||||
public User getUser(String openId, Lang lang) throws WeixinException {
|
public User getUser(String openId, Lang lang) throws WeixinException {
|
||||||
String user_info_uri = getRequestUri("api_user_info_uri");
|
String user_info_uri = getRequestUri("api_user_info_uri");
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
WeixinResponse response = weixinExecutor.get(String.format(user_info_uri,
|
WeixinResponse response = weixinExecutor.get(String.format(
|
||||||
token.getAccessToken(), openId, lang.name()));
|
user_info_uri, token.getAccessToken(), openId, lang.name()));
|
||||||
|
|
||||||
return response.getAsObject(new TypeReference<User>() {
|
return response.getAsObject(new TypeReference<User>() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量获取用户信息
|
||||||
|
*
|
||||||
|
* @param openIds
|
||||||
|
* 用户ID
|
||||||
|
* @return 用户列表
|
||||||
|
* @see <a
|
||||||
|
* href="http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html">获取用户信息</a>
|
||||||
|
* @see com.foxinmy.weixin4j.mp.model.User
|
||||||
|
* @throws WeixinException
|
||||||
|
* @see {@link #getUsers(Lang,String[])}
|
||||||
|
*/
|
||||||
|
public List<User> getUsers(String... openIds) throws WeixinException {
|
||||||
|
return getUsers(Lang.zh_CN, openIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量获取用户信息
|
||||||
|
*
|
||||||
|
* @param lang
|
||||||
|
* 国家地区语言版本
|
||||||
|
* @param openIds
|
||||||
|
* 用户ID
|
||||||
|
* @return 用户列表
|
||||||
|
* @see <a
|
||||||
|
* href="http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html">获取用户信息</a>
|
||||||
|
* @see com.foxinmy.weixin4j.mp.type.Lang
|
||||||
|
* @see com.foxinmy.weixin4j.mp.model.User
|
||||||
|
* @throws WeixinException
|
||||||
|
*/
|
||||||
|
public List<User> getUsers(Lang lang, String... openIds)
|
||||||
|
throws WeixinException {
|
||||||
|
String api_users_info_uri = getRequestUri("api_users_info_uri");
|
||||||
|
StringBuilder parameter = new StringBuilder();
|
||||||
|
parameter.append("{\"user_list\": [");
|
||||||
|
for (String openId : openIds) {
|
||||||
|
parameter.append("{\"openid\": \"").append(openId).append("\"");
|
||||||
|
parameter.append(",\"lang\": \"").append(lang.name()).append("\"")
|
||||||
|
.append("},");
|
||||||
|
}
|
||||||
|
parameter.delete(parameter.length() - 1, parameter.length());
|
||||||
|
parameter.append("]}");
|
||||||
|
Token token = tokenHolder.getToken();
|
||||||
|
WeixinResponse response = weixinExecutor.post(
|
||||||
|
String.format(api_users_info_uri, token.getAccessToken()),
|
||||||
|
parameter.toString());
|
||||||
|
|
||||||
|
return JSON.parseArray(
|
||||||
|
response.getAsJson().getString("user_info_list"), User.class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户一定数量(10000)的关注者列表
|
* 获取用户一定数量(10000)的关注者列表
|
||||||
*
|
*
|
||||||
@ -90,8 +138,9 @@ public class UserApi extends MpApi {
|
|||||||
public Following getFollowing(String nextOpenId) throws WeixinException {
|
public Following getFollowing(String nextOpenId) throws WeixinException {
|
||||||
String following_uri = getRequestUri("following_uri");
|
String following_uri = getRequestUri("following_uri");
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
WeixinResponse response = weixinExecutor.get(String.format(following_uri,
|
WeixinResponse response = weixinExecutor.get(String.format(
|
||||||
token.getAccessToken(), nextOpenId == null ? "" : nextOpenId));
|
following_uri, token.getAccessToken(), nextOpenId == null ? ""
|
||||||
|
: nextOpenId));
|
||||||
|
|
||||||
Following following = response
|
Following following = response
|
||||||
.getAsObject(new TypeReference<Following>() {
|
.getAsObject(new TypeReference<Following>() {
|
||||||
|
|||||||
@ -23,6 +23,8 @@ sns_user_info_uri=https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=
|
|||||||
|
|
||||||
# \u76f4\u63a5\u83b7\u53d6\u7528\u6237\u4fe1\u606f
|
# \u76f4\u63a5\u83b7\u53d6\u7528\u6237\u4fe1\u606f
|
||||||
api_user_info_uri={api_cgi_url}/user/info?access_token=%s&openid=%s&lang=%s
|
api_user_info_uri={api_cgi_url}/user/info?access_token=%s&openid=%s&lang=%s
|
||||||
|
# \u6279\u91cf\u83b7\u53d6\u7528\u6237\u4fe1\u606f
|
||||||
|
api_users_info_uri={api_cgi_url}/user/info/batchget?access_token=%s
|
||||||
# \u83b7\u53d6token
|
# \u83b7\u53d6token
|
||||||
api_token_uri={api_cgi_url}/token?grant_type=client_credential&appid=%s&secret=%s
|
api_token_uri={api_cgi_url}/token?grant_type=client_credential&appid=%s&secret=%s
|
||||||
# \u83b7\u53d6\u4e8c\u7ef4\u7801
|
# \u83b7\u53d6\u4e8c\u7ef4\u7801
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user