ChannelAction.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package info.aspirecn.iov.sjjh.supplier10000053.action;
  2. import info.aspirecn.iov.sjjh.commons.lang.ChannelTypeHandleResponseObject;
  3. import info.aspirecn.iov.sjjh.commons.lang.Constant;
  4. import info.aspirecn.iov.sjjh.supplier10000053.constant.CommonConstant;
  5. import info.aspirecn.iov.sjjh.supplier10000053.service.ChannelService;
  6. import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils;
  7. import io.swagger.annotations.ApiOperation;
  8. import io.swagger.annotations.ApiParam;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.apache.tomcat.util.codec.binary.Base64;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.PostMapping;
  13. import org.springframework.web.bind.annotation.RequestHeader;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import org.springframework.web.context.request.RequestContextHolder;
  17. import org.springframework.web.context.request.ServletRequestAttributes;
  18. import javax.servlet.http.HttpServletRequest;
  19. /**
  20. * @author xusonglin
  21. * @version V1.0
  22. **/
  23. @Slf4j
  24. @RestController
  25. public class ChannelAction {
  26. @Autowired
  27. ChannelService channelService;
  28. @ApiOperation(value = "信用分查询接口", notes = "")
  29. @PostMapping(value = "/creditScoreQuery.do")
  30. public ChannelTypeHandleResponseObject creditScoreQuery(
  31. @ApiParam(value = "通道ID") @RequestHeader(name = "channelId") String channelId,
  32. @ApiParam(value = "超时时间,单位:毫秒", example = "10000") @RequestParam(name = "outTime", required = true) int outTime,
  33. @ApiParam(value = "请求参数JSON串") @RequestParam(name = "customBody", required = true) String customBody) {
  34. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
  35. .getRequest();
  36. ChannelTypeHandleResponseObject ret = channelService.creditScoreQuery(request, customBody, outTime);
  37. //把接口参数、调用结果和是否收费放入访问日志中
  38. if (ret.getCode() != Constant.SUCCESS) {
  39. request.setAttribute(CommonConstant.Charge_Log_ResponseCode, Constant.CHANNEL_LOG_ERROR_CODE);
  40. } else {
  41. request.setAttribute(CommonConstant.Charge_Log_ResponseCode, Constant.CHANNEL_LOG_SUCCESS_CODE);
  42. }
  43. request.setAttribute(CommonConstant.Charge_Log_Key, ret.getIsCharge());
  44. try {
  45. request.setAttribute(Constant.CHANNEL_LOG_QUERY,
  46. Base64.encodeBase64String(customBody.getBytes(CommonConstant.PARA_ENCODE)));
  47. } catch (Exception ex) {
  48. ErrorUtils.captureException(ex);
  49. log.error("creditScoreQuery.encodeBase64String.Exception=", ex);
  50. }
  51. request.setAttribute(Constant.CHANNEL_TYPE_KEY, Constant.CHANNEL_TYPE_SYNC);
  52. return ret;
  53. }
  54. }