package org.springblade.openapi.wps.util;

import io.jsonwebtoken.Claims;
import org.springblade.core.launch.constant.TokenConstant;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.openapi.wps.pojo.vo.Api4WpsUserVO;

/**
 * @author bfhuange
 * @date 2024/10/30
 */
public class TokenUtils {

    /**
     *  获取wps需要的用户信息
     * @param token
     * @return
     */
    public static Api4WpsUserVO getWpsUser(String token) {
        if (StringUtil.isBlank(token)) {
            return null;
        }
        Claims claims = AuthUtil.parseJWT(token);
        if (claims == null) {
            return null;
        }
        String userId = Func.toStr(claims.get(TokenConstant.USER_ID));
        String nickName = Func.toStr(claims.get(TokenConstant.NICK_NAME));
        return new Api4WpsUserVO(userId, nickName);
    }
}
