kaiyu
2020-09-15 68294b3a156d2c0573c04f1ac43940a55e397269
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.moral.service.impl;
 
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.moral.service.WebTokenService;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service;
 
import java.util.Date;
 
@Service
public class WebTokenServiceImpl implements WebTokenService {
    public final static String SECRET = "QXPC_Screen_B/S";
    @Override
    public String getToken(String id) {
        String token="";
        token= JWT.create()
                .withIssuer("qxpc")//发布者
                .withIssuedAt(new Date())//生成时间
                .withExpiresAt(DateUtils.addHours(new Date(),1))//有效时间
                .withClaim("aid",id)//存放数据
                .sign(Algorithm.HMAC256(SECRET));
        return token;
    }
}