Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huang.tao
/
jmai-platform
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f3ec19d1
authored
Jan 28, 2026
by
zhu.zewen
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
优化云签接口
parent
333ef8f7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
156 additions
and
24 deletions
jmai-physic/src/main/java/com/jmai/physic/cloudsign/CheckTokenValidRequest.java
jmai-physic/src/main/java/com/jmai/physic/cloudsign/CloudsignService.java
jmai-physic/src/main/java/com/jmai/physic/cloudsign/LoginByPinResponse.java
jmai-physic/src/main/java/com/jmai/physic/controller/CloudSignController.java
jmai-physic/src/main/java/com/jmai/physic/cloudsign/CheckTokenValidRequest.java
0 → 100644
View file @
f3ec19d1
package
com
.
jmai
.
physic
.
cloudsign
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* 检查令牌有效性请求参数
* 由于是检查当前用户的令牌,所以不需要额外参数,业务参数会自动填充
*/
@Data
@ApiModel
(
value
=
"CheckTokenValidRequest"
,
description
=
"检查当前用户令牌有效性请求参数"
)
public
class
CheckTokenValidRequest
{
@ApiModelProperty
(
value
=
"深圳市卫生计生组织机构代码,每个医院均有独立编码"
,
hidden
=
true
)
private
String
businessOrgCode
;
@ApiModelProperty
(
value
=
"深圳市CA业务系统编码,每个业务系统均有独立编码"
,
hidden
=
true
)
private
String
businessSystemCode
;
@ApiModelProperty
(
value
=
"业务系统应用ID,业务系统的唯一标识号"
,
hidden
=
true
)
private
String
businessSystemAppID
;
@ApiModelProperty
(
value
=
"加密口令,通过登录接口获取"
,
hidden
=
true
)
private
String
encryptedToken
;
}
\ No newline at end of file
jmai-physic/src/main/java/com/jmai/physic/cloudsign/CloudsignService.java
View file @
f3ec19d1
...
@@ -100,7 +100,7 @@ public class CloudsignService {
...
@@ -100,7 +100,7 @@ public class CloudsignService {
/**
/**
* PIN码登录
* PIN码登录
*/
*/
public
GenloginqrcodeRespon
loginByPin
(
PinLoginRequest
request
){
public
LoginByPinResponse
loginByPin
(
PinLoginRequest
request
){
request
.
setLoginType
(
1
);
request
.
setLoginType
(
1
);
// 自动填充业务参数
// 自动填充业务参数
if
(
cloudSignProperties
.
getTestEnabled
())
{
if
(
cloudSignProperties
.
getTestEnabled
())
{
...
@@ -122,8 +122,8 @@ public class CloudsignService {
...
@@ -122,8 +122,8 @@ public class CloudsignService {
if
(
ObjectUtil
.
isEmpty
(
response
)){
if
(
ObjectUtil
.
isEmpty
(
response
)){
throw
new
ServiceException
(
"获取失败"
);
throw
new
ServiceException
(
"获取失败"
);
}
}
GenloginqrcodeRespon
genloginqrcodeRespon
=
JSON
.
parseObject
(
response
,
GenloginqrcodeRespon
.
class
);
LoginByPinResponse
loginByPinResponse
=
JSON
.
parseObject
(
response
,
LoginByPinResponse
.
class
);
return
genloginqrcodeRespon
;
return
loginByPinResponse
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"获取动态令牌失败:"
+
e
.
getMessage
(),
e
);
log
.
error
(
"获取动态令牌失败:"
+
e
.
getMessage
(),
e
);
throw
new
ServiceException
(
"loginByPin-获取动态令牌失败"
,
e
);
throw
new
ServiceException
(
"loginByPin-获取动态令牌失败"
,
e
);
...
@@ -379,6 +379,79 @@ public class CloudsignService {
...
@@ -379,6 +379,79 @@ public class CloudsignService {
}
}
/**
/**
* 通过queryStatus接口获取令牌的精确过期时间
* @param encryptedToken 加密令牌
* @return 过期时间
*/
public
LocalDateTime
getExpiryTimeFromStatus
(
String
encryptedToken
)
{
QueryStatusRequest
request
=
new
QueryStatusRequest
();
// 自动填充业务参数
if
(
cloudSignProperties
.
getTestEnabled
())
{
request
.
setBusinessOrgCode
(
cloudSignProperties
.
getTestBusinessOrgCode
());
request
.
setBusinessSystemCode
(
cloudSignProperties
.
getTestBusinessSystemCode
());
request
.
setBusinessSystemAppID
(
cloudSignProperties
.
getTestBusinessSystemAppID
());
}
else
{
request
.
setBusinessOrgCode
(
cloudSignProperties
.
getBusinessOrgCode
());
request
.
setBusinessSystemCode
(
cloudSignProperties
.
getBusinessSystemCode
());
request
.
setBusinessSystemAppID
(
cloudSignProperties
.
getBusinessSystemApplD
());
}
request
.
setEncryptedToken
(
encryptedToken
);
QueryStatusResponse
response
=
queryStatus
(
request
);
if
(
response
.
getStatusCode
()
==
0
&&
response
.
getEventValue
()
!=
null
)
{
String
timeStr
=
response
.
getEventValue
().
getTime
();
if
(
timeStr
!=
null
)
{
try
{
int
seconds
=
Integer
.
parseInt
(
timeStr
);
if
(
seconds
>
0
)
{
// 如果返回的时间大于0,则使用该时间作为过期时间
return
LocalDateTime
.
now
().
plusSeconds
(
seconds
);
}
else
{
// 如果返回-1表示令牌已过期
return
LocalDateTime
.
now
();
}
}
catch
(
NumberFormatException
e
)
{
log
.
warn
(
"解析令牌有效时间失败: {}"
,
timeStr
);
// 解析失败时,使用默认的2小时有效期
return
LocalDateTime
.
now
().
plusHours
(
2
);
}
}
}
// 如果查询失败或没有时间信息,使用默认的2小时有效期
return
LocalDateTime
.
now
().
plusHours
(
2
);
}
/**
* 检查当前用户的encryptedToken是否有效
* @return QueryStatusResponse 包含令牌有效性信息
*/
public
QueryStatusResponse
checkCurrentUserTokenValid
()
{
// 创建查询请求
QueryStatusRequest
request
=
new
QueryStatusRequest
();
// 自动填充业务参数
if
(
cloudSignProperties
.
getTestEnabled
())
{
request
.
setBusinessOrgCode
(
cloudSignProperties
.
getTestBusinessOrgCode
());
request
.
setBusinessSystemCode
(
cloudSignProperties
.
getTestBusinessSystemCode
());
request
.
setBusinessSystemAppID
(
cloudSignProperties
.
getTestBusinessSystemAppID
());
}
else
{
request
.
setBusinessOrgCode
(
cloudSignProperties
.
getBusinessOrgCode
());
request
.
setBusinessSystemCode
(
cloudSignProperties
.
getBusinessSystemCode
());
request
.
setBusinessSystemAppID
(
cloudSignProperties
.
getBusinessSystemApplD
());
}
// 设置从数据库获取的令牌
request
.
setEncryptedToken
(
getCurrentUserEncryptedToken
());
// 调用queryStatus接口检查令牌状态
return
queryStatus
(
request
);
}
/**
* 保存云签令牌信息到数据库
* 保存云签令牌信息到数据库
*/
*/
public
void
saveCloudSignToken
(
UserDto
user
,
String
encryptedToken
)
{
public
void
saveCloudSignToken
(
UserDto
user
,
String
encryptedToken
)
{
...
@@ -387,10 +460,12 @@ public class CloudsignService {
...
@@ -387,10 +460,12 @@ public class CloudsignService {
cloudSignToken
.
setUserId
(
user
.
getUserId
());
cloudSignToken
.
setUserId
(
user
.
getUserId
());
cloudSignToken
.
setWorkNo
(
user
.
getWorkNo
());
cloudSignToken
.
setWorkNo
(
user
.
getWorkNo
());
cloudSignToken
.
setEncryptedToken
(
encryptedToken
);
cloudSignToken
.
setEncryptedToken
(
encryptedToken
);
// 设置令牌过期时间为当前时间加上默认有效期(例如2小时)
cloudSignToken
.
setExpiryTime
(
LocalDateTime
.
now
().
plusHours
(
2
));
// 通过queryStatus接口获取精确的过期时间
LocalDateTime
expiryTime
=
getExpiryTimeFromStatus
(
encryptedToken
);
cloudSignToken
.
setExpiryTime
(
expiryTime
);
cloudSignToken
.
setStatus
(
1
);
// 设置为有效状态
cloudSignToken
.
setStatus
(
1
);
// 设置为有效状态
// 保存到数据库
// 保存到数据库
// 先尝试删除旧的令牌记录(如果有)
// 先尝试删除旧的令牌记录(如果有)
cloudSignTokenMapper
.
delete
(
Wrappers
.<
CloudSignToken
>
lambdaUpdate
()
cloudSignTokenMapper
.
delete
(
Wrappers
.<
CloudSignToken
>
lambdaUpdate
()
...
...
jmai-physic/src/main/java/com/jmai/physic/cloudsign/LoginByPinResponse.java
0 → 100644
View file @
f3ec19d1
package
com
.
jmai
.
physic
.
cloudsign
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
@Data
@ApiModel
(
value
=
"LoginByPinResponse"
,
description
=
"PIN码登录响应参数"
)
public
class
LoginByPinResponse
{
@ApiModelProperty
(
value
=
"状态码,非0表示执行失败"
)
private
Integer
statusCode
;
@ApiModelProperty
(
value
=
"状态信息"
)
private
String
eventMsg
;
@ApiModelProperty
(
value
=
"事件值对象"
)
private
EventValue
eventValue
;
@Data
@ApiModel
(
value
=
"LoginByPinResponse.EventValue"
,
description
=
"事件值对象"
)
public
static
class
EventValue
{
@ApiModelProperty
(
value
=
"加密令牌,用于登录后的CA签名等操作使用"
)
private
String
encryptedToken
;
}
}
\ No newline at end of file
jmai-physic/src/main/java/com/jmai/physic/controller/CloudSignController.java
View file @
f3ec19d1
...
@@ -41,22 +41,16 @@ public class CloudSignController extends AbstractService {
...
@@ -41,22 +41,16 @@ public class CloudSignController extends AbstractService {
@PostMapping
(
"/queryStatus"
)
@PostMapping
(
"/checkTokenValid"
)
@ApiOperation
(
value
=
"检查云签状态"
)
@ApiOperation
(
value
=
"检查当前用户令牌有效性"
)
public
ResponseData
<
QueryStatusResponse
>
queryStatus
(
@RequestBody
QueryStatusRequest
queryStatusRequest
)
{
public
ResponseData
<
QueryStatusResponse
>
checkTokenValid
()
{
String
workNo
=
SpringContextUtils
.
getWorkNo
();
QueryStatusResponse
response
=
cloudsignService
.
checkCurrentUserTokenValid
();
if
(
ObjectUtil
.
isEmpty
(
workNo
))
{
return
ResponseData
.
ok
(
response
);
throw
new
ServiceException
(
"当前用户工号为空"
);
}
// 现在业务参数和encryptedToken会在服务层自动填充
QueryStatusResponse
queryStatus
=
cloudsignService
.
queryStatus
(
queryStatusRequest
);
return
ResponseData
.
ok
(
queryStatus
);
}
}
@PostMapping
(
"/loginByPin"
)
@PostMapping
(
"/loginByPin"
)
@ApiOperation
(
value
=
"PIN码登录"
)
@ApiOperation
(
value
=
"PIN码登录"
)
public
ResponseData
<
GenloginqrcodeRespon
>
loginByPin
(
@RequestBody
PinLoginRequest
pinLoginRequest
)
{
public
ResponseData
<
LoginByPinResponse
>
loginByPin
(
@RequestBody
PinLoginRequest
pinLoginRequest
)
{
String
workNo
=
SpringContextUtils
.
getWorkNo
();
String
workNo
=
SpringContextUtils
.
getWorkNo
();
if
(
ObjectUtil
.
isEmpty
(
workNo
))
{
if
(
ObjectUtil
.
isEmpty
(
workNo
))
{
throw
new
ServiceException
(
"当前用户工号为空"
);
throw
new
ServiceException
(
"当前用户工号为空"
);
...
@@ -66,7 +60,7 @@ public class CloudSignController extends AbstractService {
...
@@ -66,7 +60,7 @@ public class CloudSignController extends AbstractService {
pinLoginRequest
.
setUserEncodePin
(
pinLoginRequest
.
getUserEncodePin
());
pinLoginRequest
.
setUserEncodePin
(
pinLoginRequest
.
getUserEncodePin
());
// 现在业务参数和测试环境配置会在服务层自动处理
// 现在业务参数和测试环境配置会在服务层自动处理
GenloginqrcodeRespon
pinLogin
=
cloudsignService
.
loginByPin
(
pinLoginRequest
);
LoginByPinResponse
pinLogin
=
cloudsignService
.
loginByPin
(
pinLoginRequest
);
return
ResponseData
.
ok
(
pinLogin
);
return
ResponseData
.
ok
(
pinLogin
);
}
}
...
@@ -105,7 +99,7 @@ public class CloudSignController extends AbstractService {
...
@@ -105,7 +99,7 @@ public class CloudSignController extends AbstractService {
// 跳过认证
// 跳过认证
@AuthSkipped
@AuthSkipped
@PostMapping
(
"/loginByQrcode/callback"
)
@PostMapping
(
"/loginByQrcode/callback"
)
@ApiOperation
(
value
=
"二维码登录回调"
)
@ApiOperation
(
value
=
"
回调-
二维码登录回调"
)
public
ResponseData
<
CloudSignCallbackResponse
>
loginByQrcodeCallback
(
@RequestBody
CloudSignCallbackRequest
callbackRequest
)
{
public
ResponseData
<
CloudSignCallbackResponse
>
loginByQrcodeCallback
(
@RequestBody
CloudSignCallbackRequest
callbackRequest
)
{
log
.
info
(
"接收到云签登录回调,claimUuid: {}, loginStatus: {}, relBizNo: {}"
,
log
.
info
(
"接收到云签登录回调,claimUuid: {}, loginStatus: {}, relBizNo: {}"
,
callbackRequest
.
getClaimUuid
(),
callbackRequest
.
getLoginStatus
(),
callbackRequest
.
getRelBizNo
());
callbackRequest
.
getClaimUuid
(),
callbackRequest
.
getLoginStatus
(),
callbackRequest
.
getRelBizNo
());
...
@@ -230,8 +224,6 @@ public class CloudSignController extends AbstractService {
...
@@ -230,8 +224,6 @@ public class CloudSignController extends AbstractService {
return
saveDir
+
java
.
io
.
File
.
separator
+
fileName
;
return
saveDir
+
java
.
io
.
File
.
separator
+
fileName
;
}
}
@PostMapping
(
"/getLoginByQrcodeResult"
)
@PostMapping
(
"/getLoginByQrcodeResult"
)
@ApiOperation
(
value
=
"查询二维码登录结果"
)
@ApiOperation
(
value
=
"查询二维码登录结果"
)
public
ResponseData
<
GetLoginResultResponse
>
getLoginByQrcodeResult
(
@RequestBody
GetLoginResultRequest
getLoginResultRequest
)
{
public
ResponseData
<
GetLoginResultResponse
>
getLoginByQrcodeResult
(
@RequestBody
GetLoginResultRequest
getLoginResultRequest
)
{
...
@@ -245,8 +237,21 @@ public class CloudSignController extends AbstractService {
...
@@ -245,8 +237,21 @@ public class CloudSignController extends AbstractService {
return
ResponseData
.
ok
(
getLoginResult
);
return
ResponseData
.
ok
(
getLoginResult
);
}
}
@PostMapping
(
"/queryStatus"
)
@ApiOperation
(
value
=
"测试-检查云签状态"
)
public
ResponseData
<
QueryStatusResponse
>
queryStatus
(
@RequestBody
QueryStatusRequest
queryStatusRequest
)
{
String
workNo
=
SpringContextUtils
.
getWorkNo
();
if
(
ObjectUtil
.
isEmpty
(
workNo
))
{
throw
new
ServiceException
(
"当前用户工号为空"
);
}
// 现在业务参数和encryptedToken会在服务层自动填充
QueryStatusResponse
queryStatus
=
cloudsignService
.
queryStatus
(
queryStatusRequest
);
return
ResponseData
.
ok
(
queryStatus
);
}
@PostMapping
(
"/getCertInfo"
)
@PostMapping
(
"/getCertInfo"
)
@ApiOperation
(
value
=
"获取Base64编码证书"
)
@ApiOperation
(
value
=
"
测试-
获取Base64编码证书"
)
public
ResponseData
<
GetCertInfoResponse
>
getCertInfo
(
@RequestBody
GetCertInfoRequest
getCertInfoRequest
)
{
public
ResponseData
<
GetCertInfoResponse
>
getCertInfo
(
@RequestBody
GetCertInfoRequest
getCertInfoRequest
)
{
String
workNo
=
SpringContextUtils
.
getWorkNo
();
String
workNo
=
SpringContextUtils
.
getWorkNo
();
if
(
ObjectUtil
.
isEmpty
(
workNo
))
{
if
(
ObjectUtil
.
isEmpty
(
workNo
))
{
...
@@ -259,7 +264,7 @@ public class CloudSignController extends AbstractService {
...
@@ -259,7 +264,7 @@ public class CloudSignController extends AbstractService {
}
}
@PostMapping
(
"/verifyData"
)
@PostMapping
(
"/verifyData"
)
@ApiOperation
(
value
=
"云签证书数字签名验证"
)
@ApiOperation
(
value
=
"
测试-
云签证书数字签名验证"
)
public
ResponseData
<
VerifyDataResponse
>
verifyData
(
@RequestBody
VerifyDataRequest
verifyDataRequest
)
{
public
ResponseData
<
VerifyDataResponse
>
verifyData
(
@RequestBody
VerifyDataRequest
verifyDataRequest
)
{
String
workNo
=
SpringContextUtils
.
getWorkNo
();
String
workNo
=
SpringContextUtils
.
getWorkNo
();
if
(
ObjectUtil
.
isEmpty
(
workNo
))
{
if
(
ObjectUtil
.
isEmpty
(
workNo
))
{
...
...
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