package com.walker.web; import com.walker.web.token.JwtTokenGenerator; import com.walker.web.util.IdUtils; import com.walker.web.util.IpUtils; import com.walker.web.util.Location; import org.junit.Test; import org.springframework.web.client.RestTemplate; public class TokenTest { private static final String TOKEN_SECRET = "zbc_mike_@2022"; // @Test public void testUid(){ System.out.println(IdUtils.fastSimpleUUID()); } // @Test public void testLocationIp(){ String ip = "221.15.155.4"; RestTemplate restTemplate = new RestTemplate(); Location location = IpUtils.getLocationAli(ip, restTemplate); if(location != null){ System.out.println(location); } else { System.out.println("未查询到归属地"); } } // @Test public void testCreateToken(){ TokenGenerator tokenGenerator = new JwtTokenGenerator(); // String token = tokenGenerator.createToken("userId:123456789", 3, TOKEN_SECRET); String token = tokenGenerator.createToken("test_key", "1", 30, TOKEN_SECRET); System.out.println("token = " + token); } // @Test public void testValidateTokenn(){ // String token = "eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJ3YWxrZXJzb2Z0IiwiaWF0IjoxNjY1MzkxNDIyLCJzdWIiOiJ1c2VySWQ6MTIzNDU2Nzg5IiwiZXhwIjoxNjY1MzkxNjAyfQ.sLoS0K4Qz4KSAO0icTrQo3L4rt17TBjIWiQld5hscsWkY1oxdM7qJucxAlP9D1up2Mrbnq1zU5M2OIfhbX_2uA"; String token = "eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJ3YWxrZXJzb2Z0IiwiaWF0IjoxNjY3MzA1NDQyLCJsb2dpbl91c2VyX2tleSI6InRlc3Rfa2V5IiwidXNlcl9pZF9rZXkiOiJ1c2VySWQ6MTIzNDU2Nzg5IiwiZXhwIjoxNjY3MzA1NjIyfQ.i365flYgaDXC9AucYebG_GqNua56ugVUatxlM5P0w7PsgQgHxoWF0S8P40qL-b8Phqnf-ZX0Caqx1xLwfUF_qA"; TokenGenerator tokenGenerator = new JwtTokenGenerator(); try{ String data = tokenGenerator.validateToken(token, TOKEN_SECRET); System.out.println("data = " + data); } catch (TokenException ex){ ex.printStackTrace(); System.out.println(ex.getTitle()); } } }