com.jfinal.weixin.sdk.api.UserApi Maven / Gradle / Ivy
/**
* Copyright (c) 2011-2014, James Zhan 詹波 ([email protected]).
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
package com.jfinal.weixin.sdk.api;
import com.jfinal.weixin.sdk.kit.ParaMap;
import com.jfinal.weixin.sdk.utils.HttpUtils;
import com.jfinal.weixin.sdk.utils.JsonUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 用户管理 API
*
* https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
*
*/
public class UserApi {
private static String getUserInfo = "https://api.weixin.qq.com/cgi-bin/user/info";
private static String getFollowers = "https://api.weixin.qq.com/cgi-bin/user/get";
private static String batchGetUserInfo = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=";
/**
* 获取用户基本信息(包括UnionID机制)
* @param openId 普通用户的标识,对当前公众号唯一
* @return ApiResult
*/
public static ApiResult getUserInfo(String openId) {
ParaMap pm = ParaMap.create("access_token", AccessTokenApi.getAccessTokenStr()).put("openid", openId).put("lang", "zh_CN");
return new ApiResult(HttpUtils.get(getUserInfo, pm.getData()));
}
/**
* 获取用户列表
* @param nextOpenid 第一个拉取的OPENID,不填默认从头开始拉取
* @return ApiResult
*/
public static ApiResult getFollowers(String nextOpenid) {
ParaMap pm = ParaMap.create("access_token", AccessTokenApi.getAccessTokenStr());
if (nextOpenid != null)
pm.put("next_openid", nextOpenid);
return new ApiResult(HttpUtils.get(getFollowers, pm.getData()));
}
/**
* 获取用户列表
* @return ApiResult
*/
public static ApiResult getFollows() {
return getFollowers(null);
}
/**
* 批量获取用户基本信息, by Unas
* @param jsonStr json字符串
* @return ApiResult
*/
public static ApiResult batchGetUserInfo(String jsonStr) {
String jsonResult = HttpUtils.post(batchGetUserInfo + AccessTokenApi.getAccessTokenStr(), jsonStr);
return new ApiResult(jsonResult);
}
/**
* 批量获取用户基本信息
* @param openIdList openid列表
* @return ApiResult
*/
public static ApiResult batchGetUserInfo(List openIdList) {
Map>> userListMap = new HashMap>>();
List