微信获取个人信息并进行整理
前言
Github:https://github.com/HealerJean
1、注意点
1、Name有可能是表情
WeChatUserInfo resultWeChatUserInfo = JsonUtils.toObject(EmojiParser.parseToAliases( result),WeChatUserInfo.class);
2、订阅时间是一个long类型的数据
Date subscribeTime =new Date(JSONObject.fromObject(result).getLong("subscribe_time")*1000);
3、tagList 是一个字符串数组(这里我将它变成一个带有逗号的字符串)
String tag = JSONObject.fromObject(result).get("tagid_list").toString();
String tagList = tag.substring(tag.indexOf("[")+1, tag.indexOf("]"));
/**
* 获取微信用户基本信息
*/
@Override
public WeChatUserInfo getUserInfoByOpenId(String openId, WeChatBusinessNo weChatBusinessNo) {
String url = WechatApiUrlParams.USER_GET_USER_INFO;
String access_token = AccessToakeUtil.getAccessToaken(weChatBusinessNo);
String requestUrl = url.replace("ACCESS_TOKEN", access_token).replace("OPENID", openId);
HttpBackBean httpBackBean = SdkHttpHelper.handleGet(requestUrl,null,null,SdkHttpHelper.OVERTIME);
String result = httpBackBean.getResult();
log.info(result);
WeChatUserInfo resultWeChatUserInfo = JsonUtils.toObject(EmojiParser.parseToAliases( result),WeChatUserInfo.class);
String tag = JSONObject.fromObject(result).get("tagid_list").toString();
String tagList = tag.substring(tag.indexOf("[")+1, tag.indexOf("]"));
Date subscribeTime =new Date(JSONObject.fromObject(result).getLong("subscribe_time")*1000);
log.info("订阅时间"+ DateHelper.convertDate2String(subscribeTime)+"openId"+resultWeChatUserInfo.getOpenId());
resultWeChatUserInfo.setTagidList(tagList);
resultWeChatUserInfo.setSubscribeTime(subscribeTime);
return resultWeChatUserInfo;
}