package com.tiesheng.platform.config.wxmp.bean;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;

/**
 * @author hao
 */
public class WxUserInfo {

    private String accessToken;
    private String nickname;
    private String sex;
    private String province;
    private String city;
    private String country;
    private String headimgurl;
    private String openid;
    private String appId;

    ///////////////////////////////////////////////////////////////////////////
    // 逻辑方法
    ///////////////////////////////////////////////////////////////////////////


    /**
     * 通过oAuth2AccessToken获取用户信息
     *
     * @param oAuth2AccessToken
     * @return
     */
    public static WxUserInfo create(WxOAuth2AccessToken oAuth2AccessToken) {
        String s = HttpUtil.get("https://api.weixin.qq.com/sns/userinfo"
                + "?access_token=" + oAuth2AccessToken.getAccessToken()
                + "&openid=" + oAuth2AccessToken.getOpenid() + "&lang=zh_CN");
        return JSONUtil.toBean(s, WxUserInfo.class);
    }


    ///////////////////////////////////////////////////////////////////////////
    // setter\getter
    ///////////////////////////////////////////////////////////////////////////

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getHeadimgurl() {
        return headimgurl;
    }

    public void setHeadimgurl(String headimgurl) {
        this.headimgurl = headimgurl;
    }

    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }
}
