package cn.iselab.mooctest.user.configure;

import cn.iselab.mooctest.user.data.Token;
import cn.iselab.mooctest.user.util.WechatUtil;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.Hashtable;
import java.util.logging.Logger;

/**
 * @Author ROKG
 * @Description
 * @Date: Created in 下午4:35 2018/4/2
 * @Modified By:
 */
@ConfigurationProperties(prefix="wechat")
@Component
public class WechatConfiguration {
    private String appId;

    private String appSecret;

    private Token token;

    public String getAppId() {
        return appId;
    }

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

    public String getAppSecret() {
        return appSecret;
    }

    public void setAppSecret(String appSecret) {
        this.appSecret = appSecret;
    }

    public Token getToken(String code) {
        if (appId != null && appSecret != null) {
            token = WechatUtil.getToken(appId, appSecret, code);
        }
        return token;
    }

    public void setToken(Token token) {
        this.token = token;
    }
}
