From c8dffd157cd8b62023b26e62a0b92c152d959423 Mon Sep 17 00:00:00 2001
From: Codex Assistant <codex@example.com>
Date: 星期三, 08 十月 2025 21:19:28 +0800
Subject: [PATCH] build(backend): switch to thin-jar layout (split libs into target/lib); chore: remove test-* files; misc updates
---
backend/src/main/java/com/rongyichuang/auth/util/JwtUtil.java | 36 ++++++++++++++++++++++++++++++------
1 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/backend/src/main/java/com/rongyichuang/auth/util/JwtUtil.java b/backend/src/main/java/com/rongyichuang/auth/util/JwtUtil.java
index 91b828e..489d0f8 100644
--- a/backend/src/main/java/com/rongyichuang/auth/util/JwtUtil.java
+++ b/backend/src/main/java/com/rongyichuang/auth/util/JwtUtil.java
@@ -25,21 +25,37 @@
private long jwtExpiration;
/**
- * 鐢熸垚JWT token
+ * 鐢熸垚JWT token锛堟棫鐗堟湰锛屼繚鎸佸吋瀹规�э級
*/
public String generateToken(Long userId, String phone) {
+ return generateToken(userId, phone, null);
+ }
+
+ /**
+ * 鐢熸垚JWT token锛堟柊鐗堟湰锛屾敮鎸亀xopenid锛�
+ */
+ public String generateToken(Long userId, String phone, String wxopenid) {
Date now = new Date();
Date expiryDate = new Date(now.getTime() + jwtExpiration);
SecretKey key = Keys.hmacShaKeyFor(jwtSecret.getBytes());
- return Jwts.builder()
+ JwtBuilder builder = Jwts.builder()
.setSubject(userId.toString())
- .claim("phone", phone)
.setIssuedAt(now)
- .setExpiration(expiryDate)
- .signWith(key, SignatureAlgorithm.HS256)
- .compact();
+ .setExpiration(expiryDate);
+
+ // 鍙湁褰損hone涓嶄负null鏃舵墠娣诲姞phone claim
+ if (phone != null) {
+ builder.claim("phone", phone);
+ }
+
+ // 鍙湁褰搘xopenid涓嶄负null鏃舵墠娣诲姞wxopenid claim
+ if (wxopenid != null) {
+ builder.claim("wxopenid", wxopenid);
+ }
+
+ return builder.signWith(key, SignatureAlgorithm.HS256).compact();
}
/**
@@ -59,6 +75,14 @@
}
/**
+ * 浠巘oken涓幏鍙栧井淇penid
+ */
+ public String getWxOpenidFromToken(String token) {
+ Claims claims = getClaimsFromToken(token);
+ return claims.get("wxopenid", String.class);
+ }
+
+ /**
* 楠岃瘉token鏄惁鏈夋晥
*/
public boolean validateToken(String token) {
--
Gitblit v1.8.0