package org.sxkj.resource.util;
|
|
|
import com.auth0.jwt.JWT;
|
import com.auth0.jwt.algorithms.Algorithm;
|
|
import java.util.Map;
|
|
public class OnlyofficeJwt {
|
|
/**
|
* 把jsonObject返回给前端使用
|
* @return
|
*/
|
public static Map<String, Object> getToken(Map<String, Object> config){
|
String tokenSecret = "ztzf-aisky-kx5xo-dx2w2-xpx5q";
|
String token = "";
|
try {
|
// Signer signer = HMACSigner.newSHA256Signer(tokenSecret);
|
// JWT jwt = new JWT();
|
// for (String key : payloadClaims.keySet()) {
|
// jwt.addClaim(key, payloadClaims.get(key));
|
// }
|
// token = JWT.getEncoder().encode(jwt, signer);
|
|
Algorithm algorithm = Algorithm.HMAC256(tokenSecret);
|
// Calendar calendar = Calendar.getInstance();
|
// Instant issuedAt = calendar.toInstant();
|
// calendar.add(12, 5);
|
// Instant expiresAt = calendar.toInstant();
|
// token = JWT.create().withIssuedAt(issuedAt).withExpiresAt(expiresAt).withPayload(payloadClaims).sign(algorithm);
|
|
token = JWT.create()
|
.withPayload(config)
|
.sign(algorithm);
|
} catch (Exception e) {
|
token = "";
|
}
|
config.put("token", token);
|
return config;
|
}
|
}
|