天天看点

获取微信用户列表Openid

    public static JSONArray getWechatUserOpenIds(String nextOpenid) {

        // 获取微信用户openid的json数组

        JSONArray openIdArry = null;

        // 获取微信的access_token凭证

        String access_token = (String) Cache.get(WXConst.ACCESS_TOKEN);

        // 获取我心用户openid的url(当数据量特大时)

        // String requestUrl

        // =WXConst.GET_wechatUser_OPENID_URL+access_token+"&next_openid="+nextOpenid;

        // 获取我心用户openid的url(当数据量不大时)

        String requestUrl = WXConst.GET_WECHATUSER_OPENID_URL + access_token;

        try {

            // 请求微信接口获得的的结果对象

            String result = WXHttpUtil.MsgHttpsRequest(requestUrl, "GET", null);

            // 判断请求是否成功

            if (!result.contains(Const.ERRCODE)) {

                // 请求成功返回成功的消息

                System.out.println(Messages.get("get_weChatUser_list_success") + result);

                // 将返回的result对象转成JSON对象进行解析

                JSONObject resultObj = new JSONObject(result);

                // 微信该公众账号的总用户数

                String total = resultObj.getString("total");

                // 拉取的OPENID个数,最大值为10000

                String count = resultObj.getString("count");

                // 拉取列表的后一个用户的OPENID

                // String next_openid =resultObj.getString("next_openid ");

                // 列表数据,OPENID的列表

                JSONObject openIdObject = (JSONObject) resultObj.get("data");

                // 获得所有用户的openid

                openIdArry = new JSONArray();

                openIdArry = (JSONArray) openIdObject.get(WXConst.FIELD_SQL_OPENID);

            } else {

                // 请求成功返回失败的消息

                System.out.println(Messages.get("get_weChatUser_list_fail") + result);

            }

        } catch (Exception e) {

            e.printStackTrace();

        }

        return openIdArry;

    }

转载于:https://www.cnblogs.com/xunfang123/p/4196189.html