Commit 79faae14 by zhu.zewen

新增云签相关接口

parent 7d26bbe5
......@@ -197,19 +197,26 @@ public class CloudsignService {
}
/**
* 云签证书数字签名
* @param base64SourceData
* @return 签名后的数据
* 云签证书数字签名(简化版,使用默认参数)
* @param base64SourceData 待签名数据的Base64编码
* @return 签名
*/
@Deprecated
public String sign(String base64SourceData){
// 从当前用户上下文获取工号作为relBizNo
String relBizNo = SpringContextUtils.getWorkNo();
if (ObjectUtil.isEmpty(relBizNo)) {
throw new ServiceException("当前用户工号为空");
return sign(base64SourceData, null);
}
/**
* 云签证书数字签名(带业务ID参数)
* @param base64SourceData 待签名数据的Base64编码
* @param bizId 业务ID
* @return 签名值
*/
public String sign(String base64SourceData, String bizId){
// 使用默认业务类型和时间戳设置,但使用传入的业务ID
SignDataRequest request = new SignDataRequest();
// 不再需要外部传入encryptedToken,改为从数据库获取
// 自动填充业务参数
if (cloudSignProperties.getTestEnabled()) {
request.setBusinessOrgCode(cloudSignProperties.getTestBusinessOrgCode());
request.setBusinessSystemCode(cloudSignProperties.getTestBusinessSystemCode());
......@@ -219,15 +226,23 @@ public class CloudsignService {
request.setBusinessSystemCode(cloudSignProperties.getBusinessSystemCode());
request.setBusinessSystemAppID(cloudSignProperties.getBusinessSystemApplD());
}
request.setEncryptedToken(getCurrentUserEncryptedToken());
request.setBusinessTypeCode("007");
request.setWithTsa(true);
request.setBusinessTypeCode(cloudSignProperties.getDefaultBusinessTypeCode()); // 从配置加载默认业务类型
request.setWithTsa(cloudSignProperties.getDefaultWithTsa()); // 从配置加载默认时间戳设置
request.setBase64SourceData(base64SourceData);
// 设置传入的业务ID
if (ObjectUtil.isNotEmpty(bizId)) {
request.setBizId(bizId);
}
SignDataRespon resp = signData(request);
GetstampRequest getstampRequest = new GetstampRequest();
getstampRequest.setRelBizNo(relBizNo);
String getstamp = getStamp(getstampRequest);
return base64SourceData;
if (resp.getStatusCode() != 0) {
throw new ServiceException("签名失败: " + resp.getEventMsg());
}
return resp.getEventValue().getSignedData();
}
/**
......@@ -236,19 +251,6 @@ public class CloudsignService {
*/
public SignDataRespon signData(SignDataRequest request){
String logTip = "signdata";
// 自动填充业务参数和加密令牌
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.setBusinessTypeCode("007");
request.setWithTsa(true);
request.setEncryptedToken(getCurrentUserEncryptedToken());
String json = OpenUtil.toJson(request);
try {
......@@ -259,12 +261,37 @@ public class CloudsignService {
throw new ServiceException("获取失败");
}
SignDataRespon signDataRespon = JSON.parseObject(response, SignDataRespon.class);
// 检查返回的状态码
if (signDataRespon.getStatusCode() != 0) {
log.error("{}-签名失败: {}", logTip, signDataRespon.getEventMsg());
throw new ServiceException("签名失败: " + signDataRespon.getEventMsg());
}
return signDataRespon;
} catch (ServiceException se) {
// 重新抛出ServiceException
throw se;
} catch (Exception exception) {
log.error("签名失败,e:{}"+exception.getMessage());
throw new ServiceException("签名失败");
log.error("签名失败,e:{}", exception.getMessage(), exception);
throw new ServiceException("签名失败: " + exception.getMessage());
}
}
/**
* 获取当前用户的印章图片
* @return 印章图片的Base64编码
*/
public String getCurrentUserStamp(){
String relBizNo = SpringContextUtils.getWorkNo();
if (ObjectUtil.isEmpty(relBizNo)) {
throw new ServiceException("当前用户工号为空");
}
GetstampRequest request = new GetstampRequest();
request.setRelBizNo(relBizNo);
return getStamp(request);
}
/**
......
......@@ -119,4 +119,16 @@ public class CloudSignProperties {
* 二维码图片保存路径
*/
private String qrCodeSavePath = "D:/jmai/cloudsign";
/**
* 默认业务类型代码
*/
private String defaultBusinessTypeCode = "007";
/**
* 默认是否包含时间戳
*/
private Boolean defaultWithTsa = true;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment