package com.sjyt.icom.asst.service;

import com.sjyt.icom.asst.common.model.message.VerifyClaims;
import com.sjyt.icom.asst.common.util.FuncUtils;
import com.sjyt.icom.asst.common.util.JjwtUtil;
import org.junit.Test;

/**
 * <p>TODO</p>
 *
 * @author renyanru
 * @version V1.0.0
 * @date 2022/6/28 16:29
 */
public class TestJjwt {
    @Test
    public void test1() {
        // jwt所面向的用户，放登录的用户名等
        //String subject = JSON.toJSONString(user);
        try {
            VerifyClaims verifyClaims = VerifyClaims.builder().from("1541677765097558016").rid("7kwaBAqAGxLE9wk6VbkzfVpgQkfy2BxCzSMQ5J2HjHT").roomCode("1").build();
            String jwt = JjwtUtil.createJWT(null, verifyClaims);
            System.out.println("JWT：" + jwt);
            System.out.println("JWT长度：" + jwt.length());
            System.out.println("\njwt三个组成部分中间payload部分的解密：");
            final VerifyClaims claims = JjwtUtil.getClaims(jwt);
            System.out.println("用户名：" + claims.getFrom());
            System.out.println("房间号：" + claims.getRid());
            System.out.println("房间码：" + claims.getRoomCode());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test2(){
        VerifyClaims verifyClaims1 = VerifyClaims.builder().from("1541677765097558016").rid("7kwaBAqAGxLE9wk6VbkzfVpgQkfy2BxCzSMQ5J2HjHT").roomCode("1").build();
        System.out.println(FuncUtils.checkObjFieldIsNullAndBlank(verifyClaims1,null));
        VerifyClaims verifyClaims2 = VerifyClaims.builder().from("1541677765097558016").rid("7kwaBAqAGxLE9wk6VbkzfVpgQkfy2BxCzSMQ5J2HjHT").build();
        System.out.println(FuncUtils.checkObjFieldIsNullAndBlank(verifyClaims2,null));
    }
}
