微信获取个人信息并进行整理

前言

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;
}





如果满意,请打赏博主任意金额,感兴趣的在微信转账的时候,添加博主微信哦, 请下方留言吧。可与博主自由讨论哦

支付包 微信 微信公众号
支付宝 微信 微信公众号
posted @ 2018-09-10 11:15  HealerJean  阅读(433)  评论(0编辑  收藏  举报