package com.ozs.da.utils;

import com.ozs.da.entity.token.Token;
import org.springframework.util.StringUtils;

/**
 * token解析工具类
 *
 * @author 许明
 * on 2019/3/5.
 * @version 2.0.0
 */
public final class TokenUtil {


    /**
     * 解析Token 字符串
     *
     * @param token token字符串
     * @return token token对象
     * @throws Exception
     */
    public static Token parseTokenStr(String token) throws Exception {
        if (StringUtils.isEmpty(token)) {
            throw new Exception("令牌为空！");
        }
        String tokenJsonStr = AesUtil.decrypt(token,
                CommonConfUtil.getConf("aes.key"),
                CommonConfUtil.getConf("aes.iv"));
        return JsonUtil.fromJson(tokenJsonStr, Token.class);
    }

}
