个人记录使用
public String getWxListHandle(String access_token, String next_openid, StringBuffer stringBuffer) {
String unionid = "";
List<Map> user_list = new ArrayList<Map>();
String wxcUserList = getWXCUserList(access_token, next_openid);
List list = new ArrayList<String>();
Map map = new HashMap();
if (wxcUserList !=null && !"".equals(wxcUserList)) {
Map mapB = JSONObject.parseObject(wxcUserList, Map.class);
int errcode = mapB.containsKey("errcode") ? Integer.parseInt(mapB.get("errcode").toString()) : 0;
if(errcode == 40001){
access_token = 获取access_token
getWxListHandle(access_token, next_openid, stringBuffer);
}
int total = mapB.containsKey("total") ? Integer.parseInt(mapB.get("total").toString()) : 0;
if (total == 0) {
return "0";
}
next_openid = mapB.containsKey("next_openid") ? mapB.get("next_openid").toString() : "";
int count = mapB.containsKey("count") ? Integer.parseInt(mapB.get("count").toString()) : 0;
map = mapB.containsKey("data") ? JSONObject.parseObject(mapB.get("data").toString(), Map.class) : null;
if (map == null || map.size() == 0) {
return "0";
}
if(map.containsKey("openid")){
list = JSONObject.parseObject(map.get("openid").toString(), List.class);
}
for (int y = 0; y < list.size(); y++) {
Map<String, String> user_map = new HashMap<String, String>();
user_map.put("openid", list.get(y).toString());
user_map.put("lang", "zh_CN");
user_list.add(user_map);
if(y > 0 && (y%99 == 0 || y == list.size()-1)){
String user_info_query = getFollow(access_token, user_list);
if("".equals(user_info_query)){
continue;
}
Map user_info_map = new HashMap();
if(user_info_query.contains("user_info_list")){
user_info_map = JSONObject.parseObject(user_info_query, Map.class);
}
if(user_info_map ==null || !user_info_map.containsKey("user_info_list")){
continue;
}
List<Map> user_info_list = JSONObject.parseObject(user_info_map.get("user_info_list").toString(), List.class);
for (int x = 0; x < user_info_list.size(); x++) {
Object object = user_info_list.get(x).get("unionid");
if(object ==null ||"".equals(object)){
continue;
}
unionid = object.toString();
if ("".equals(unionid)) {
continue;
}
String sql = "select unionid,openid from 用户表where deleted = 0 and unionid = ?";
List<Map> list_integral = jdbcDao.queryForList(sql, new String[]{unionid});
if (list_integral != null && list_integral.size() > 0) {
String openid = list_integral.get(0).get("openid").toString();
stringBuffer.append("'" + openid + "',");
}
}
user_list.clear();
}
}
if (count == 10000) {
getWxListHandle(access_token, next_openid, stringBuffer);
} else {
return "1";
}
} else {
return "0";
}
return "0";
}
public String getWXCUserList(String access_token, String next_openid) {
List<NameValuePair> reqParamUser = new ArrayList<NameValuePair>();
reqParamUser.add(new BasicNameValuePair("access_token", access_token));
reqParamUser.add(new BasicNameValuePair("next_openid", next_openid));
String resultUn = common.get("https://api.weixin.qq.com/cgi-bin/user/get", reqParamUser);
return resultUn;
}
public String getFollow(String access_token, List lists) {
String url = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token="+access_token;
Map map =new HashMap();
map.put("user_list",lists);
String resultUn = common.post(url,JSON.toJSONString(map));
return resultUn;
}