Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-communication
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-communication
Commits
6cccf32b
Commit
6cccf32b
authored
Oct 12, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into prod
parents
1250fdf1
f88f8c46
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
652 additions
and
5 deletions
+652
-5
yd-communication-api/src/main/java/com/yd/communication/api/controller/ApiCoSessionController.java
+48
-0
yd-communication-api/src/main/java/com/yd/communication/api/service/ApiCoSessionService.java
+10
-0
yd-communication-api/src/main/java/com/yd/communication/api/service/impl/ApiCoSessionServiceImpl.java
+0
-0
yd-communication-feign/src/main/java/com/yd/communication/feign/client/ApiCoSessionFeignClient.java
+44
-0
yd-communication-feign/src/main/java/com/yd/communication/feign/dto/RoomLinkDTO.java
+21
-0
yd-communication-feign/src/main/java/com/yd/communication/feign/enums/RedisEnum.java
+2
-1
yd-communication-feign/src/main/java/com/yd/communication/feign/fallback/ApiCoSessionFeignFallbackFactory.java
+22
-0
yd-communication-feign/src/main/java/com/yd/communication/feign/request/SetLinkFailureRequest.java
+11
-0
yd-communication-feign/src/main/java/com/yd/communication/feign/response/GetLinkStatusResponse.java
+18
-0
yd-communication-feign/src/main/java/com/yd/communication/feign/response/JoinResponse.java
+6
-0
yd-communication-feign/src/main/java/com/yd/communication/feign/response/SetLinkFailureResponse.java
+12
-0
yd-communication-feign/src/main/java/com/yd/communication/feign/response/http/QuerySfpUserResponse.java
+46
-0
yd-communication-service/src/main/java/com/yd/communication/service/utils/CffpTokenUtil.java
+207
-0
yd-communication-service/src/main/java/com/yd/communication/service/utils/MyBatisPlusCodeGenerator.java
+4
-4
yd-communication-service/src/main/java/com/yd/communication/service/utils/SfpTokenUtil.java
+201
-0
No files found.
yd-communication-api/src/main/java/com/yd/communication/api/controller/ApiCoSessionController.java
View file @
6cccf32b
...
@@ -8,6 +8,7 @@ import com.yd.communication.feign.response.*;
...
@@ -8,6 +8,7 @@ import com.yd.communication.feign.response.*;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
/**
/**
...
@@ -44,6 +45,53 @@ public class ApiCoSessionController implements ApiCoSessionFeignClient {
...
@@ -44,6 +45,53 @@ public class ApiCoSessionController implements ApiCoSessionFeignClient {
}
}
/**
/**
* 根据房间号和密码获取会话详情
*
* @param roomId 房间号
* @param roomPwd 房间密码
* @return 完整会话信息
*/
@Override
public
Result
<
SessionDetailResponse
>
get
(
String
roomId
,
String
roomPwd
)
{
return
apiCoSessionService
.
get
(
roomId
,
roomPwd
);
}
/**
* 获取房间链接状态信息
*
* @param roomId 房间号
* @param roomPwd 房间密码
* @return
*/
@Override
public
Result
<
GetLinkStatusResponse
>
getLinkStatus
(
String
roomId
,
String
roomPwd
)
{
return
apiCoSessionService
.
getLinkStatus
(
roomId
,
roomPwd
);
}
/**
* 设置房间链接状态为失效
*
* @param request 加入会话请求
* @return 会话详情
*/
@Override
public
Result
<
SetLinkFailureResponse
>
setLinkFailure
(
SetLinkFailureRequest
request
)
{
return
apiCoSessionService
.
setLinkFailure
(
request
);
}
/**
* 判断资源创建者和参与者是否是同一个人(供参与者调用)
*
* @param roomId 房间号
* @param roomPwd 房间密码
* @return true-是同一人 false-不是同一人
*/
@Override
public
Result
<
Boolean
>
isMy
(
String
roomId
,
String
roomPwd
,
HttpServletRequest
httpRequest
)
{
return
apiCoSessionService
.
isMy
(
roomId
,
roomPwd
,
httpRequest
);
}
/**
* 获取会话状态
* 获取会话状态
* @param request
* @param request
* @return
* @return
...
...
yd-communication-api/src/main/java/com/yd/communication/api/service/ApiCoSessionService.java
View file @
6cccf32b
...
@@ -6,6 +6,8 @@ import com.yd.communication.feign.request.*;
...
@@ -6,6 +6,8 @@ import com.yd.communication.feign.request.*;
import
com.yd.communication.feign.response.*
;
import
com.yd.communication.feign.response.*
;
import
com.yd.communication.service.model.CoSession
;
import
com.yd.communication.service.model.CoSession
;
import
javax.servlet.http.HttpServletRequest
;
public
interface
ApiCoSessionService
{
public
interface
ApiCoSessionService
{
...
@@ -26,4 +28,12 @@ public interface ApiCoSessionService {
...
@@ -26,4 +28,12 @@ public interface ApiCoSessionService {
void
updateCurrentPage
(
String
roomId
,
String
newPageJson
,
String
operatorId
);
void
updateCurrentPage
(
String
roomId
,
String
newPageJson
,
String
operatorId
);
CoSession
getByRoomId
(
String
roomId
);
CoSession
getByRoomId
(
String
roomId
);
Result
<
SessionDetailResponse
>
get
(
String
roomId
,
String
roomPwd
);
Result
<
GetLinkStatusResponse
>
getLinkStatus
(
String
roomId
,
String
roomPwd
);
Result
<
SetLinkFailureResponse
>
setLinkFailure
(
SetLinkFailureRequest
request
);
Result
<
Boolean
>
isMy
(
String
roomId
,
String
roomPwd
,
HttpServletRequest
httpRequest
);
}
}
yd-communication-api/src/main/java/com/yd/communication/api/service/impl/ApiCoSessionServiceImpl.java
View file @
6cccf32b
This diff is collapsed.
Click to expand it.
yd-communication-feign/src/main/java/com/yd/communication/feign/client/ApiCoSessionFeignClient.java
View file @
6cccf32b
...
@@ -7,6 +7,7 @@ import com.yd.communication.feign.response.*;
...
@@ -7,6 +7,7 @@ import com.yd.communication.feign.response.*;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
/**
/**
...
@@ -37,6 +38,49 @@ public interface ApiCoSessionFeignClient {
...
@@ -37,6 +38,49 @@ public interface ApiCoSessionFeignClient {
Result
<
JoinResponse
>
join
(
@Validated
@RequestBody
JoinRequest
request
);
Result
<
JoinResponse
>
join
(
@Validated
@RequestBody
JoinRequest
request
);
/**
/**
* 根据房间号和密码获取会话详情
*
* @param roomId 房间号
* @param roomPwd 房间密码
* @return 完整会话信息
*/
@GetMapping
(
"/detail/roomIdAndPwd"
)
Result
<
SessionDetailResponse
>
get
(
@RequestParam
(
"roomId"
)
String
roomId
,
@RequestParam
(
"roomPwd"
)
String
roomPwd
);
/**
* 获取房间链接状态信息
*
* @param roomId 房间号
* @param roomPwd 房间密码
* @return
*/
@GetMapping
(
"/link/status"
)
Result
<
GetLinkStatusResponse
>
getLinkStatus
(
@RequestParam
(
"roomId"
)
String
roomId
,
@RequestParam
(
"roomPwd"
)
String
roomPwd
);
/**
* 设置房间链接状态为失效
*
* @param request 加入会话请求
* @return 会话详情
*/
@PostMapping
(
"/set/link/failure"
)
Result
<
SetLinkFailureResponse
>
setLinkFailure
(
@Validated
@RequestBody
SetLinkFailureRequest
request
);
/**
* 判断资源创建者和参与者是否是同一个人(供参与者调用)
*
* @param roomId 房间号
* @param roomPwd 房间密码
* @return true-是同一人 false-不是同一人
*/
@GetMapping
(
"/isMy"
)
Result
<
Boolean
>
isMy
(
@RequestParam
(
"roomId"
)
String
roomId
,
@RequestParam
(
"roomPwd"
)
String
roomPwd
,
HttpServletRequest
httpRequest
);
/**
* 获取会话状态
* 获取会话状态
* @param request
* @param request
* @return
* @return
...
...
yd-communication-feign/src/main/java/com/yd/communication/feign/dto/RoomLinkDTO.java
0 → 100644
View file @
6cccf32b
package
com
.
yd
.
communication
.
feign
.
dto
;
import
lombok.Data
;
import
java.io.Serializable
;
@Data
public
class
RoomLinkDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 纯链接
*/
private
String
roomLink
;
/**
* 二维码里面的链接
*/
private
String
qrCodeRoomLink
;
}
yd-communication-feign/src/main/java/com/yd/communication/feign/enums/RedisEnum.java
View file @
6cccf32b
...
@@ -10,9 +10,10 @@ import java.util.concurrent.TimeUnit;
...
@@ -10,9 +10,10 @@ import java.util.concurrent.TimeUnit;
public
enum
RedisEnum
{
public
enum
RedisEnum
{
//协同房间缓存信息redis参数
//协同房间缓存信息redis参数
ROOM
(
RedisConstants
.
ROOM_KEY_PREFIX
,
1
20
,
TimeUnit
.
MINUTE
S
),
ROOM
(
RedisConstants
.
ROOM_KEY_PREFIX
,
1
,
TimeUnit
.
DAY
S
),
//房间链接缓存信息redis参数
//房间链接缓存信息redis参数
ROOM_LINK
(
RedisConstants
.
ROOM_LINK_KEY_PREFIX
,
120
,
TimeUnit
.
MINUTES
),
ROOM_LINK
(
RedisConstants
.
ROOM_LINK_KEY_PREFIX
,
120
,
TimeUnit
.
MINUTES
),
//code置换资源创建者token的缓存信息
;
;
//缓存key前缀
//缓存key前缀
...
...
yd-communication-feign/src/main/java/com/yd/communication/feign/fallback/ApiCoSessionFeignFallbackFactory.java
View file @
6cccf32b
...
@@ -8,6 +8,8 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -8,6 +8,8 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.cloud.openfeign.FallbackFactory
;
import
org.springframework.cloud.openfeign.FallbackFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.http.HttpServletRequest
;
/**
/**
* 通信服务-协同会话信息Feign降级处理
* 通信服务-协同会话信息Feign降级处理
*/
*/
...
@@ -24,6 +26,26 @@ public class ApiCoSessionFeignFallbackFactory implements FallbackFactory<ApiCoSe
...
@@ -24,6 +26,26 @@ public class ApiCoSessionFeignFallbackFactory implements FallbackFactory<ApiCoSe
}
}
@Override
@Override
public
Result
<
SessionDetailResponse
>
get
(
String
roomId
,
String
roomPwd
)
{
return
null
;
}
@Override
public
Result
<
GetLinkStatusResponse
>
getLinkStatus
(
String
roomId
,
String
roomPwd
)
{
return
null
;
}
@Override
public
Result
<
SetLinkFailureResponse
>
setLinkFailure
(
SetLinkFailureRequest
request
)
{
return
null
;
}
@Override
public
Result
<
Boolean
>
isMy
(
String
roomId
,
String
roomPwd
,
HttpServletRequest
httpRequest
)
{
return
null
;
}
@Override
public
Result
<
JoinResponse
>
join
(
JoinRequest
request
)
{
public
Result
<
JoinResponse
>
join
(
JoinRequest
request
)
{
return
null
;
return
null
;
}
}
...
...
yd-communication-feign/src/main/java/com/yd/communication/feign/request/SetLinkFailureRequest.java
0 → 100644
View file @
6cccf32b
package
com
.
yd
.
communication
.
feign
.
request
;
import
lombok.Data
;
@Data
public
class
SetLinkFailureRequest
{
private
String
roomId
;
private
String
roomPwd
;
}
yd-communication-feign/src/main/java/com/yd/communication/feign/response/GetLinkStatusResponse.java
0 → 100644
View file @
6cccf32b
package
com
.
yd
.
communication
.
feign
.
response
;
import
lombok.Data
;
@Data
public
class
GetLinkStatusResponse
{
/**
* 报告归属人姓名
*/
private
String
reportOwnerName
;
/**
* 报告归属人手机号尾号四位
*/
private
String
reportOwnerMobileLast
;
}
yd-communication-feign/src/main/java/com/yd/communication/feign/response/JoinResponse.java
View file @
6cccf32b
...
@@ -57,4 +57,9 @@ public class JoinResponse {
...
@@ -57,4 +57,9 @@ public class JoinResponse {
* 手机号
* 手机号
*/
*/
private
String
mobile
;
private
String
mobile
;
/**
* 置换资源所有者token信息
*/
private
String
code
;
}
}
\ No newline at end of file
yd-communication-feign/src/main/java/com/yd/communication/feign/response/SetLinkFailureResponse.java
0 → 100644
View file @
6cccf32b
package
com
.
yd
.
communication
.
feign
.
response
;
import
lombok.Data
;
@Data
public
class
SetLinkFailureResponse
{
/**
* 报告归属人姓名
*/
private
String
reportOwnerName
;
}
yd-communication-feign/src/main/java/com/yd/communication/feign/response/http/QuerySfpUserResponse.java
0 → 100644
View file @
6cccf32b
package
com
.
yd
.
communication
.
feign
.
response
.
http
;
import
lombok.Data
;
import
java.util.Date
;
@Data
public
class
QuerySfpUserResponse
{
private
Long
id
;
//serial idPRIauto_increment
private
String
name
;
//userName
private
String
mobile
;
//手机号
private
Integer
gender
;
//性别,1,男,2,女
private
String
age
;
//年龄
private
String
manageMobile
;
//管理经纪人手机号(保单托管)
private
Date
loginDate
;
//登录时间(用于判断该用户是否登录过期 30天, 登录成功更新,退出或者切换账号更新)
private
Integer
loginState
;
//是否登录(0=No, 1=Yes)
private
String
customerSource
;
//客户来源
private
String
level
;
//用户等级
private
String
levelName
;
//用户等级名称
private
Integer
isVip
;
//是否vip
private
Date
vipExpireDate
;
//vip到期时间
private
Date
inactivateDate
;
//激活到期时间
private
Integer
remainingTimes
;
//剩余次数
private
Integer
isMax
;
//是否达到最大购买次数 0-否 1-是
private
Integer
userType
;
//用户类型
private
Long
roleId
;
//用户角色ID
private
String
systemType
;
//系统类型(tvm、sfp、policyManage)
private
String
tenantProjectRoleIds
;
//租户项目角色ID列表
private
String
flag
;
//标识
private
String
remark
;
//备注
private
String
wxNickname
;
//微信昵称
private
String
wxOpenId
;
//用户小程序登录的openid
private
String
wxOpenIdGzh
;
//用户公众号登录的openid
private
Integer
isBlacklist
;
//是否黑名单 0-否 1-是
private
Integer
isActive
;
//是否启用(0=No, 1=Yes)
private
Date
createdAt
;
//创建时间
private
String
createdBy
;
//创建人
private
Date
updatedAt
;
//修改时间
private
String
updatedBy
;
//修改人
/**
* 律家保-法税卡激活接口,请求⽅用户唯⼀识别号 (用于跳转到律家保页面的挂参)
*/
private
String
ljbRefId
;
}
yd-communication-service/src/main/java/com/yd/communication/service/utils/CffpTokenUtil.java
0 → 100644
View file @
6cccf32b
package
com
.
yd
.
communication
.
service
.
utils
;
import
io.jsonwebtoken.*
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* CFFP 项目专用 JWT Token 工具类
* 完全在代码内部获取环境标识(System.getProperty),硬编码不同环境的配置
* 支持生成 Token 和解析 Token(获取 userId、cffpUserId 等)
*
* @author yourname
*/
@Slf4j
@Service
public
class
CffpTokenUtil
{
// JWT 标准声明 Key
private
static
final
String
CLAIM_KEY_SUBJECT
=
"sub"
;
private
static
final
String
CLAIM_KEY_CREATED
=
"created"
;
// 自定义声明 Key(与 CffpTokenFilter 保持一致)
private
static
final
String
CLAIM_KEY_USERID
=
"UserId"
;
private
static
final
String
CLAIM_KEY_CFFP_USERID
=
"cffpUserId"
;
// 静态配置字段(一套配置,根据环境加载不同的值)
private
static
String
seal
;
private
static
String
issuer
;
private
static
Long
expiration
;
/**
* 初始化:通过 System.getProperty 获取环境,硬编码对应的配置
* 该方法在 Spring 容器启动完成后自动执行
*/
@PostConstruct
public
void
init
()
{
// 从系统属性中获取 spring.profiles.active,如果获取不到则默认为 "default"
String
activeProfile
=
System
.
getProperty
(
"spring.profiles.active"
,
"default"
);
// 判断是否为生产环境
boolean
isProd
=
"prod"
.
equalsIgnoreCase
(
activeProfile
)
||
"production"
.
equalsIgnoreCase
(
activeProfile
)
||
activeProfile
.
toLowerCase
().
contains
(
"prod"
);
if
(
isProd
)
{
// 生产环境配置
seal
=
"zhb123!@#"
;
issuer
=
"cffpwealthcenter"
;
expiration
=
2592000L
;
log
.
info
(
"CffpTokenUtil 加载生产环境配置, issuer: {}, expiration: {} 秒"
,
issuer
,
expiration
);
}
else
{
// 测试/开发环境配置
seal
=
"zhb123!@#"
;
issuer
=
"zuihuibi"
;
expiration
=
86400000L
;
log
.
info
(
"CffpTokenUtil 加载测试环境配置, issuer: {}, expiration: {} 秒"
,
issuer
,
expiration
);
}
}
// ======================== 生成 Token ========================
/**
* 生成 JWT Token(自动添加 issuer 前缀,如 "zuihuibi {token}")
*
* @param ticket 用户标识(通常为登录名或唯一标识)
* @param userId 用户 ID(字符串)
* @param cffpUserId CFFP 用户 ID(可选)
* @return 完整 Token 字符串(含前缀)
*/
public
static
String
generateToken
(
String
ticket
,
String
userId
,
String
cffpUserId
)
{
Map
<
String
,
Object
>
claims
=
new
HashMap
<>();
claims
.
put
(
CLAIM_KEY_SUBJECT
,
ticket
);
claims
.
put
(
CLAIM_KEY_USERID
,
userId
);
if
(
cffpUserId
!=
null
)
{
claims
.
put
(
CLAIM_KEY_CFFP_USERID
,
cffpUserId
);
}
claims
.
put
(
CLAIM_KEY_CREATED
,
new
Date
());
String
token
=
Jwts
.
builder
()
.
setClaims
(
claims
)
.
setExpiration
(
new
Date
(
System
.
currentTimeMillis
()
+
expiration
*
1000
))
.
signWith
(
SignatureAlgorithm
.
HS512
,
seal
)
.
compact
();
return
issuer
+
" "
+
token
;
}
// ======================== 解析 Token ========================
/**
* 从 Token 中解析 Claims
*
* @param token 原始 Token(可能包含 issuer 前缀)
* @return Map, key 包含 "resultCode"(SUCCESS/EXPIRED/INVALID)和 "claims"(解析成功时为 Claims 对象)
*/
public
static
Map
<
String
,
Object
>
getClaimsFromToken
(
String
token
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
String
resultCode
=
"SUCCESS"
;
Claims
claims
=
null
;
if
(
token
==
null
||
token
.
isEmpty
())
{
map
.
put
(
"resultCode"
,
"INVALID"
);
map
.
put
(
"claims"
,
null
);
return
map
;
}
try
{
// 去除 issuer 前缀(如果存在)
String
realToken
=
token
;
if
(
token
.
startsWith
(
issuer
+
" "
))
{
realToken
=
token
.
substring
(
issuer
.
length
()
+
1
);
}
Jws
<
Claims
>
jwsClaims
=
Jwts
.
parser
()
.
setSigningKey
(
seal
)
.
parseClaimsJws
(
realToken
);
claims
=
jwsClaims
.
getBody
();
}
catch
(
ExpiredJwtException
e
)
{
resultCode
=
"EXPIRED"
;
}
catch
(
UnsupportedJwtException
|
MalformedJwtException
|
SignatureException
|
IllegalArgumentException
e
)
{
resultCode
=
"INVALID"
;
}
catch
(
Exception
e
)
{
resultCode
=
"INVALID"
;
}
map
.
put
(
"resultCode"
,
resultCode
);
map
.
put
(
"claims"
,
claims
);
return
map
;
}
/**
* 从 Token 中获取用户 ID(String 形式)
*
* @param token 原始 Token
* @return 用户 ID 字符串,解析失败返回 null
*/
public
static
String
getUserIdFromToken
(
String
token
)
{
Map
<
String
,
Object
>
map
=
getClaimsFromToken
(
token
);
if
(
"SUCCESS"
.
equals
(
map
.
get
(
"resultCode"
)))
{
Claims
claims
=
(
Claims
)
map
.
get
(
"claims"
);
if
(
claims
!=
null
)
{
Object
userId
=
claims
.
get
(
CLAIM_KEY_USERID
);
return
userId
!=
null
?
userId
.
toString
()
:
null
;
}
}
return
null
;
}
/**
* 从 Token 中获取 CFFP 用户 ID
*
* @param token 原始 Token
* @return CFFP 用户 ID 字符串,解析失败返回 null
*/
public
static
String
getCffpUserIdFromToken
(
String
token
)
{
Map
<
String
,
Object
>
map
=
getClaimsFromToken
(
token
);
if
(
"SUCCESS"
.
equals
(
map
.
get
(
"resultCode"
)))
{
Claims
claims
=
(
Claims
)
map
.
get
(
"claims"
);
if
(
claims
!=
null
)
{
Object
cffpUserId
=
claims
.
get
(
CLAIM_KEY_CFFP_USERID
);
return
cffpUserId
!=
null
?
cffpUserId
.
toString
()
:
null
;
}
}
return
null
;
}
/**
* 验证 Token 是否有效(未过期、格式正确)
*
* @param token 原始 Token
* @return true 表示有效,false 表示无效或过期
*/
public
static
boolean
validateToken
(
String
token
)
{
Map
<
String
,
Object
>
map
=
getClaimsFromToken
(
token
);
return
"SUCCESS"
.
equals
(
map
.
get
(
"resultCode"
));
}
/**
* 检查 Token 是否过期
*
* @param token 原始 Token
* @return true 表示已过期,false 表示未过期或解析失败
*/
public
static
boolean
isTokenExpired
(
String
token
)
{
Map
<
String
,
Object
>
map
=
getClaimsFromToken
(
token
);
String
resultCode
=
(
String
)
map
.
get
(
"resultCode"
);
if
(
"EXPIRED"
.
equals
(
resultCode
))
{
return
true
;
}
if
(
"SUCCESS"
.
equals
(
resultCode
))
{
Claims
claims
=
(
Claims
)
map
.
get
(
"claims"
);
if
(
claims
!=
null
)
{
Date
expirationDate
=
claims
.
getExpiration
();
return
expirationDate
!=
null
&&
expirationDate
.
before
(
new
Date
());
}
}
return
false
;
}
}
\ No newline at end of file
yd-communication-service/src/main/java/com/yd/communication/service/utils/MyBatisPlusCodeGenerator.java
View file @
6cccf32b
...
@@ -5,11 +5,11 @@ import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
...
@@ -5,11 +5,11 @@ import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
public
class
MyBatisPlusCodeGenerator
{
public
class
MyBatisPlusCodeGenerator
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
FastAutoGenerator
.
create
(
"jdbc:mysql://139.224.145.34:3308/
yd_communication
?serverTimezone=GMT%2B8"
,
"root"
,
"Zxm7320017"
)
FastAutoGenerator
.
create
(
"jdbc:mysql://139.224.145.34:3308/
test
?serverTimezone=GMT%2B8"
,
"root"
,
"Zxm7320017"
)
.
globalConfig
(
builder
->
{
.
globalConfig
(
builder
->
{
builder
.
author
(
"zxm"
)
builder
.
author
(
"zxm"
)
//
.outputDir("src/main/java/com/yd/user/service");
.
outputDir
(
"src/main/java/com/yd/user/service"
);
.
outputDir
(
"D:/soft/ideaproject/v2/yd-communication/yd-communication-service/src/main/java"
);
//
.outputDir("D:/soft/ideaproject/v2/yd-communication/yd-communication-service/src/main/java");
})
})
.
packageConfig
(
builder
->
{
.
packageConfig
(
builder
->
{
builder
.
parent
(
"com.yd.communication.service"
)
builder
.
parent
(
"com.yd.communication.service"
)
...
@@ -21,7 +21,7 @@ public class MyBatisPlusCodeGenerator {
...
@@ -21,7 +21,7 @@ public class MyBatisPlusCodeGenerator {
})
})
.
strategyConfig
(
builder
->
{
.
strategyConfig
(
builder
->
{
builder
.
addInclude
(
builder
.
addInclude
(
"c
o_session"
,
"co_operation_log"
,
"recording_task"
,
"co_desensitization_rule
"
"c
lient_session
"
)
)
.
entityBuilder
()
.
entityBuilder
()
.
enableLombok
()
.
enableLombok
()
...
...
yd-communication-service/src/main/java/com/yd/communication/service/utils/SfpTokenUtil.java
0 → 100644
View file @
6cccf32b
package
com
.
yd
.
communication
.
service
.
utils
;
import
io.jsonwebtoken.*
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* SFP 项目专用 JWT Token 工具类
* 完全在代码内部获取环境标识(System.getProperty),硬编码不同环境的配置
* 支持生成 Token 和解析 Token(获取 userId、customerId 等)
*
* @author yourname
*/
@Slf4j
@Service
public
class
SfpTokenUtil
{
// JWT 标准声明 Key
private
static
final
String
CLAIM_KEY_SUBJECT
=
"sub"
;
private
static
final
String
CLAIM_KEY_CREATED
=
"created"
;
// 自定义声明 Key(与 JwtTokenUtil 保持一致)
private
static
final
String
CLAIM_KEY_USERID
=
"UserId"
;
private
static
final
String
CLAIM_KEY_CUSTOMERID
=
"CustomerId"
;
// 静态配置字段
private
static
String
seal
;
private
static
String
issuer
;
private
static
Long
expiration
;
/**
* 初始化:通过 System.getProperty 获取环境,硬编码对应的配置
* 该方法在 Spring 容器启动完成后自动执行
*/
@PostConstruct
public
void
init
()
{
// 从系统属性中获取 spring.profiles.active,如果获取不到则默认为 "default"
String
activeProfile
=
System
.
getProperty
(
"spring.profiles.active"
,
"default"
);
// 判断是否为生产环境(可自定义判断规则,如包含 "prod" 或 "production")
boolean
isProd
=
"prod"
.
equalsIgnoreCase
(
activeProfile
)
||
"production"
.
equalsIgnoreCase
(
activeProfile
)
||
activeProfile
.
toLowerCase
().
contains
(
"prod"
);
if
(
isProd
)
{
// 生产环境配置(请替换为实际的生产密钥)
seal
=
"SFP2023!@#"
;
issuer
=
"sfpfamilyfinancialplanning"
;
expiration
=
2592000L
;
// 24小时
log
.
info
(
"SfpTokenUtil 加载生产环境配置, issuer: {}, expiration: {} 秒"
,
issuer
,
expiration
);
}
else
{
// 测试/开发环境配置(请替换为实际的测试密钥)
seal
=
"zhb123!@#"
;
issuer
=
"zuihuibi"
;
expiration
=
2592000L
;
log
.
info
(
"SfpTokenUtil 加载测试环境配置, issuer: {}, expiration: {} 秒"
,
issuer
,
expiration
);
}
}
// ======================== 生成 Token ========================
/**
* 生成 JWT Token(自动添加 issuer 前缀,如 "zuihuibi {token}")
*
* @param ticket 用户标识(通常为登录名或唯一标识)
* @param userId 用户 ID(字符串)
* @param customerId 客户 ID(可选)
* @return 完整 Token 字符串(含前缀)
*/
public
static
String
generateToken
(
String
ticket
,
String
userId
,
String
customerId
)
{
Map
<
String
,
Object
>
claims
=
new
HashMap
<>();
claims
.
put
(
CLAIM_KEY_SUBJECT
,
ticket
);
claims
.
put
(
CLAIM_KEY_USERID
,
userId
);
if
(
customerId
!=
null
)
{
claims
.
put
(
CLAIM_KEY_CUSTOMERID
,
customerId
);
}
claims
.
put
(
CLAIM_KEY_CREATED
,
new
Date
());
String
token
=
Jwts
.
builder
()
.
setClaims
(
claims
)
.
setExpiration
(
new
Date
(
System
.
currentTimeMillis
()
+
expiration
*
1000
))
.
signWith
(
SignatureAlgorithm
.
HS512
,
seal
)
.
compact
();
return
issuer
+
" "
+
token
;
}
// ======================== 解析 Token ========================
/**
* 从 Token 中解析 Claims(包含所有声明信息)
*
* @param token 原始 Token(可能包含 issuer 前缀)
* @return Map, key 包含 "resultCode"(SUCCESS/EXPIRED/INVALID)和 "claims"(解析成功时为 Claims 对象)
*/
public
static
Map
<
String
,
Object
>
getClaimsFromToken
(
String
token
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
String
resultCode
=
"SUCCESS"
;
Claims
claims
=
null
;
try
{
// 去除 issuer 前缀(如果存在)
String
realToken
=
token
;
if
(
token
.
startsWith
(
issuer
+
" "
))
{
realToken
=
token
.
substring
(
issuer
.
length
()
+
1
);
}
Jws
<
Claims
>
jwsClaims
=
Jwts
.
parser
()
.
setSigningKey
(
seal
)
.
parseClaimsJws
(
realToken
);
claims
=
jwsClaims
.
getBody
();
}
catch
(
ExpiredJwtException
e
)
{
resultCode
=
"EXPIRED"
;
}
catch
(
UnsupportedJwtException
|
MalformedJwtException
|
SignatureException
|
IllegalArgumentException
e
)
{
resultCode
=
"INVALID"
;
}
catch
(
Exception
e
)
{
resultCode
=
"INVALID"
;
}
map
.
put
(
"resultCode"
,
resultCode
);
map
.
put
(
"claims"
,
claims
);
return
map
;
}
/**
* 从 Token 中获取用户 ID(String 形式)
*
* @param token 原始 Token
* @return 用户 ID 字符串,解析失败返回 null
*/
public
static
String
getUserIdFromToken
(
String
token
)
{
Map
<
String
,
Object
>
map
=
getClaimsFromToken
(
token
);
if
(
"SUCCESS"
.
equals
(
map
.
get
(
"resultCode"
)))
{
Claims
claims
=
(
Claims
)
map
.
get
(
"claims"
);
if
(
claims
!=
null
)
{
Object
userId
=
claims
.
get
(
CLAIM_KEY_USERID
);
return
userId
!=
null
?
userId
.
toString
()
:
null
;
}
}
return
null
;
}
/**
* 从 Token 中获取客户 ID
*
* @param token 原始 Token
* @return 客户 ID 字符串,解析失败返回 null
*/
public
static
String
getCustomerIdFromToken
(
String
token
)
{
Map
<
String
,
Object
>
map
=
getClaimsFromToken
(
token
);
if
(
"SUCCESS"
.
equals
(
map
.
get
(
"resultCode"
)))
{
Claims
claims
=
(
Claims
)
map
.
get
(
"claims"
);
if
(
claims
!=
null
)
{
Object
customerId
=
claims
.
get
(
CLAIM_KEY_CUSTOMERID
);
return
customerId
!=
null
?
customerId
.
toString
()
:
null
;
}
}
return
null
;
}
/**
* 验证 Token 是否有效(未过期、格式正确)
*
* @param token 原始 Token
* @return true 表示有效,false 表示无效或过期
*/
public
static
boolean
validateToken
(
String
token
)
{
Map
<
String
,
Object
>
map
=
getClaimsFromToken
(
token
);
return
"SUCCESS"
.
equals
(
map
.
get
(
"resultCode"
));
}
/**
* 检查 Token 是否过期
*
* @param token 原始 Token
* @return true 表示已过期,false 表示未过期或解析失败
*/
public
static
boolean
isTokenExpired
(
String
token
)
{
Map
<
String
,
Object
>
map
=
getClaimsFromToken
(
token
);
String
resultCode
=
(
String
)
map
.
get
(
"resultCode"
);
if
(
"EXPIRED"
.
equals
(
resultCode
))
{
return
true
;
}
if
(
"SUCCESS"
.
equals
(
resultCode
))
{
Claims
claims
=
(
Claims
)
map
.
get
(
"claims"
);
if
(
claims
!=
null
)
{
Date
expirationDate
=
claims
.
getExpiration
();
return
expirationDate
!=
null
&&
expirationDate
.
before
(
new
Date
());
}
}
return
false
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment