AuthDiag.java 1.5 KB

12345678910111213141516171819202122232425262728293031
  1. import cn.yoshop.common.auth.LoginInfo;
  2. import cn.yoshop.common.auth.PhpUnserializer;
  3. import cn.yoshop.common.auth.ThinkFileCacheTokenStore;
  4. import java.lang.reflect.Field;
  5. import java.nio.file.Files;
  6. import java.nio.file.Path;
  7. public class AuthDiag {
  8. public static void main(String[] args) throws Exception {
  9. Path p = Path.of("F:/shop/java-rewrite/test-runtime/cache/a9/3029ed2d7a32cb7772b841e3c3a68a.php");
  10. byte[] content = Files.readAllBytes(p);
  11. System.out.println("file len = " + content.length);
  12. System.out.println("head32 = " + new String(content, 0, 32, java.nio.charset.StandardCharsets.UTF_8).replace("\n", "\\n"));
  13. byte[] serialized = new byte[content.length - 32];
  14. System.arraycopy(content, 32, serialized, 0, serialized.length);
  15. try {
  16. Object o = PhpUnserializer.parse(serialized);
  17. System.out.println("parse OK: " + o);
  18. } catch (Exception e) {
  19. System.out.println("parse FAIL: " + e);
  20. e.printStackTrace();
  21. }
  22. ThinkFileCacheTokenStore store = new ThinkFileCacheTokenStore();
  23. Field f = ThinkFileCacheTokenStore.class.getDeclaredField("cachePath");
  24. f.setAccessible(true);
  25. f.set(store, "F:/shop/java-rewrite/test-runtime/cache");
  26. LoginInfo info = store.getLoginInfo("testtoken123");
  27. System.out.println("token resolve: " + (info == null ? "null" : "storeId=" + info.getStoreId() + " login=" + info.isLogin() + " userId=" + info.getStoreUserId()));
  28. }
  29. }