ChannelAction.java 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. package info.aspirecn.iov.sjjh.supplier10000027.action;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import info.aspirecn.iov.sjjh.commons.lang.ChannelTypeHandleResponseObject;
  5. import info.aspirecn.iov.sjjh.commons.lang.Constant;
  6. import info.aspirecn.iov.sjjh.supplier10000027.constant.SjjhConstant;
  7. import info.aspirecn.iov.sjjh.supplier10000027.service.ChannelService;
  8. import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils;
  9. import io.swagger.annotations.ApiOperation;
  10. import io.swagger.annotations.ApiParam;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.apache.tomcat.util.codec.binary.Base64;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.*;
  15. import org.springframework.web.context.request.RequestContextHolder;
  16. import org.springframework.web.context.request.ServletRequestAttributes;
  17. import sun.misc.BASE64Encoder;
  18. import javax.servlet.http.HttpServletRequest;
  19. import java.io.UnsupportedEncodingException;
  20. import java.net.URLEncoder;
  21. /**
  22. * @description:
  23. * @author: xusonglin
  24. * @create: 2019/9/3 14:12
  25. * @version: V1.0
  26. **/
  27. @RestController
  28. @Slf4j
  29. public class ChannelAction {
  30. @Autowired
  31. private ChannelService service;
  32. @ApiOperation(value = "身份证有效期")
  33. @PostMapping(value = "/validateCompositeIdentityInfo.do")
  34. public ChannelTypeHandleResponseObject validateCompositeIdentityInfo(
  35. @ApiParam(value = "通道ID") @RequestHeader(name = "channelId") String channelId,
  36. @ApiParam(value = "超时时间,单位:毫秒", example = "10000") @RequestParam(name = "outTime") int outTime,
  37. @ApiParam(value = "请求参数JSON串") @RequestParam(name = "customBody") String customBody) {
  38. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
  39. .getRequest();
  40. //调用service
  41. ChannelTypeHandleResponseObject responseObject = service.validateCompositeIdentityInfo(request, customBody, outTime);
  42. //把接口参数、调用结果和是否收费放入访问日志中
  43. if (responseObject.getCode() != Constant.SUCCESS) {
  44. request.setAttribute(SjjhConstant.LOG_ERROR_PARA, Constant.CHANNEL_LOG_ERROR_CODE);
  45. } else {
  46. request.setAttribute(SjjhConstant.LOG_ERROR_PARA, Constant.CHANNEL_LOG_SUCCESS_CODE);
  47. }
  48. request.setAttribute(SjjhConstant.LOG_FEE_PARA, responseObject.getIsCharge());
  49. try {
  50. request.setAttribute(Constant.CHANNEL_LOG_QUERY, Base64.encodeBase64String(customBody.getBytes(SjjhConstant.PARA_ENCODE)));
  51. } catch (UnsupportedEncodingException e) {
  52. ErrorUtils.captureException(e);
  53. }
  54. request.setAttribute(Constant.CHANNEL_TYPE_KEY, Constant.CHANNEL_TYPE_SYNC);
  55. return responseObject;
  56. }
  57. @ApiOperation(value = "身份证简项")
  58. @PostMapping(value = "/validateIdentityInfo.do")
  59. public ChannelTypeHandleResponseObject validateIdentityInfo(
  60. @ApiParam(value = "通道ID") @RequestHeader(name = "channelId") String channelId,
  61. @ApiParam(value = "超时时间,单位:毫秒", example = "10000") @RequestParam(name = "outTime") int outTime,
  62. @ApiParam(value = "请求参数JSON串") @RequestParam(name = "customBody") String customBody) {
  63. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
  64. .getRequest();
  65. log.info("params === " + customBody);
  66. /* try {
  67. customBody = Base64.encodeBase64String(customBody.getBytes(SjjhConstant.PARA_ENCODE));
  68. log.info("action传入customBody转base64:" + customBody);
  69. } catch (Exception e) {
  70. log.error("转base64失败");
  71. ErrorUtils.captureException(e);
  72. }*/
  73. //调用service
  74. ChannelTypeHandleResponseObject responseObject = service.validateIdentityInfo(request, customBody, outTime);
  75. //把接口参数、调用结果和是否收费放入访问日志中
  76. if (responseObject.getCode() != Constant.SUCCESS) {
  77. request.setAttribute(SjjhConstant.LOG_ERROR_PARA, Constant.CHANNEL_LOG_ERROR_CODE);
  78. } else {
  79. request.setAttribute(SjjhConstant.LOG_ERROR_PARA, Constant.CHANNEL_LOG_SUCCESS_CODE);
  80. }
  81. request.setAttribute(SjjhConstant.LOG_FEE_PARA, responseObject.getIsCharge());
  82. try {
  83. request.setAttribute(Constant.CHANNEL_LOG_QUERY, Base64.encodeBase64String(customBody.getBytes(SjjhConstant.PARA_ENCODE)));
  84. } catch (UnsupportedEncodingException e) {
  85. ErrorUtils.captureException(e);
  86. }
  87. request.setAttribute(Constant.CHANNEL_TYPE_KEY, Constant.CHANNEL_TYPE_SYNC);
  88. return responseObject;
  89. }
  90. @ApiOperation(value = "身份证简项+人像")
  91. @PostMapping(value = "/validatePhotoIdentityInfo.do", produces = "application/json;charset=UTF-8")
  92. public ChannelTypeHandleResponseObject validatePhotoIdentityInfo(
  93. @ApiParam(value = "通道ID") @RequestHeader(name = "channelId") String channelId,
  94. @ApiParam(value = "超时时间,单位:毫秒", example = "10000") @RequestParam(name = "outTime") int outTime,
  95. @ApiParam(value = "请求参数JSON串") @RequestBody String customBody) {
  96. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
  97. .getRequest();
  98. //调用service
  99. ChannelTypeHandleResponseObject responseObject = service.validatePhotoIdentityInfo(request, customBody, outTime);
  100. //把接口参数、调用结果和是否收费放入访问日志中
  101. if (responseObject.getCode() != Constant.SUCCESS) {
  102. request.setAttribute(SjjhConstant.LOG_ERROR_PARA, Constant.CHANNEL_LOG_ERROR_CODE);
  103. } else {
  104. request.setAttribute(SjjhConstant.LOG_ERROR_PARA, Constant.CHANNEL_LOG_SUCCESS_CODE);
  105. }
  106. request.setAttribute(SjjhConstant.LOG_FEE_PARA, responseObject.getIsCharge());
  107. try {
  108. JSONObject paramObject = JSON.parseObject(customBody);
  109. paramObject.put("photo", "base64");
  110. log.info("actionBase64={}", Base64.encodeBase64String(paramObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE)));
  111. request.setAttribute(Constant.CHANNEL_LOG_QUERY,
  112. Base64.encodeBase64String(paramObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE)));
  113. } catch (Exception ex) {
  114. ErrorUtils.captureException(ex);
  115. }
  116. request.setAttribute(Constant.CHANNEL_TYPE_KEY, Constant.CHANNEL_TYPE_SYNC);
  117. return responseObject;
  118. }
  119. @ApiOperation(value = "身份证简项 - 中心通用版")
  120. @PostMapping(value = "/validateIdentityInfoCommon.do")
  121. public ChannelTypeHandleResponseObject validateIdentityInfoCommon(
  122. @ApiParam(value = "通道ID") @RequestHeader(name = "channelId") String channelId,
  123. @ApiParam(value = "超时时间,单位:毫秒", example = "10000") @RequestParam(name = "outTime") int outTime,
  124. @ApiParam(value = "请求参数JSON串") @RequestParam(name = "customBody") String customBody) {
  125. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
  126. .getRequest();
  127. //调用service
  128. ChannelTypeHandleResponseObject responseObject = service. validateIdentityInfoCommon(request, customBody, outTime, SjjhConstant.DECODE_TYPE_COMMON);
  129. //把接口参数、调用结果和是否收费放入访问日志中
  130. if (responseObject.getCode() != Constant.SUCCESS) {
  131. request.setAttribute(SjjhConstant.LOG_ERROR_PARA, Constant.CHANNEL_LOG_ERROR_CODE);
  132. } else {
  133. request.setAttribute(SjjhConstant.LOG_ERROR_PARA, Constant.CHANNEL_LOG_SUCCESS_CODE);
  134. }
  135. request.setAttribute(SjjhConstant.LOG_FEE_PARA, responseObject.getIsCharge());
  136. try {
  137. request.setAttribute(Constant.CHANNEL_LOG_QUERY, Base64.encodeBase64String(customBody.getBytes(SjjhConstant.PARA_ENCODE)));
  138. } catch (UnsupportedEncodingException e) {
  139. ErrorUtils.captureException(e);
  140. }
  141. request.setAttribute(Constant.CHANNEL_TYPE_KEY, Constant.CHANNEL_TYPE_SYNC);
  142. return responseObject;
  143. }
  144. @ApiOperation(value = "身份证简项 - 中心通用版-WZ加密版")
  145. @PostMapping(value = "/validateIdentityInfoCommonWZ.do")
  146. public ChannelTypeHandleResponseObject validateIdentityInfoCommonWZ(
  147. @ApiParam(value = "通道ID") @RequestHeader(name = "channelId") String channelId,
  148. @ApiParam(value = "超时时间,单位:毫秒", example = "10000") @RequestParam(name = "outTime") int outTime,
  149. @ApiParam(value = "请求参数JSON串") @RequestParam(name = "customBody") String customBody) {
  150. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
  151. .getRequest();
  152. //调用service
  153. ChannelTypeHandleResponseObject responseObject = service.validateIdentityInfoCommon(request, customBody, outTime, SjjhConstant.DECODE_TYPE_WEIZHONG);
  154. //把接口参数、调用结果和是否收费放入访问日志中
  155. if (responseObject.getCode() != Constant.SUCCESS) {
  156. request.setAttribute(SjjhConstant.LOG_ERROR_PARA, Constant.CHANNEL_LOG_ERROR_CODE);
  157. } else {
  158. request.setAttribute(SjjhConstant.LOG_ERROR_PARA, Constant.CHANNEL_LOG_SUCCESS_CODE);
  159. }
  160. request.setAttribute(SjjhConstant.LOG_FEE_PARA, responseObject.getIsCharge());
  161. try {
  162. request.setAttribute(Constant.CHANNEL_LOG_QUERY, Base64.encodeBase64String(customBody.getBytes(SjjhConstant.PARA_ENCODE)));
  163. } catch (UnsupportedEncodingException e) {
  164. ErrorUtils.captureException(e);
  165. }
  166. request.setAttribute(Constant.CHANNEL_TYPE_KEY, Constant.CHANNEL_TYPE_SYNC);
  167. return responseObject;
  168. }
  169. }