SnsAccessTokenBean.java 2.36 KB
package com.server.utils.weixin.bean;

import com.alibaba.fastjson.JSON;
import com.server.utils.weixin.ReturnCode;

import java.util.Map;

/**
 * Created by dell on 2018/2/28.
 */
public class SnsAccessTokenBean {

    private String access_token;
    private Integer expires_in;
    private String refresh_token;
    private String openid;
    private String scope;
    private String unionid;
    private Integer errcode;
    private String errmsg;
    private Long expiredTime;
    private String json;

    public SnsAccessTokenBean(String jsonStr) {
        this.json = jsonStr;

        try {
            Map e = (Map) JSON.parseObject(jsonStr, Map.class);
            this.access_token = (String)e.get("access_token");
            this.expires_in = this.getInt(e, "expires_in");
            this.refresh_token = (String)e.get("refresh_token");
            this.openid = (String)e.get("openid");
            this.unionid = (String)e.get("unionid");
            this.scope = (String)e.get("scope");
            this.errcode = this.getInt(e, "errcode");
            this.errmsg = (String)e.get("errmsg");
            if(this.expires_in != null) {
                this.expiredTime = Long.valueOf(System.currentTimeMillis() + (long)((this.expires_in.intValue() - 5) * 1000));
            }

        } catch (Exception var3) {
            throw new RuntimeException(var3);
        }
    }

    public String getJson() {
        return this.json;
    }

    private Integer getInt(Map<String, Object> temp, String key) {
        Number number = (Number)temp.get(key);
        return number == null?null:Integer.valueOf(number.intValue());
    }

    public String getAccessToken() {
        return this.access_token;
    }

    public Integer getExpiresIn() {
        return this.expires_in;
    }

    public String getRefresh_token() {
        return this.refresh_token;
    }

    public String getOpenid() {
        return this.openid;
    }

    public String getScope() {
        return this.scope;
    }

    public Integer getErrorCode() {
        return this.errcode;
    }

    public String getErrorMsg() {
        if(this.errcode != null) {
            String result = ReturnCode.get(this.errcode.intValue());
            if(result != null) {
                return result;
            }
        }
        return this.errmsg;
    }

    public String getUnionid() {
        return this.unionid;
    }

}