Пример #1
0
 /**
  * 请求信的access token http请求方式: GET
  * https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
  * {"access_token":"ACCESS_TOKEN","expires_in":7200} {"errcode":40013,"errmsg":"invalid appid"}
  */
 public boolean request() {
   String url = accessTokenUrl();
   String result = HttpUtils.get(url);
   if (StringUtils.isBlank(result)) return false;
   if (!parseData(result)) {
     return false;
   }
   logger.info("token获取成功");
   return true;
 }
Пример #2
0
 /**
  * 获取帐号的关注者列表
  *
  * @param nextOpenId
  * @return
  */
 public Follwers subscriberList(String nextOpenId) {
   String url = USRE_GET_URL + accessToken;
   if (StringUtils.isNotBlank(nextOpenId)) {
     url += "&next_openid=" + nextOpenId;
   }
   String resultStr = HttpUtils.get(url);
   logger.info("return data " + resultStr);
   try {
     WeChatUtil.isSuccess(resultStr);
   } catch (WeChatException e) {
     logger.error(e.getMessage());
     e.printStackTrace();
     return null;
   }
   return JSONObject.parseObject(resultStr, Follwers.class);
 }
Пример #3
0
 /**
  * 获取用户基本信息
  *
  * @param openid 普通用户的标识,对当前公众号唯一
  * @param lang 返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语
  * @return
  */
 public User getUserInfo(String openId, LanguageType lang) {
   String url = USER_INFO_GET_URL + this.accessToken + "&openid=" + openId;
   if (lang != null) {
     url += "&lang=" + lang.name();
   }
   String resultStr = HttpUtils.get(url);
   logger.info("return data " + resultStr);
   try {
     WeChatUtil.isSuccess(resultStr);
   } catch (WeChatException e) {
     logger.error(e.getMessage());
     e.printStackTrace();
     return null;
   }
   User user = JSONObject.parseObject(resultStr, User.class);
   return user;
 }