Esempio n. 1
0
 /**
  * 获取用户信息
  *
  * @param accessToken 接口访问凭证
  * @param openId 用户标识
  * @return WeixinUserInfo
  */
 public static RecevieUserInfo getUserInfo(String accessToken, String openId) {
   // 拼接请求地址
   String requestUrl =
       "https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID";
   requestUrl = requestUrl.replace("ACCESS_TOKEN", accessToken).replace("OPENID", openId);
   // 获取用户信息
   try {
     String jsonStr = ToolHttp.get(true, requestUrl);
     RecevieUserInfo weixinUserInfo = JSONObject.parseObject(jsonStr, RecevieUserInfo.class);
     return weixinUserInfo;
   } catch (Exception e) {
     log.error("ToolUser.getUserInfo获取用户信息异常,accessToken:" + accessToken + " openId:" + openId);
     return null;
   }
 }
Esempio n. 2
0
 /**
  * 获取关注者列表
  *
  * @param accessToken 调用接口凭证
  * @param nextOpenId 第一个拉取的openId,不填默认从头开始拉取
  * @return WeixinUserList
  */
 public static RecevieUserList getUserList(String accessToken, String nextOpenId) {
   if (null == nextOpenId) {
     nextOpenId = "";
   }
   // 拼接请求地址
   String requestUrl =
       "https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID";
   requestUrl = requestUrl.replace("ACCESS_TOKEN", accessToken).replace("NEXT_OPENID", nextOpenId);
   // 获取关注者列表
   try {
     String jsonStr = ToolHttp.get(true, requestUrl);
     RecevieUserList weixinUserList = JSONObject.parseObject(jsonStr, RecevieUserList.class);
     return weixinUserList;
   } catch (Exception e) {
     log.error(
         "ToolUser.getUserInfo获取用户信息异常,accessToken:" + accessToken + " nextOpenId:" + nextOpenId);
     return null;
   }
 }