Commit df1d7dc5 authored by kang.nie@inzymeits.com's avatar kang.nie@inzymeits.com
Browse files

初始化代码

parent 565dfc9e
Pipeline #3110 failed with stages
in 0 seconds
package com.cusc.nirvana.user.rnr.openapi.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* 二手车解绑DTO
*
* @author huchenhui
* @date 2022-04-14
*/
@Data
public class SecondHandUnbindRequestDTO extends OpenApiBaseDTO implements Serializable {
private static final long serialVersionUID = -407770263820788123L;
@ApiModelProperty(value = "请求ID")
@NotEmpty(message = "请求ID不能为空")
private String requestId;
@ApiModelProperty(value = "车辆VIN号")
@NotBlank(message = "车辆VIN号不能为空")
private String vin;
@ApiModelProperty(value = "客户类型 0:新车车主 1:二手车车主")
@NotNull(message = "客户类型不能为空")
private Integer customerType;
@ApiModelProperty(value = "是否委托人代办 true:是 false:否")
@NotNull(message = "是否委托人不能为空")
private Boolean isConsigner = false;
@ApiModelProperty(value = "委托人信息")
private ConsignerInfoDTO consignerInfo;
@ApiModelProperty(value = "ICCID编号集合")
@NotEmpty(message = "ICCID不能为空")
private List<String> iccidList;
@ApiModelProperty(value = "车主姓名")
@NotBlank(message = "车主姓名不能为空")
private String fullName;
@ApiModelProperty(value = "性别")
@NotBlank(message = "性别不能为空")
private String gender;
@ApiModelProperty(value = "证件类型 " +
"'IDCARD':居民身份证 " +
"'HOUSEHOLD':户口簿 " +
"'PLAIDCARD':中国人民解放军军人身份证件 " +
"'CAPFIDCARD':中国人民武装警察身份证件 " +
"'HKIDCARD':港澳居民来往内地通行证 " +
"'TAIBAOZHENG':台湾居民来往大陆通行证 " +
"'PASSPORT':外国公民护照 " +
"'HKRESIDENCECARD':港澳居民居住证 " +
"'TWRESIDENCECARD':台湾居民居住证")
@NotBlank(message = "证件类型不能为空")
private String certType;
@ApiModelProperty(value = "证件号码")
private String certNumber;
@ApiModelProperty(value = "证件地址")
@NotBlank(message = "证件地址不能为空")
private String certAddress;
@ApiModelProperty(value = "证件照片")
@NotEmpty(message = "证件照片不能为空")
private List<String> certPic;
@ApiModelProperty(value = "证件有效期")
@NotBlank(message = "证件有效期不能为空")
private String certExpirationDate;
@ApiModelProperty(value = "活体验证视频")
@NotBlank(message = "活体验证视频不能为空")
private String liveVerificationVideo;
@ApiModelProperty(value = "通讯地址")
private String contactAddress;
@ApiModelProperty(value = "入网合同")
// @NotEmpty(message = "入网合同不能为空")
private List<String> contractPic;
@ApiModelProperty(value = "购车合同")
@NotEmpty(message = "购车合同不能为空")
private List<String> purchaseContractPic;
@ApiModelProperty(value = "购车发票")
// @NotEmpty(message = "购车发票不能为空")
private List<String> purchaseInvoicePic;
@ApiModelProperty(value = "过户证明")
private List<String> transferCertificatePic;
@ApiModelProperty(value = "车主手机号码")
@NotBlank(message = "车主手机号码不能为空")
private String phone;
@ApiModelProperty(value = "短信验证码")
private String verificationCode;
}
package com.cusc.nirvana.user.rnr.openapi.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.List;
/**
* @author yubo
* @since 2022-05-03 09:59
*/
@Data
@Accessors(chain = true)
public class UnBindIccidDTO extends OpenApiBaseDTO {
@ApiModelProperty(value = "ICCID")
@NotEmpty(message = "ICCID列表不能为空")
private List<String> iccidList;
@ApiModelProperty(value = "VIN")
@NotBlank(message = "VIN不能为空")
private String vin;
@ApiModelProperty(value = "业务ID")
@NotBlank(message = "实名业务ID不能为空")
private String rnrId;
private String name;
//手机,脱密
private String phone;
//性别,0男,1女
private Integer gender;
}
package com.cusc.nirvana.user.rnr.openapi.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.List;
/**
* Description: 剩余卡绑定DTO
* <br />
* CreateDate 2022-04-20 20:22:56
*
* @author yuyi
**/
@Data
public class VehicleCardRnrDTO extends OpenApiBaseDTO implements Serializable {
private static final long serialVersionUID = -5712879585098743410L;
@ApiModelProperty(value = "车辆VIN号")
@NotBlank(message = "vin不能为空")
private String vin;
@ApiModelProperty(value = "实名id")
private String rnrId;
@ApiModelProperty(value = "ICCID编码集合")
@NotEmpty(message = "ICCID不能为空")
private List<String> iccidList;
}
package com.cusc.nirvana.user.rnr.openapi.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.List;
@Accessors(chain = true)
@Data
public class VinCardInfoDTO extends OpenApiBaseDTO {
@NotBlank(message = "VIN不能为空")
private String vin;
@NotEmpty(message = "ICCID不能为空")
private List<String> iccidList;
}
package com.cusc.nirvana.user.rnr.openapi.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
/**
* 车辆VIN号DTO
*
* @author huchenhui
* @date 2022-04-15
*/
@Data
@Accessors(chain = true)
public class VinDTO extends OpenApiBaseDTO {
@ApiModelProperty(value = "车辆VIN号")
@NotBlank(message = "车辆VIN号不能为空")
private String vin;
}
package com.cusc.nirvana.user.rnr.openapi.dto.groups;
/**
* Description: 企业责任人变更DTO
* <br />
* CreateDate 2022-04-20 16:41:45
*
* @author yuyi
**/
public interface EnterpriseCorporationChangeGroup {
/**
* Description: 查询参数验证
* <br />
* CreateDate 2022-04-20 17:05:51
*
* @author yuyi
**/
interface Query{}
/**
* Description: 提交参数验证
* <br />
* CreateDate 2022-04-20 17:05:51
*
* @author yuyi
**/
interface Submit{}
}
package com.cusc.nirvana.user.rnr.openapi.dto.groups;
import javax.validation.groups.Default;
/**
* @author yubo
* @since 2022-04-18 16:30
*/
public interface PersonalSubmit extends Default {
}
package com.cusc.nirvana.user.rnr.openapi.dto.groups;
import javax.validation.groups.Default;
/**
* @author yubo
* @since 2022-04-18 16:32
*/
public interface PersonalVehicleCardVerify extends Default {
}
package com.cusc.nirvana.user.rnr.openapi.dto.groups;
/**
* Description: 剩余卡绑定验证分组
* <br />
* CreateDate 2022-04-20 16:41:45
*
* @author yuyi
**/
public interface VehicleCardRnrGroup {
/**
* Description: 查询参数验证
* <br />
* CreateDate 2022-04-20 17:05:51
*
* @author yuyi
**/
interface Query{}
/**
* Description: 提交参数验证
* <br />
* CreateDate 2022-04-20 17:05:51
*
* @author yuyi
**/
interface Submit{}
}
package com.cusc.nirvana.user.rnr.openapi.dto.groups;
import javax.validation.groups.Default;
/**
* @author yubo
* @since 2022-04-18 11:24
*/
public interface VehicleCardVerify extends Default {
}
package com.cusc.nirvana.user.rnr.openapi.dto.response;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 开放平台DTO基类
*
* @author tangjw
* @since 2022-05-10
*/
@Data
@NoArgsConstructor
public abstract class OpenApiBaseRsp {
}
package com.cusc.nirvana.user.rnr.openapi.dto.response;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* 实名卡信息(MgRnrCardInfo)传输对象类
*
* @author yuy336
* @since 2022-03-04 11:06:36
*/
@ApiModel(value = "实名卡信息", description = "实名卡信息")
@Data
public class RnAuthInfoRsp extends OpenApiBaseRsp {
private static final long serialVersionUID = -77640748451387414L;
@ApiModelProperty(value = "实名业务主键")
private String rnrId;
@ApiModelProperty(value = "老的业务id,换人之前的cardid")
private String oldCardId;
@ApiModelProperty(value = "卡号")
// @NotBlank(groups = SaveRelation.class, message = "卡号不能为空")
private String iccid;
@ApiModelProperty(value = "物联网设备id")
// @NotBlank(groups = SaveRelation.class, message = "物联网设备id不能为空")
private String iotId;
@ApiModelProperty(value = "实名状态 0 未实名 1 已实名 2 实名失败 3 已解绑")
// @NotNull(groups = SaveRelation.class, message = "实名状态不能为空")
private String rnrStatus;
@ApiModelProperty(value = "语言版本")
private Long lang;
@ApiModelProperty(value = "备注信息")
private Long comment;
@ApiModelProperty(value = "iccid集合")
private List<String> iccidList;
@ApiModelProperty(value = "姓名(自然人姓名或企业责任人姓名)")
private String fullName;
@ApiModelProperty(value = "证件类型")
private String certType;
@ApiModelProperty(value = "证件号码")
private String certNumber;
@ApiModelProperty(value = "手机号码")
private String phone;
@ApiModelProperty(value = "是否是企业")
private String isCompany;
@ApiModelProperty(value = "公司名称")
private String companyName;
}
package com.cusc.nirvana.user.rnr.openapi.dto.response;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Map;
/**
* 实名卡信息(RnAuthStateRsp) 状态接口返回对象
*
* @author tangjw
* @since 2022-05-10 09:06:36
*/
@ApiModel(value = "实名状态返回对象", description = "实名状态返回对象")
@Data
public class RnAuthStateRsp extends OpenApiBaseRsp {
private static final long serialVersionUID = -77640748451387414L;
@ApiModelProperty(value = "实名状态集合key:vin-iccid;value:实名状态", example = "vin-iccid:已实名")
private Map<String, String> rnAuthStateMap;
}
package com.cusc.nirvana.user.rnr.openapi.exception;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.rnr.fp.common.ResponseCode;
import com.cusc.nirvana.web.exception.AppGlobalException;
import com.cusc.nirvana.web.handler.AppGlobalExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.BindException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.util.Set;
@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
@ControllerAdvice
public class RnrApiGlobalExceptionHandler {
private Logger logger = LoggerFactory.getLogger(RnrApiGlobalExceptionHandler.class);
@ExceptionHandler({IllegalArgumentException.class, MethodArgumentNotValidException.class, AppGlobalException.class,RnrOpenApiException.class})
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public Response methodArgumentNotValidExceptionHandle(Exception ex) {
String message = "";
if (ex instanceof IllegalArgumentException) {
logger.error("IllegalArgumentException:", ex);
// 参数校验不通过
IllegalArgumentException illegalArgumentException = ((IllegalArgumentException) ex);
message = illegalArgumentException.getMessage();
} else if (ex instanceof MethodArgumentNotValidException) {
logger.error("MethodArgumentNotValidException:", ex);
// 参数校验不通过
MethodArgumentNotValidException methodArgumentNotValidException = ((MethodArgumentNotValidException) ex);
message = methodArgumentNotValidException.getBindingResult().getAllErrors().get(0).getDefaultMessage();
return Response.createError(message, ResponseCode.INVALID_DATA.getCode());
} else if (ex instanceof AppGlobalException) {
logger.error("AppGlobalException:", ex);
// 自定义异常
AppGlobalException appGlobalException = (AppGlobalException) ex;
Response response = appGlobalException.getRes();
if (response.getData() instanceof Throwable) {
response.setData(null);
}
return response;
} else {
message = "未知系统异常200";
}
return Response.createError(message);
}
@ExceptionHandler(Exception.class)
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Response validExceptionHandle(Exception ex) {
String message;
if (ex instanceof BindException) {
BindException bingException = (BindException) ex;
message = bingException.getAllErrors().get(0).getDefaultMessage();
} else if (ex instanceof HttpMessageNotReadableException) {
HttpMessageNotReadableException notReadableException = (HttpMessageNotReadableException) ex;
message = notReadableException.getMessage();
} else if (ex instanceof ConstraintViolationException) {
//参数校验异常,controller层直接参数校验(单个字段校验)
ConstraintViolationException validationException = (ConstraintViolationException) ex;
Set<ConstraintViolation<?>> violationErrors = validationException.getConstraintViolations();
ConstraintViolation<?> error = violationErrors.iterator().next();
message = error.getMessage();
} else if (ex instanceof HttpRequestMethodNotSupportedException) {
HttpRequestMethodNotSupportedException methodNotSupportedException = (HttpRequestMethodNotSupportedException) ex;
message = methodNotSupportedException.getMessage();
} else {
message = "未知系统异常500:" + ex.getMessage();
}
logger.error("{}:", message, ex);
return Response.createError("系统忙稍后再试,CODE@500");
}
}
\ No newline at end of file
package com.cusc.nirvana.user.rnr.openapi.exception;
import com.cusc.nirvana.web.exception.AppGlobalException;
/**
* 自定义异常
*
* @author tangjw
*/
public class RnrOpenApiException extends AppGlobalException {
private static final long serialVersionUID = 1L;
public RnrOpenApiException(String message) {
super(message);
}
public RnrOpenApiException(String message, Integer code) {
super(code, message);
}
public RnrOpenApiException(Integer code, String msg) {
super(code, msg);
}
public RnrOpenApiException(String msg, Throwable cause) {
super(msg, cause);
}
public RnrOpenApiException(Integer code, String msg, Throwable cause) {
super(code, msg, cause);
}
}
package com.cusc.nirvana.user.rnr.openapi.interceptor;
import com.alibaba.fastjson.JSON;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.rnr.fp.common.ResponseCode;
import com.cusc.nirvana.user.rnr.openapi.common.Constants;
import com.cusc.nirvana.user.rnr.openapi.config.OpenapiConfig;
import com.cusc.nirvana.user.rnr.openapi.constants.AuthConstant;
import com.cusc.nirvana.user.rnr.openapi.util.SignUtils;
import com.cusc.nirvana.user.rnr.openapi.util.ThreadLocalUtil;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
/**
* Description: 鉴权拦截器
* <p>
* 1. 从RequestHead中获取开放平台租户ID(TENANT_NO),通过开放平台租户ID获取对应的实名制系统租户ID(rnrTenantRelation)
* 2. 通过入参中的组织ID(orgId)获取组织对应的实名制系统租户ID(rnrTenant)
* 3. 校验 实名制系统租户ID(rnrTenant) 是否与 实名制系统租户ID(rnrTenantRelation)是否相同,
* 不相同,拦截
* 相同,将参数中的用户ID,实名制系统租户ID放入ThreadLocal中,后续使用
* <br />
* <p>
* CreateDate 2022-05-06 14:36
*
* @author caow
**/
public class AuthInterceptor implements HandlerInterceptor {
private static final Logger LOGGER = LoggerFactory.getLogger(AuthInterceptor.class);
@Autowired
OpenapiConfig openapiConfig;
@Value("${auth.userId:OpenApi}")
private String userId;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
String requestUri = request.getRequestURI();
Response checkResponse = signCheck(request);
if (!checkResponse.isSuccess()) {
LOGGER.info("AuthInterceptor url:{}, sign check failed, {}.", requestUri, checkResponse.getMsg());
returnJson(response,
JSON.toJSONString(Response.createError(checkResponse.getMsg(),
ResponseCode.INVALID_DATA.getCode())));
return false;
}
ThreadLocalUtil.set(AuthConstant.TENANT_NO_NAME, openapiConfig.getTenantNo());
ThreadLocalUtil.set(AuthConstant.USER_ID_NAME, userId);
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
Exception ex) {
ThreadLocalUtil.removeByKey(AuthConstant.USER_ID_NAME);
ThreadLocalUtil.removeByKey(AuthConstant.TENANT_NO_NAME);
}
/**
* 签名校验
* @param request
* @return
*/
private Response signCheck(HttpServletRequest request) {
String sign = request.getHeader(Constants.SIGN);
String appId = request.getHeader(Constants.APP_ID);
String nonceStr = request.getHeader(Constants.NONCE_STR);
String timeStamp = request.getHeader(Constants.TIMESTAMP);
String version = request.getHeader(Constants.VERSION);
if(StringUtils.isBlank(sign)){
return Response.createError("请求Header中缺少SIGN");
}
if(StringUtils.isBlank(appId)){
return Response.createError("请求Header中缺少APPID");
}
if(StringUtils.isBlank(nonceStr)){
return Response.createError("请求Header中缺少NONCE_STR");
}
if(StringUtils.isBlank(timeStamp) || !StringUtils.isNumeric(timeStamp)){
return Response.createError("请求Header中缺少TIMESTAMP或TIMESTAMP格式错误");
}
if(StringUtils.isBlank(version)){
return Response.createError("请求Header中缺少VERSION");
}
Map<String, String> map = Maps.newHashMapWithExpectedSize(4);
map.put(Constants.APP_ID, appId);
map.put(Constants.TIMESTAMP, timeStamp);
map.put(Constants.NONCE_STR, nonceStr);
map.put(Constants.VERSION, version);
long currentTimeMillis = System.currentTimeMillis();
long apiTime = Long.parseLong(timeStamp);
if(currentTimeMillis > apiTime && (currentTimeMillis - apiTime) > openapiConfig.getTimeOut()){
return Response.createError("TIMESTAMP超时,已超过"+openapiConfig.getTimeOut()/1000+"秒");
}
boolean valid = SignUtils.getInstance().isValid(sign, map, openapiConfig.getAppSecret());
if(!valid){
return Response.createError("签名校验失败,请确认签名信息");
}
return Response.createSuccess();
}
private void returnJson(HttpServletResponse response, String json) {
response.setCharacterEncoding("utf-8");
response.setContentType("application/json; charset=utf-8");
PrintWriter writer = null;
try {
writer = response.getWriter();
writer.write(json);
} catch (IOException e) {
LOGGER.error("AuthInterceptor 响应json 异常: {}", e);
} finally {
if (writer != null) {
writer.close();
}
}
}
}
package com.cusc.nirvana.user.rnr.openapi.interceptor;
import java.io.IOException;
import java.lang.reflect.Type;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;
public abstract class RequestBodyAdviceAdapter implements RequestBodyAdvice {
@Override
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
throws IOException {
return inputMessage;
}
@Override
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
return body;
}
@Override
@Nullable
public Object handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessage,
MethodParameter parameter, Type targetType,
Class<? extends HttpMessageConverter<?>> converterType) {
return body;
}
}
package com.cusc.nirvana.user.rnr.openapi.interceptor;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.cusc.nirvana.user.rnr.openapi.config.OpenapiConfig;
import com.cusc.nirvana.user.rnr.openapi.constants.AuthConstant;
import com.cusc.nirvana.user.rnr.openapi.dto.OrganizationRespDTO;
import com.cusc.nirvana.user.rnr.openapi.dto.PagerDTO;
import com.cusc.nirvana.user.rnr.openapi.exception.RnrOpenApiException;
import com.cusc.nirvana.user.rnr.openapi.service.IOrganizationService;
import com.cusc.nirvana.user.rnr.openapi.util.ThreadLocalUtil;
import com.cusc.nirvana.user.util.crypt.Sm4Util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.io.*;
import java.lang.reflect.Type;
import java.util.List;
@Slf4j
@RestControllerAdvice
public class RequestBodyDecodeAdvice extends RequestBodyAdviceAdapter {
@Autowired
private IOrganizationService organizationService;
@Autowired
private OpenapiConfig openapiConfig;
@Override
public boolean supports(MethodParameter methodParameter, Type targetType,
Class<? extends HttpMessageConverter<?>> converterType) {
/**
* 系统使用的是FastJson作为json数据的Http消息转换器
*/
return FastJsonHttpMessageConverter.class.isAssignableFrom(converterType);
}
@Override
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
Class<? extends HttpMessageConverter<?>> converterType) throws IOException {
// 读取加密的请求体 todo 后续要进行加白名单功能
if (!"decode".equals(parameter.getMethod().getName()) && !"encode".equals(parameter.getMethod().getName())
&& !"liveness".equals(parameter.getMethod().getName())) {
// byte[] body = new byte[inputMessage.getBody().available()];
// inputMessage.getBody().read(body);
// String bodySource = new String(body, StandardCharsets.UTF_8);
String bodySource = getStringByInputStream(inputMessage.getBody());
if (StringUtils.isNotEmpty(bodySource)) {
if (bodySource.contains("\"")) {
bodySource = bodySource.replace("\"", "").trim();
}
try {
// 解密
String bodyStr = Sm4Util.decryptEcbPaddingString(openapiConfig.getDataSecret(), bodySource);
//从请求头获取开放平台租户ID
List<String> openTenantId = inputMessage.getHeaders().get(AuthConstant.HEADER_TENANT_ID);
JSONObject param = JSONObject.parseObject(bodyStr);
if (null == param) {
throw new RnrOpenApiException("解密body时候出错,请检查租户相关秘钥配置后再试");
}
String orgId = (String) param.get(AuthConstant.BODY_ORG_ID);
if (StringUtils.isEmpty(orgId) && org.apache.commons.collections4.CollectionUtils.isNotEmpty(
openTenantId)) {
PagerDTO pagerDTO = new PagerDTO();
try {
List<OrganizationRespDTO> orgList =
organizationService.getOrgListByPage(openTenantId.get(0), pagerDTO);
if (!org.apache.commons.collections4.CollectionUtils.isEmpty(orgList)) {
orgId = orgList.get(0).getUuid();
param.put(AuthConstant.BODY_ORG_ID, orgId);
ThreadLocalUtil.set(AuthConstant.BODY_ORG_ID, orgId);
}
} catch (Exception e) {
log.error("getOrgListByPage-error", e);
}
}
byte[] body = param.toJSONString().getBytes();
// 使用解密后的数据,构造新的读取流
InputStream rawInputStream = new ByteArrayInputStream(body);
return new HttpInputMessage() {
@Override
public HttpHeaders getHeaders() {
return inputMessage.getHeaders();
}
@Override
public InputStream getBody() throws IOException {
return rawInputStream;
}
};
} catch (Exception e) {
log.error("解密body失败", e);
throw new RnrOpenApiException("解密body失败,请检查租户相关秘钥配置后再试");
}
}
}
return inputMessage;
}
private String getStringByInputStream(InputStream inputStream) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
try {
StringBuilder result = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
result.append(line);
}
return result.toString();
} catch (Exception e) {
try {
inputStream.close();
bufferedReader.close();
} catch (Exception e1) {
log.error("body-inputstream转String异常", e);
}
}
return null;
}
}
package com.cusc.nirvana.user.rnr.openapi.interceptor;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.rnr.openapi.config.OpenapiConfig;
import com.cusc.nirvana.user.util.crypt.Sm4Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
@Slf4j
@RestControllerAdvice
public class ResponseBodyEncodeAdvice implements ResponseBodyAdvice {
@Autowired
OpenapiConfig openapiConfig;
@Override
public boolean supports(MethodParameter returnType, Class converterType) {
return true;
}
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
// 读取加密的请求体
if (body instanceof Response) {
Response rnrResponse = (Response) body;
if (rnrResponse.isSuccess() && !"decode".equals(returnType.getMethod().getName()) && !"encode".equals(returnType.getMethod().getName())) {
try {
String bodyStr = JSON.toJSONString(rnrResponse.getData(), SerializerFeature.MapSortField);
String encodeData = Sm4Util.encryptEcbPaddingHexString(openapiConfig.getDataSecret(), bodyStr);
rnrResponse.setData(encodeData);
} catch (Exception e) {
log.error("获取租户秘钥信息失败或解密失败-error", e);
}
}
return rnrResponse;
} else {
Response resp = (Response) body;
if (resp.isSuccess() && !"decode".equals(returnType.getMethod().getName()) && !"encode".equals(returnType.getMethod().getName())) {
try {
String bodyStr = JSON.toJSONString(resp.getData(), SerializerFeature.MapSortField);
String encodeData = Sm4Util.encryptEcbPaddingHexString(openapiConfig.getDataSecret(), bodyStr);
resp.setData(encodeData);
} catch (Exception e) {
log.error("获取租户秘钥信息失败或解密失败-error", e);
}
}
return resp;
}
}
}
package com.cusc.nirvana.user.rnr.openapi.service;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.rnr.mg.dto.RnrOrderDTO;
import com.cusc.nirvana.user.rnr.openapi.dto.SecondHandUnbindRequestDTO;
import com.cusc.nirvana.user.rnr.openapi.dto.VehicleCardRnrDTO;
/**
* 解绑接口
* @author yubo
* @since 2022-04-25 09:31
*/
public interface ICardUnBindService {
Response sendMessage(VehicleCardRnrDTO bean);
Response checkOrderStatus(RnrOrderDTO bean);
Response originalOwner(VehicleCardRnrDTO bean);
/**
* 二手车现车主解绑-自然人
*/
Response secondHandPersonalUnbind(SecondHandUnbindRequestDTO bean);
}
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 to comment