Merge branch 'dev' into 'uat'
Dev See merge request eshop/biz_service_ebtp_extend!51
This commit is contained in:
@ -35,10 +35,18 @@ spec:
|
||||
|
||||
# 定义容器模板,该模板可以包含多个容器
|
||||
spec:
|
||||
volumes:
|
||||
- name: log
|
||||
hostPath:
|
||||
path: /var/lib/docker/log/349553515466-test/default-group/all #开发环境
|
||||
# 必选,Pod中容器列表
|
||||
containers:
|
||||
- name: biz-service-ebtp-extend
|
||||
image: harbor.dcos.guangzhou.unicom.local/eshop/biz-service-ebtp-extend:latest
|
||||
# 在容器中挂载日志存储区
|
||||
volumeMounts:
|
||||
- name: log
|
||||
mountPath: /log
|
||||
# 需要暴露的端口库号列表
|
||||
ports:
|
||||
- containerPort: 18018
|
||||
|
@ -37,9 +37,8 @@ spec:
|
||||
spec:
|
||||
volumes:
|
||||
- name: log
|
||||
persistentVolumeClaim:
|
||||
claimName: log-pvc
|
||||
readOnly: false
|
||||
hostPath:
|
||||
path: /var/lib/docker/log/349553515466-preprod/default-group/all #开发环境
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
|
@ -38,9 +38,8 @@ spec:
|
||||
# 挂载日志存储
|
||||
volumes:
|
||||
- name: log
|
||||
persistentVolumeClaim:
|
||||
claimName: log-pvc
|
||||
readOnly: false
|
||||
hostPath:
|
||||
path: /var/lib/docker/log/349553515466-uat/default-group/all #开发环境
|
||||
|
||||
# 必选,Pod中容器列表
|
||||
containers:
|
||||
|
@ -9,7 +9,9 @@ import com.chinaunicom.mall.ebtp.extend.timeService.tsa.SystemTime;
|
||||
import com.chinaunicom.mall.ebtp.extend.timeService.tsa.TtsAgent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -17,15 +19,19 @@ import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TimeServiceConstant {
|
||||
|
||||
public static TSAClient client;
|
||||
|
||||
public TimeServiceConstant() {
|
||||
try {
|
||||
@Value("${spring.redis.sentinel.master}")
|
||||
private String redis;
|
||||
|
||||
static {
|
||||
try{
|
||||
Properties prop = new Properties();
|
||||
ClassPathResource classPathResource = new ClassPathResource("cssconfig.properties");
|
||||
InputStream inputStream = classPathResource.getInputStream();
|
||||
InputStream inputStream =classPathResource.getInputStream();
|
||||
prop.load(inputStream);
|
||||
inputStream.close();
|
||||
|
||||
@ -33,60 +39,67 @@ public class TimeServiceConstant {
|
||||
TSAClientFactory factory = TSAClientFactory.newInstance(prop);
|
||||
// 获得TSAClient
|
||||
client = (TSAClient) factory.getTSAClient();
|
||||
} catch (Exception e) {
|
||||
}catch (Exception e){
|
||||
log.error("读取配置文件或连接时间戳服务器异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请时间戳
|
||||
*
|
||||
* @param data 待申请时间戳的原文
|
||||
* @return 时间戳加密原文
|
||||
*/
|
||||
public String signTimeStamp(String data) {
|
||||
try {
|
||||
data = data != null && !"".equals(data) ? data : "system";
|
||||
public String signTimeStamp(String data){
|
||||
if(redis.equals("eshop-redis-sim")){
|
||||
return "";
|
||||
}
|
||||
try{
|
||||
|
||||
data = data!=null&&!"".equals(data)?data:"system";
|
||||
//第三步:申请时间戳,向时间戳服务器发起申请时间戳请求,返回时间戳结果
|
||||
TSASignedResult result = client.signTimeStamp("SHA1", data.getBytes("UTF-8"));
|
||||
//第四步:获取时间戳数据,tsaData为时间戳数据,验证时间戳时使用,如果不是实时验证,需要将时间戳数据保存在应用服务器
|
||||
byte[] tsaData = result.getSignedData();
|
||||
log.info("tsaData -->" + tsaData);
|
||||
log.info("tsaData -->"+tsaData);
|
||||
String timestamp = Base64.encodeBase64String(tsaData);
|
||||
log.info("timestamp -->" + timestamp);
|
||||
log.info("timestamp -->"+timestamp);
|
||||
return timestamp;
|
||||
} catch (Exception e) {
|
||||
}catch (Exception e){
|
||||
log.error("申请时间戳异常", e);
|
||||
}
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析时间戳
|
||||
*
|
||||
* @param timestamp 时间戳加密原文
|
||||
* @return 时间戳对象
|
||||
*/
|
||||
public TtsAgent.TtsParseResult verifyTimeStamp2(String timestamp) {
|
||||
try {
|
||||
log.info("timestamp -->" + timestamp);
|
||||
public TtsAgent.TtsParseResult verifyTimeStamp2(String timestamp){
|
||||
String systemtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
||||
TtsAgent.TtsParseResult ttsParseResult = new TtsAgent.TtsParseResult(systemtime,"","");
|
||||
if(redis.equals("eshop-redis-sim")){
|
||||
return ttsParseResult;
|
||||
}
|
||||
try{
|
||||
|
||||
log.info("timestamp -->"+timestamp);
|
||||
TSAVerifyResult verifyResult = this.verifyTimeStamp(timestamp);
|
||||
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(verifyResult.getSignedTime());
|
||||
TtsAgent.TtsParseResult ttsParseResult = new TtsAgent.TtsParseResult(time, HelperUtil.bytesToHexString(verifyResult.getData()),
|
||||
ttsParseResult = new TtsAgent.TtsParseResult(time, HelperUtil.bytesToHexString(verifyResult.getData()),
|
||||
verifyResult.getSignerSubject());
|
||||
return ttsParseResult;
|
||||
} catch (Exception e) {
|
||||
}catch (Exception e){
|
||||
log.error("解析时间戳", e);
|
||||
}
|
||||
return null;
|
||||
return ttsParseResult;
|
||||
}
|
||||
|
||||
private TSAVerifyResult verifyTimeStamp(String timestamp) {
|
||||
try {
|
||||
log.info("timestamp -->" + timestamp);
|
||||
private TSAVerifyResult verifyTimeStamp(String timestamp){
|
||||
|
||||
try{
|
||||
|
||||
log.info("timestamp -->"+timestamp);
|
||||
TSAVerifyResult verifyResult = client.verifyTimeStamp(Base64.decodeBase64(timestamp));
|
||||
return verifyResult;
|
||||
} catch (Exception e) {
|
||||
}catch (Exception e){
|
||||
log.error("解析时间戳", e);
|
||||
}
|
||||
return null;
|
||||
@ -94,92 +107,118 @@ public class TimeServiceConstant {
|
||||
|
||||
/**
|
||||
* 获取时间戳
|
||||
*
|
||||
* @param data 待申请时间戳的原文
|
||||
* @return 时间戳对象
|
||||
*/
|
||||
public TtsAgent.TtsParseResult getServiceTimeObj(String data) {
|
||||
try {
|
||||
String timestamp = this.signTimeStamp(data);
|
||||
TtsAgent.TtsParseResult ttsParseResult = this.verifyTimeStamp2(timestamp);
|
||||
public TtsAgent.TtsParseResult getServiceTimeObj(String data){
|
||||
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
||||
TtsAgent.TtsParseResult ttsParseResult = new TtsAgent.TtsParseResult(time,"","");
|
||||
if(redis.equals("eshop-redis-sim")){
|
||||
return ttsParseResult;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try{
|
||||
|
||||
String timestamp = this.signTimeStamp(data);
|
||||
ttsParseResult = this.verifyTimeStamp2(timestamp);
|
||||
}catch (Exception e){
|
||||
log.error("获取时间戳异常", e);
|
||||
}
|
||||
return null;
|
||||
return ttsParseResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接获取获取时间戳 时间1
|
||||
*
|
||||
* @param data 待申请时间戳的原文
|
||||
* @return 时间
|
||||
*/
|
||||
public String getServiceTime(String data) {
|
||||
try {
|
||||
public String getServiceTime(String data){
|
||||
log.info("------------------redis-"+redis);
|
||||
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
||||
if(redis.equals("eshop-redis-sim")){
|
||||
return time;
|
||||
}
|
||||
try{
|
||||
|
||||
String timestamp = this.signTimeStamp(data);
|
||||
TSAVerifyResult verifyResult = this.verifyTimeStamp(timestamp);
|
||||
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(verifyResult.getSignedTime());
|
||||
|
||||
return time;
|
||||
} catch (Exception e) {
|
||||
time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(verifyResult.getSignedTime());
|
||||
}catch (Exception e){
|
||||
log.error("获取时间戳异常", e);
|
||||
}
|
||||
return null;
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 直接获取获取时间戳 时间1
|
||||
*
|
||||
* @param data 待申请时间戳的原文
|
||||
* @return date时间
|
||||
*/
|
||||
public Date getServiceDate(String data) {
|
||||
try {
|
||||
public Date getServiceDate(String data){
|
||||
if(redis.equals("eshop-redis-sim")){
|
||||
return new Date();
|
||||
}
|
||||
try{
|
||||
|
||||
String timestamp = this.signTimeStamp(data);
|
||||
TSAVerifyResult verifyResult = this.verifyTimeStamp(timestamp);
|
||||
Date date = verifyResult.getSignedTime();
|
||||
return date;
|
||||
} catch (Exception e) {
|
||||
}catch (Exception e){
|
||||
log.error("获取时间戳异常", e);
|
||||
}
|
||||
return null;
|
||||
return new Date();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年月日时分秒分割存储对象
|
||||
*
|
||||
* @param data 待申请时间戳的原文
|
||||
* @return SystemTime
|
||||
*/
|
||||
public SystemTime getServiceSystemTime(String data) {
|
||||
try {
|
||||
String timestamp = this.signTimeStamp(data);
|
||||
TSAVerifyResult verifyResult = this.verifyTimeStamp(timestamp);
|
||||
Date date = verifyResult.getSignedTime();
|
||||
SystemTime systemTime = new SystemTime()
|
||||
.setYear(date.getYear() + 1900)
|
||||
.setMonth(date.getMonth() + 1)
|
||||
public SystemTime getServiceSystemTime(String data){
|
||||
Date date = new Date();
|
||||
if(redis.equals("eshop-redis-sim")){
|
||||
return new SystemTime()
|
||||
.setYear(date.getYear()+1900)
|
||||
.setMonth(date.getMonth()+1)
|
||||
.setDate(date.getDate())
|
||||
.setHour(date.getHours())
|
||||
.setMinute(date.getMinutes())
|
||||
.setSecond(date.getSeconds())
|
||||
.setTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
|
||||
return systemTime;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try{
|
||||
|
||||
String timestamp = this.signTimeStamp(data);
|
||||
TSAVerifyResult verifyResult = this.verifyTimeStamp(timestamp);
|
||||
date = verifyResult.getSignedTime();
|
||||
|
||||
}catch (Exception e){
|
||||
log.error("获取时间戳异常", e);
|
||||
}
|
||||
return null;
|
||||
SystemTime systemTime = new SystemTime()
|
||||
.setYear(date.getYear()+1900)
|
||||
.setMonth(date.getMonth()+1)
|
||||
.setDate(date.getDate())
|
||||
.setHour(date.getHours())
|
||||
.setMinute(date.getMinutes())
|
||||
.setSecond(date.getSeconds())
|
||||
.setTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
|
||||
return systemTime;
|
||||
}
|
||||
|
||||
public static void main(String arge[]) {
|
||||
Date date = new Date();
|
||||
System.out.println("-----------" + (date.getYear() + 1900));
|
||||
System.out.println("-----------" + (date.getMonth() + 1));
|
||||
System.out.println("-----------" + date.getDate());
|
||||
System.out.println("-----------" + date.getHours());
|
||||
System.out.println("-----------" + date.getMinutes());
|
||||
System.out.println("-----------" + date.getSeconds());
|
||||
public static void main(String arge[]){
|
||||
try{
|
||||
|
||||
Date date = new Date();
|
||||
System.out.println("-----------"+(date.getYear()+1900));
|
||||
System.out.println("-----------"+(date.getMonth()+1));
|
||||
System.out.println("-----------"+date.getDate());
|
||||
System.out.println("-----------"+date.getHours());
|
||||
System.out.println("-----------"+date.getMinutes());
|
||||
System.out.println("-----------"+date.getSeconds());
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.timeService.controller;
|
||||
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import com.chinaunicom.mall.ebtp.extend.export.service.ExportServiceFactory;
|
||||
import com.chinaunicom.mall.ebtp.extend.timeService.TimeServiceConstant;
|
||||
import com.chinaunicom.mall.ebtp.extend.timeService.tsa.SystemTime;
|
||||
import com.chinaunicom.mall.ebtp.extend.timeService.tsa.TtsAgent;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -20,6 +22,8 @@ import java.util.Date;
|
||||
@RequestMapping("/v1/timeService")
|
||||
public class TimeServiceController {
|
||||
|
||||
@Autowired
|
||||
private TimeServiceConstant timeServiceConstant;
|
||||
/**
|
||||
* 申请时间戳
|
||||
*
|
||||
@ -29,8 +33,8 @@ public class TimeServiceController {
|
||||
@ApiOperation("申请时间戳")
|
||||
@GetMapping(value = "/signTimeStamp")
|
||||
public BaseResponse<String> signTimeStamp(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) {
|
||||
TimeServiceConstant constant = new TimeServiceConstant();
|
||||
return BaseResponse.success(constant.signTimeStamp(data));
|
||||
//TimeServiceConstant constant = new TimeServiceConstant();
|
||||
return BaseResponse.success(timeServiceConstant.signTimeStamp(data));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,8 +46,8 @@ public class TimeServiceController {
|
||||
@ApiOperation("解析时间戳加密原文")
|
||||
@PostMapping(value = "/verifyTimeStamp")
|
||||
public BaseResponse<TtsAgent.TtsParseResult> verifyTimeStamp(@ApiParam(value = "时间戳加密原文", required = true) @RequestBody String timestamp) {
|
||||
TimeServiceConstant constant = new TimeServiceConstant();
|
||||
return BaseResponse.success(constant.verifyTimeStamp2(timestamp));
|
||||
//TimeServiceConstant constant = new TimeServiceConstant();
|
||||
return BaseResponse.success(timeServiceConstant.verifyTimeStamp2(timestamp));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,8 +59,8 @@ public class TimeServiceController {
|
||||
@ApiOperation("直接获取时间戳对象(内涵日期)")
|
||||
@PostMapping(value = "/getServiceTimeObj")
|
||||
public BaseResponse<TtsAgent.TtsParseResult> getServiceTimeObj(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) {
|
||||
TimeServiceConstant constant = new TimeServiceConstant();
|
||||
return BaseResponse.success(constant.getServiceTimeObj(data));
|
||||
//TimeServiceConstant constant = new TimeServiceConstant();
|
||||
return BaseResponse.success(timeServiceConstant.getServiceTimeObj(data));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,8 +72,8 @@ public class TimeServiceController {
|
||||
@ApiOperation("直接获取日期字符串")
|
||||
@GetMapping(value = "/getServiceTime")
|
||||
public BaseResponse<String> getServiceTime(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) {
|
||||
TimeServiceConstant constant = new TimeServiceConstant();
|
||||
return BaseResponse.success(constant.getServiceTime(data));
|
||||
//TimeServiceConstant constant = new TimeServiceConstant();
|
||||
return BaseResponse.success(timeServiceConstant.getServiceTime(data));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,8 +85,8 @@ public class TimeServiceController {
|
||||
@ApiOperation("获取日期对象SystemTime")
|
||||
@GetMapping(value = "/getServiceSystemTime")
|
||||
public BaseResponse<SystemTime> getServiceSystemTime(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) {
|
||||
TimeServiceConstant constant = new TimeServiceConstant();
|
||||
return BaseResponse.success(constant.getServiceSystemTime(data));
|
||||
//TimeServiceConstant constant = new TimeServiceConstant();
|
||||
return BaseResponse.success(timeServiceConstant.getServiceSystemTime(data));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,9 +100,9 @@ public class TimeServiceController {
|
||||
public BaseResponse<SystemTime> getDescOpenRoomTime(@RequestParam(name = "openTime", required = true) String openTime) {
|
||||
try {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
TimeServiceConstant constant = new TimeServiceConstant();
|
||||
//TimeServiceConstant constant = new TimeServiceConstant();
|
||||
|
||||
Date now = constant.getServiceDate("getDescOpenRoomTime");
|
||||
Date now = timeServiceConstant.getServiceDate("getDescOpenRoomTime");
|
||||
;//当前时间
|
||||
Date date = df.parse(openTime);//过去
|
||||
long l = date.getTime() - now.getTime();
|
||||
|
Reference in New Issue
Block a user