package thyyxxk.webserver.service;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import org.springframework.stereotype.Service;
import thyyxxk.webserver.entity.login.UserInfo;

import java.util.Date;

/**
 * @author dj
 */
@Service("TokenService")
public class TokenService {
    public String getToken(UserInfo userInfo) {
        Date start = new Date();
        long expireTimeStamp = System.currentTimeMillis() + 60 * 60 * 1000 * 24;
        Date expireTime = new Date(expireTimeStamp);
        return JWT.create()
                .withAudience(userInfo.getCode())
                .withIssuedAt(start)
                .withExpiresAt(expireTime)
                .sign(Algorithm.HMAC256(userInfo.getPassword()));
    }
}
