ChannelServiceImpl.java 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480
  1. package info.aspirecn.iov.sjjh.supplier10000043.service;
  2. import brave.Tracer;
  3. import com.alibaba.fastjson.JSONArray;
  4. import info.aspirecn.iov.sjjh.channel.inter.platform.ChannelActionInterface;
  5. import info.aspirecn.iov.sjjh.service.sms.action.SmsActionInterface;
  6. import info.aspirecn.iov.sjjh.supplier10000043.constant.SupplierProperties;
  7. import info.aspirecn.iov.sjjh.supplier10000043.util.AesUtil;
  8. import info.aspirecn.iov.sjjh.supplier10000043.util.CommonUtil;
  9. import info.aspirecn.iov.sjjh.supplier10000043.util.NotifyThread;
  10. import okhttp3.*;
  11. import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
  12. import com.alibaba.fastjson.JSON;
  13. import com.alibaba.fastjson.JSONObject;
  14. import com.fasterxml.jackson.databind.ObjectMapper;
  15. import info.aspirecn.iov.sjjh.commons.lang.ChannelTypeHandleResponseObject;
  16. import info.aspirecn.iov.sjjh.commons.lang.Constant;
  17. import info.aspirecn.iov.sjjh.commons.lang.PatternTools;
  18. import info.aspirecn.iov.sjjh.supplier10000043.constant.SjjhConstant;
  19. import info.aspirecn.iov.sjjh.supplier10000043.model.*;
  20. import info.aspirecn.iov.sjjh.supplier10000043.util.DESedeUtil;
  21. import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.apache.axis.AxisFault;
  24. import org.apache.axis.AxisProperties;
  25. import org.apache.cxf.frontend.ClientProxy;
  26. import org.apache.commons.lang3.StringUtils;
  27. import org.apache.cxf.endpoint.Client;
  28. import org.apache.cxf.transport.http.HTTPConduit;
  29. import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
  30. import org.apache.tomcat.util.codec.binary.Base64;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.beans.factory.annotation.Value;
  33. import org.springframework.data.redis.core.StringRedisTemplate;
  34. import org.springframework.stereotype.Service;
  35. import javax.servlet.http.HttpServletRequest;
  36. import javax.validation.ConstraintViolation;
  37. import javax.validation.Validation;
  38. import javax.validation.Validator;
  39. import javax.validation.ValidatorFactory;
  40. import javax.xml.bind.JAXBContext;
  41. import javax.xml.bind.JAXBException;
  42. import javax.xml.bind.Unmarshaller;
  43. import javax.xml.namespace.QName;
  44. import javax.xml.rpc.encoding.XMLType;
  45. import javax.xml.ws.WebServiceException;
  46. import java.io.IOException;
  47. import java.io.StringReader;
  48. import java.net.SocketTimeoutException;
  49. import java.time.LocalDateTime;
  50. import java.time.format.DateTimeFormatter;
  51. import java.util.*;
  52. import java.util.concurrent.ConcurrentHashMap;
  53. import java.util.concurrent.TimeUnit;
  54. import java.util.concurrent.atomic.AtomicLong;
  55. /**
  56. * @description:
  57. * @author: xusonglin
  58. * @create: 2020/6/15 16:02
  59. * @version: V1.0
  60. **/
  61. @Service
  62. @Slf4j
  63. public class ChannelServiceImpl implements ChannelService {
  64. @Autowired
  65. private Tracer tracer;
  66. @Value("${supplier.url}")
  67. private String url;
  68. @Autowired
  69. private CommonUtil commonUtil;
  70. @Value("${supplier.twoElementsMethod}")
  71. private String twoElementsMethod;
  72. @Value("${supplier.photoIdentityMethod}")
  73. private String photoIdentityMethod;
  74. @Value("${supplier.decryptKey}")
  75. private String decryptKey;
  76. @Value("${supplier.urlV2}")
  77. private String urlV2;
  78. @Value("${spring.application.name}")
  79. private String applicationName;
  80. @Value("${supplier.decodeApi}")
  81. private String decodeApi;
  82. @Value("${supplier.decodeUrl}")
  83. private String decodeUrl;
  84. @Value("${supplier.decodeAppKey}")
  85. private String decodeAppKey;
  86. @Value("${supplier.decodeAppSecret}")
  87. private String decodeAppSecret;
  88. @Value("${supplier.aesDecryptKey}")
  89. private String aesDecryptKey;
  90. @Value("${supplier.urlV3}")
  91. private String urlV3;
  92. @Value("${supplier.urlV4}")
  93. private String urlV4;
  94. @Autowired
  95. SupplierProperties supplierProperties;
  96. @Autowired
  97. StringRedisTemplate stringRedisTemplate;
  98. @Autowired
  99. SmsActionInterface smsActionInterface;
  100. @Autowired
  101. ChannelActionInterface channelActionInterface;
  102. DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
  103. @Autowired
  104. private ObjectMapper objectMapper;
  105. @Override
  106. public ChannelTypeHandleResponseObject twoElementsCheck(HttpServletRequest request, String customBody, int outTime, String decodeType) {
  107. ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
  108. ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
  109. ret.setCode(Constant.SUCCESS);
  110. String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
  111. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  112. String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
  113. if (StringUtils.isBlank(returnType)) {
  114. returnType = Constant.CUSTOMER_RETURN_ZW;
  115. }
  116. if (outTime <= SjjhConstant.PARA_ZERO) {
  117. outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
  118. }
  119. log.info("supplier10000043.twoElementsCheck---customBody={},outTime={}", customBody, outTime);
  120. /* String key="url"+twoElementsMethod;
  121. LocalDateTime now = LocalDateTime.now();
  122. String ymd = dateTimeFormatter.format(now);
  123. String hashKey = "043-"+ymd;
  124. boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrlSecondUp());
  125. if(!flag){
  126. countOver(ret);
  127. return ret;
  128. }*/
  129. if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) {
  130. customBody = decodeParams(ret, returnType, customBody, decodeType);
  131. if (StringUtils.isBlank(customBody)) {
  132. // ret.setCode(Constant.SUCCESS);
  133. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  134. //reduceVisitCount(hashKey,key);
  135. return ret;
  136. }
  137. }
  138. try {
  139. TwoElementsRequestObject requestObject = objectMapper.readValue(customBody,
  140. TwoElementsRequestObject.class);
  141. log.info("supplier10000043.twoElementsCheck---requestObject={}", requestObject);
  142. // 参数校验
  143. if (!validateRequestParams(ret, returnType, requestObject)) {
  144. ret.setCode(Constant.SUCCESS);
  145. // reduceVisitCount(hashKey,key);
  146. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  147. return ret;
  148. }
  149. // 直接引用远程的wsdl文件
  150. // 以下都是套路
  151. AxisProperties.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory");
  152. org.apache.axis.client.Service service = new org.apache.axis.client.Service();
  153. org.apache.axis.client.Call call = (org.apache.axis.client.Call) service.createCall();
  154. call.setTargetEndpointAddress(url);
  155. call.setOperationName(twoElementsMethod);// WSDL里面描述的接口名称
  156. call.setTimeout(outTime);
  157. call.addParameter(SjjhConstant.PARAMETER_INLICENSE,
  158. XMLType.XSD_STRING,
  159. javax.xml.rpc.ParameterMode.IN);// 接口的参数
  160. call.addParameter(SjjhConstant.PARAMETER_INCONDITIONS,
  161. XMLType.XSD_STRING,
  162. javax.xml.rpc.ParameterMode.IN);
  163. call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
  164. String paramXml = SjjhConstant.TWO_ELEMENTS_XML_TEMPLATE
  165. .replace("{fsd}", requestObject.getIdCode().substring(0, 6))
  166. .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX)
  167. .replace("{idCode}", requestObject.getIdCode())
  168. .replace("{name}", requestObject.getName());
  169. String result = (String) call.invoke(new Object[]{SjjhConstant.TWO_ELEMENTS_SECRET_KEY, paramXml});
  170. // String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><RESPONSE errorcode=\"-20\" code=\"0\" countrows=\"1\"><ROWS><ROW><ErrorCode>-20</ErrorCode><ErrorMsg>计费失败,请与管理员联系(errorcode=-20)!</ErrorMsg></ROW></ROWS></RESPONSE>";
  171. log.info("twoElementsCheck上游返回xml:{}", result);
  172. upstreamCode = setTwoElementsCheckResponse(ret, returnType, result);
  173. } catch (SocketTimeoutException ste) {
  174. log.info("supplier10000043.twoElementsCheck接口-SocketTimeoutException:{}", ste);
  175. ErrorUtils.captureException(ste);
  176. ret.setCode(Constant.REQUEST_TIMEOUT);
  177. } catch (AxisFault axisFault) {
  178. log.info("supplier10000043.twoElementsCheck接口-AxisFaultException:{}", axisFault);
  179. ErrorUtils.captureException(axisFault);
  180. ret.setCode(Constant.REQUEST_TIMEOUT);
  181. } catch (Exception ioe) {
  182. log.info("supplier10000043.twoElementsCheck接口-Exception:{}", ioe);
  183. ErrorUtils.captureException(ioe);
  184. ret.setCode(Constant.FAIL);
  185. }
  186. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  187. return ret;
  188. }
  189. @Override
  190. public ChannelTypeHandleResponseObject twoElementsCheckNew(HttpServletRequest request, String customBody, int outTime, String decodeType) {
  191. ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
  192. ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
  193. ret.setCode(Constant.SUCCESS);
  194. String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
  195. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  196. String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
  197. if (StringUtils.isBlank(returnType)) {
  198. returnType = Constant.CUSTOMER_RETURN_ZW;
  199. }
  200. if (outTime <= SjjhConstant.PARA_ZERO) {
  201. outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
  202. }
  203. log.info("supplier10000043.twoElementsCheckNew---customBody={},outTime={}", customBody, outTime);
  204. /* String key="url"+twoElementsMethod;
  205. LocalDateTime now = LocalDateTime.now();
  206. String ymd = dateTimeFormatter.format(now);
  207. String hashKey = "043-"+ymd;
  208. boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrlSecondUp());
  209. if(!flag){
  210. countOver(ret);
  211. return ret;
  212. }*/
  213. if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) {
  214. customBody = decodeParams(ret, returnType, customBody, decodeType);
  215. if (StringUtils.isBlank(customBody)) {
  216. ret.setCode(Constant.SUCCESS);
  217. //reduceVisitCount(hashKey,key);
  218. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  219. return ret;
  220. }
  221. }
  222. try {
  223. TwoElementsRequestObject requestObject = objectMapper.readValue(customBody,
  224. TwoElementsRequestObject.class);
  225. log.info("supplier10000043.twoElementsCheckNew---requestObject={}", requestObject);
  226. // 参数校验
  227. if (!validateRequestParams(ret, returnType, requestObject)) {
  228. ret.setCode(Constant.SUCCESS);
  229. //reduceVisitCount(hashKey,key);
  230. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  231. return ret;
  232. }
  233. JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  234. factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口
  235. factory.setAddress(url);
  236. NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象
  237. // 设置客户端的配置信息,超时等.
  238. Client proxy = ClientProxy.getClient(nciicServices);
  239. HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
  240. HTTPClientPolicy policy = new HTTPClientPolicy();
  241. policy.setConnectionTimeout(outTime); // 连接超时时间
  242. policy.setReceiveTimeout(outTime);// 请求超时时间.
  243. conduit.setClient(policy);
  244. String paramXml = SjjhConstant.TWO_ELEMENTS_XML_TEMPLATE
  245. .replace("{fsd}", requestObject.getIdCode().substring(0, 6))
  246. .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX)
  247. .replace("{idCode}", requestObject.getIdCode())
  248. .replace("{name}", requestObject.getName());
  249. String result = nciicServices.nciicCheck(SjjhConstant.TWO_ELEMENTS_SECRET_KEY,paramXml);
  250. // String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><RESPONSE errorcode=\"-20\" code=\"0\" countrows=\"1\"><ROWS><ROW><ErrorCode>-20</ErrorCode><ErrorMsg>计费失败,请与管理员联系(errorcode=-20)!</ErrorMsg></ROW></ROWS></RESPONSE>";
  251. log.info("twoElementsCheck上游返回xml:{}", result);
  252. upstreamCode = setTwoElementsCheckResponse(ret, returnType, result);
  253. } catch (SocketTimeoutException ste) {
  254. log.info("supplier10000043.twoElementsCheck接口-SocketTimeoutException:{}", ste);
  255. ErrorUtils.captureException(ste);
  256. ret.setCode(Constant.REQUEST_TIMEOUT);
  257. } catch (AxisFault axisFault) {
  258. log.info("supplier10000043.twoElementsCheck接口-AxisFaultException:{}", axisFault);
  259. ErrorUtils.captureException(axisFault);
  260. ret.setCode(Constant.REQUEST_TIMEOUT);
  261. } catch (Exception ioe) {
  262. log.info("supplier10000043.twoElementsCheck接口-Exception:{}", ioe);
  263. ErrorUtils.captureException(ioe);
  264. ret.setCode(Constant.FAIL);
  265. }
  266. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  267. return ret;
  268. }
  269. private String decodeParams(ChannelTypeHandleResponseObject ret, String returnType, String customBody, String decodeType) {
  270. JSONObject requestParamObject = JSONObject.parseObject(customBody);
  271. if (decodeType.equals(SjjhConstant.DECODE_TYPE_WEIZHONG)) {
  272. if (requestParamObject.get("params") == null) {
  273. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  274. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  275. ret.setResultBody(Constant.INVALID_PARAMETER);
  276. ret.setResultDesc(Constant.INVALID_PARAMETER);
  277. } else {
  278. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  279. ret.setResultBody(Constant.INVALID_PARAMETER);
  280. ret.setResultDesc(Constant.INVALID_PARAMETER);
  281. }
  282. return "";
  283. }
  284. customBody = DESedeUtil.decryptMode(requestParamObject.getString("params"), decryptKey);
  285. if (StringUtils.isBlank(customBody)) {
  286. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  287. ret.setResultCode(Constant.ZW_RETURN_CODE_133);
  288. } else {
  289. ret.setResultCode(Constant.JK_RETURN_CODE_9931);
  290. }
  291. ret.setResultBody(Constant.RETURN_MESSAGE_133);
  292. ret.setResultDesc(Constant.RETURN_MESSAGE_133);
  293. return "";
  294. }
  295. requestParamObject = null;
  296. return customBody;
  297. }
  298. if (decodeType.equals(SjjhConstant.DECODE_TYPE_MD5) || decodeType.equals(SjjhConstant.DECODE_TYPE_SHA256)) {
  299. if (requestParamObject.get("idCode") == null || requestParamObject.get("name") == null) {
  300. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  301. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  302. } else {
  303. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  304. }
  305. ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
  306. ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
  307. return "";
  308. }
  309. if (StringUtils.isBlank(requestParamObject.getString("idCode"))
  310. || StringUtils.isBlank(requestParamObject.getString("name"))
  311. || (decodeType.equals(SjjhConstant.DECODE_TYPE_MD5)
  312. && (requestParamObject.getString("idCode").length() != 32
  313. || requestParamObject.getString("name").length() != 32))
  314. || (decodeType.equals(SjjhConstant.DECODE_TYPE_SHA256)
  315. && (requestParamObject.getString("idCode").length() != 64
  316. || requestParamObject.getString("name").length() != 64))) {
  317. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  318. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  319. } else {
  320. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  321. }
  322. ret.setResultBody(Constant.INVALID_PARAMETER);
  323. ret.setResultDesc(Constant.INVALID_PARAMETER);
  324. return "";
  325. }
  326. requestParamObject = getDecodeIdCard(requestParamObject, 10000, decodeType);
  327. if (StringUtils.isBlank(requestParamObject.getString("idCode")) || StringUtils.isBlank(requestParamObject.getString("name"))) {
  328. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  329. ret.setResultCode(Constant.ZW_RETURN_CODE_134);
  330. } else {
  331. ret.setResultCode(Constant.JK_RETURN_CODE_9932);
  332. }
  333. ret.setResultBody(Constant.RETURN_MESSAGE_134);
  334. ret.setResultDesc(Constant.RETURN_MESSAGE_134);
  335. return "";
  336. } else {
  337. customBody = JSON.toJSONString(requestParamObject);
  338. requestParamObject = null;
  339. return customBody;
  340. }
  341. }
  342. if (decodeType.equals(SjjhConstant.DECODE_TYPE_AES)) {
  343. if (requestParamObject.get("params") == null) {
  344. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  345. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  346. ret.setResultBody(Constant.INVALID_PARAMETER);
  347. ret.setResultDesc(Constant.INVALID_PARAMETER);
  348. } else {
  349. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  350. ret.setResultBody(Constant.INVALID_PARAMETER);
  351. ret.setResultDesc(Constant.INVALID_PARAMETER);
  352. }
  353. return "";
  354. }
  355. try {
  356. customBody = AesUtil.decryAES(aesDecryptKey, requestParamObject.getString("params"));
  357. if (StringUtils.isBlank(customBody)) {
  358. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  359. ret.setResultCode(Constant.ZW_RETURN_CODE_133);
  360. } else {
  361. ret.setResultCode(Constant.JK_RETURN_CODE_9931);
  362. }
  363. ret.setResultBody(Constant.RETURN_MESSAGE_133);
  364. ret.setResultDesc(Constant.RETURN_MESSAGE_133);
  365. return "";
  366. }
  367. requestParamObject = null;
  368. return customBody;
  369. } catch (Exception e) {
  370. ErrorUtils.captureException(e);
  371. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  372. ret.setResultCode(Constant.ZW_RETURN_CODE_133);
  373. } else {
  374. ret.setResultCode(Constant.JK_RETURN_CODE_9931);
  375. }
  376. ret.setResultBody(Constant.RETURN_MESSAGE_133);
  377. ret.setResultDesc(Constant.RETURN_MESSAGE_133);
  378. return "";
  379. }
  380. }
  381. return customBody;
  382. }
  383. private boolean validateRequestParams(ChannelTypeHandleResponseObject ret, String returnType,
  384. TwoElementsRequestObject requestObject) {
  385. if (!validateParamNullValue(requestObject)) {
  386. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  387. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  388. ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
  389. ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
  390. } else {
  391. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  392. ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
  393. ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
  394. }
  395. return false;
  396. } else if (StringUtils.isBlank(requestObject.getName()) ||
  397. !PatternTools.checkResult(Constant.PATTERN_SPECIAL_CN_NAME_REGEX, requestObject.getName())) {
  398. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  399. ret.setResultCode(Constant.NAME_FORMAT_ERROR_CODE);
  400. ret.setResultDesc(Constant.NAME_FORMAT_ERROR);
  401. ret.setResultBody(Constant.NAME_FORMAT_ERROR);
  402. } else {
  403. ret.setResultCode(Constant.JK_NAME_FORMAT_ERROR_CODE);
  404. ret.setResultDesc(Constant.JK_NAME_FORMAT_ERROR);
  405. ret.setResultBody(Constant.JK_NAME_FORMAT_ERROR);
  406. }
  407. return false;
  408. } else if (StringUtils.isBlank(requestObject.getIdCode())
  409. || !PatternTools.checkResult(Constant.PATTERN_SPECIAL_ID_NUMBER_REGEX, requestObject.getIdCode())) {
  410. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  411. ret.setResultCode(Constant.IDCODE_FORMAT_ERROR_CODE);
  412. ret.setResultDesc(Constant.IDCODE_FORMAT_ERROR);
  413. ret.setResultBody(Constant.IDCODE_FORMAT_ERROR);
  414. } else {
  415. ret.setResultCode(Constant.JK_IDCODE_FORMAT_ERROR_CODE);
  416. ret.setResultDesc(Constant.JK_IDCODE_FORMAT_ERROR);
  417. ret.setResultBody(Constant.JK_IDCODE_FORMAT_ERROR);
  418. }
  419. return false;
  420. } else {
  421. return true;
  422. }
  423. }
  424. private boolean validateParamNullValue(Object jsonResolveObject) {
  425. ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
  426. Validator validator = vf.getValidator();
  427. Set<ConstraintViolation<Object>> set = validator.validate(jsonResolveObject);
  428. for (ConstraintViolation<Object> con : set) {
  429. if (StringUtils.isNotBlank(con.getMessage())) {
  430. return false;
  431. }
  432. }
  433. return true;
  434. }
  435. private String setTwoElementsCheckResponse(ChannelTypeHandleResponseObject ret, String returnType, String responseXml) {
  436. String resultCode;
  437. try {
  438. if (responseXml.contains(SjjhConstant.RESULT_NOT_FIND)) {
  439. resultCode = SjjhConstant.REQUEST_NOT_FIND;
  440. setNotFindResponse(ret, returnType);
  441. } /*else if (responseXml.contains(SjjhConstant.ERROR_CODE)) {
  442. resultCode = setErrorResponse(ret, returnType, responseXml);
  443. if("-53".equals(resultCode)){
  444. String hashKey = commonUtil.getKey();
  445. boolean flag = stringRedisTemplate.boundHashOps(hashKey).putIfAbsent(SjjhConstant.secondKey,true);
  446. if(flag){
  447. Map map = SjjhConstant.hashMap.get(hashKey);
  448. if(map==null){
  449. SjjhConstant.hashMap.put(hashKey,map);
  450. }
  451. map.put(SjjhConstant.secondKey,true);
  452. }
  453. ret.setCode(Constant.REQUEST_TIMEOUT);
  454. return resultCode;
  455. }
  456. }*/
  457. else {
  458. resultCode = SjjhConstant.REQUEST_SUCCESS;
  459. setTwoElementsCheckSuccessResponse(ret, returnType, responseXml);
  460. }
  461. ret.setCode(Constant.SUCCESS);
  462. } catch (JAXBException jaxb) {
  463. resultCode = SjjhConstant.PARSE_FAILURE;
  464. log.info("supplier10000043.twoElementsCheck接口-解析上游返回xml失败:{}", jaxb.getMessage());
  465. ErrorUtils.captureException(jaxb);
  466. ret.setCode(Constant.FAIL);
  467. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  468. ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
  469. } else {
  470. ret.setResultCode(Constant.OTHER_ERROR_CODE);
  471. }
  472. ret.setResultBody(Constant.OTHER_ERROR);
  473. ret.setResultDesc(Constant.OTHER_ERROR);
  474. }
  475. return resultCode;
  476. }
  477. private void setNotFindResponse(ChannelTypeHandleResponseObject ret, String returnType) {
  478. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  479. ret.setResultCode(Constant.JK_RETURN_CODE_NO_INFO);
  480. } else {
  481. ret.setResultCode(Constant.UN_FIND_NUM_CODE);
  482. }
  483. ret.setResultBody(Constant.UN_FIND_NUM);
  484. ret.setResultDesc(Constant.UN_FIND_NUM);
  485. }
  486. private void setTwoElementsCheckSuccessResponse(ChannelTypeHandleResponseObject ret, String returnType, String responseXml) throws JAXBException {
  487. JAXBContext context = JAXBContext.newInstance(TwoElementResponseObject.class);
  488. Unmarshaller unmarshaller = context.createUnmarshaller();
  489. TwoElementResponseObject responseObject = (TwoElementResponseObject) unmarshaller.unmarshal(new StringReader(responseXml));
  490. String result = SjjhConstant.RESULT_MATCH;
  491. List<TwoElementResponseObject.NciicCheckResponseItem> items = responseObject.getRow().get(0).getOutput().getItems();
  492. for (TwoElementResponseObject.NciicCheckResponseItem item : items) {
  493. if (item.getIdCodeResult() != null && item.getIdCodeResult().equals(SjjhConstant.RESULT_UN_MATCH)) {
  494. result = SjjhConstant.RESULT_UN_MATCH;
  495. }
  496. if (item.getNameResult() != null && item.getNameResult().equals(SjjhConstant.RESULT_UN_MATCH)) {
  497. result = SjjhConstant.RESULT_UN_MATCH;
  498. }
  499. }
  500. if (result.equals(SjjhConstant.RESULT_MATCH)) {
  501. // 一致
  502. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  503. ret.setResultCode(Constant.JK_RETURN_CODE_MATCH);
  504. } else {
  505. ret.setResultCode(Constant.MATCH_CODE);
  506. }
  507. ret.setResultBody(Constant.MATCH);
  508. ret.setResultDesc(Constant.MATCH);
  509. } else {
  510. // 不一致
  511. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  512. ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH);
  513. } else {
  514. ret.setResultCode(Constant.UN_MATCH_CODE);
  515. }
  516. ret.setResultBody(Constant.UN_MATCH);
  517. ret.setResultDesc(Constant.UN_MATCH);
  518. }
  519. ret.setIsCharge(Constant.IS_CHARGE);
  520. }
  521. public String setErrorResponse(ChannelTypeHandleResponseObject ret, String returnType, String responseXml) throws JAXBException {
  522. JAXBContext context = JAXBContext.newInstance(ErrorResponseObject.class);
  523. Unmarshaller unmarshaller = context.createUnmarshaller();
  524. ErrorResponseObject errorResponseObject = (ErrorResponseObject) unmarshaller.unmarshal(new StringReader(responseXml));
  525. // 查询错误
  526. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  527. ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
  528. } else {
  529. ret.setResultCode(Constant.OTHER_ERROR_CODE);
  530. }
  531. ret.setResultBody(Constant.OTHER_ERROR);
  532. ret.setResultDesc(Constant.OTHER_ERROR);
  533. return errorResponseObject.getRow().getRowObject().getErrorCode();
  534. }
  535. @Override
  536. public ChannelTypeHandleResponseObject photoIdentityCheck(HttpServletRequest request, String customBody, int outTime, String decodeType) {
  537. ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
  538. ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
  539. ret.setCode(Constant.SUCCESS);
  540. String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
  541. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  542. String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
  543. String channelId = request.getHeader("channelId");
  544. if (StringUtils.isBlank(returnType)) {
  545. returnType = Constant.CUSTOMER_RETURN_ZW;
  546. }
  547. if (outTime <= SjjhConstant.PARA_ZERO) {
  548. outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
  549. }
  550. String key="url"+photoIdentityMethod;
  551. LocalDateTime now = LocalDateTime.now();
  552. String ymd = dateTimeFormatter.format(now);
  553. String hashKey = "043-"+ymd;
  554. boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrlPhotoUp(),channelId);
  555. if(!flag){
  556. countOver(ret,returnType);
  557. return ret;
  558. }
  559. log.info("supplier10000043.photoIdentityCheck---customBody={},outTime={}", customBody, outTime);
  560. if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) {
  561. customBody = decodeParams(ret, returnType, customBody, decodeType);
  562. if (StringUtils.isBlank(customBody)) {
  563. ret.setCode(Constant.SUCCESS);
  564. reduceVisitCount(hashKey,key);
  565. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  566. return ret;
  567. }
  568. }
  569. try {
  570. JSONObject jsonObject = JSON.parseObject(customBody);
  571. String name = jsonObject.getString("name");//requestObject.getName();
  572. String idCode = jsonObject.getString("idCode");
  573. String photo = jsonObject.getString("photo");
  574. customBody = null;
  575. jsonObject.put("photo", "图片base64");
  576. request.setAttribute(Constant.CHANNEL_LOG_QUERY,
  577. Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE)));
  578. jsonObject = null;
  579. if(!checkParm(name,idCode,returnType,ret)){
  580. reduceVisitCount(hashKey,key);
  581. return ret;
  582. }
  583. /* JSONObject jsonObject = JSON.parseObject(customBody);
  584. jsonObject.put("photo","图片base64");
  585. request.setAttribute(Constant.CHANNEL_LOG_QUERY,
  586. Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE)));
  587. PhotoIdentityRequestObject requestObject = objectMapper.readValue(customBody,
  588. PhotoIdentityRequestObject.class);
  589. // 参数校验
  590. if (!validateRequestParams(ret, returnType, requestObject)) {
  591. ret.setCode(Constant.SUCCESS);
  592. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  593. return ret;
  594. }*/
  595. JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  596. factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口
  597. factory.setAddress(url);//"http://127.0.0.1/nciic_ws/services/NciicServices"
  598. NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象
  599. // 设置客户端的配置信息,超时等.
  600. Client proxy = ClientProxy.getClient(nciicServices);
  601. HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
  602. HTTPClientPolicy policy = new HTTPClientPolicy();
  603. policy.setConnectionTimeout(outTime); // 连接超时时间
  604. policy.setReceiveTimeout(outTime);// 请求超时时间.
  605. conduit.setClient(policy);
  606. String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE
  607. .replace("{fsd}", idCode.substring(0, 6))
  608. .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX)
  609. .replace("{idCode}", idCode)
  610. .replace("{name}", name)
  611. .replace("{photo}", photo);
  612. photo = null;
  613. //String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ROWS><ROW no=\"1\"><INPUT><gmsfhm>610430199209130514</gmsfhm><xm>于博博</xm></INPUT><OUTPUT><ITEM><errormesage>服务结果:上传相片质量校验不合格,请重新拍摄上传</errormesage></ITEM><ITEM><errormesagecol></errormesagecol></ITEM></OUTPUT></ROW></ROWS>";
  614. String result = nciicServices.nciicCompare(SjjhConstant.PHOTO_IDENTITY_SECRET_KEY, paramXml);
  615. log.info("photoIdentityCheck上游返回xml:{}", result);
  616. upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result,key+SjjhConstant.key_subStr,channelId);
  617. // 直接引用远程的wsdl文件
  618. // 以下都是套路
  619. /* AxisProperties.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory");
  620. org.apache.axis.client.Service service = new org.apache.axis.client.Service();
  621. org.apache.axis.client.Call call = (org.apache.axis.client.Call) service.createCall();
  622. call.setTargetEndpointAddress(url);
  623. call.setOperationName(photoIdentityMethod);// WSDL里面描述的接口名称
  624. call.setTimeout(outTime);
  625. call.addParameter(SjjhConstant.PARAMETER_INLICENSE,
  626. XMLType.XSD_STRING,
  627. javax.xml.rpc.ParameterMode.IN);// 接口的参数
  628. call.addParameter(SjjhConstant.PARAMETER_INCONDITIONS,
  629. XMLType.XSD_STRING,
  630. javax.xml.rpc.ParameterMode.IN);
  631. call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
  632. String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE
  633. .replace("{fsd}", idCode.substring(0, 6))
  634. .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX)
  635. .replace("{idCode}", idCode)
  636. .replace("{name}", name)
  637. .replace("{photo}", photo);
  638. String result = (String) call.invoke(new Object[]{SjjhConstant.PHOTO_IDENTITY_SECRET_KEY, paramXml});
  639. // String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ROWS><ROW no=\"1\"><INPUT><gmsfhm>610430199209130514</gmsfhm><xm>于博博</xm></INPUT><OUTPUT><ITEM><errormesage>服务结果:上传相片质量校验不合格,请重新拍摄上传</errormesage></ITEM><ITEM><errormesagecol></errormesagecol></ITEM></OUTPUT></ROW></ROWS>";
  640. log.info("photoIdentityCheck上游返回xml:{}", result);
  641. upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result);*/
  642. } catch (WebServiceException ste) {
  643. log.info("supplier10000043.photoIdentityCheck接口-SocketTimeoutException:{}", ste);
  644. ErrorUtils.captureException(ste);
  645. ret.setCode(Constant.REQUEST_TIMEOUT);
  646. } catch (Exception ioe) {
  647. log.info("supplier10000043.photoIdentityCheck接口-Exception:{}", ioe);
  648. ErrorUtils.captureException(ioe);
  649. ret.setCode(Constant.FAIL);
  650. }
  651. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  652. return ret;
  653. }
  654. public boolean checkParm(String name,String idCode,String returnType,ChannelTypeHandleResponseObject ret){
  655. if (StringUtils.isBlank(name) || StringUtils.isBlank(idCode)) {
  656. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  657. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  658. ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
  659. ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
  660. } else {
  661. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  662. ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
  663. ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
  664. }
  665. return false;
  666. } else if (StringUtils.isBlank(name) ||
  667. !PatternTools.checkResult(Constant.PATTERN_SPECIAL_CN_NAME_REGEX, name)) {
  668. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  669. ret.setResultCode(Constant.NAME_FORMAT_ERROR_CODE);
  670. ret.setResultDesc(Constant.NAME_FORMAT_ERROR);
  671. ret.setResultBody(Constant.NAME_FORMAT_ERROR);
  672. } else {
  673. ret.setResultCode(Constant.JK_NAME_FORMAT_ERROR_CODE);
  674. ret.setResultDesc(Constant.JK_NAME_FORMAT_ERROR);
  675. ret.setResultBody(Constant.JK_NAME_FORMAT_ERROR);
  676. }
  677. return false;
  678. } else if (StringUtils.isBlank(idCode)
  679. || !PatternTools.checkResult(Constant.PATTERN_SPECIAL_ID_NUMBER_REGEX, idCode)) {
  680. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  681. ret.setResultCode(Constant.IDCODE_FORMAT_ERROR_CODE);
  682. ret.setResultDesc(Constant.IDCODE_FORMAT_ERROR);
  683. ret.setResultBody(Constant.IDCODE_FORMAT_ERROR);
  684. } else {
  685. ret.setResultCode(Constant.JK_IDCODE_FORMAT_ERROR_CODE);
  686. ret.setResultDesc(Constant.JK_IDCODE_FORMAT_ERROR);
  687. ret.setResultBody(Constant.JK_IDCODE_FORMAT_ERROR);
  688. }
  689. return false;
  690. }
  691. return true;
  692. }
  693. @Override
  694. public ChannelTypeHandleResponseObject photoIdentityCheckNew(HttpServletRequest request, String customBody, int outTime, String decodeType) {
  695. ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
  696. ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
  697. ret.setCode(Constant.SUCCESS);
  698. String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
  699. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  700. String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
  701. if (StringUtils.isBlank(returnType)) {
  702. returnType = Constant.CUSTOMER_RETURN_ZW;
  703. }
  704. if (outTime <= SjjhConstant.PARA_ZERO) {
  705. outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
  706. }
  707. String channelId = request.getHeader("channelId");
  708. String key="url"+photoIdentityMethod;
  709. LocalDateTime now = LocalDateTime.now();
  710. String ymd = dateTimeFormatter.format(now);
  711. String hashKey = "043-"+ymd;
  712. boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrlPhotoUp(),channelId);
  713. if(!flag){
  714. countOver(ret,returnType);
  715. return ret;
  716. }
  717. log.info("supplier10000043.photoIdentityCheck---customBody={},outTime={}", customBody, outTime);
  718. if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) {
  719. customBody = decodeParams(ret, returnType, customBody, decodeType);
  720. if (StringUtils.isBlank(customBody)) {
  721. ret.setCode(Constant.SUCCESS);
  722. reduceVisitCount(hashKey,key);
  723. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  724. return ret;
  725. }
  726. }
  727. try {
  728. JSONObject jsonObject = JSON.parseObject(customBody);
  729. String name = jsonObject.getString("name");//requestObject.getName();
  730. String idCode = jsonObject.getString("idCode");
  731. String photo = jsonObject.getString("photo");
  732. customBody = null;
  733. jsonObject.put("photo", "图片base64");
  734. request.setAttribute(Constant.CHANNEL_LOG_QUERY,
  735. Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE)));
  736. jsonObject = null;
  737. if(!checkParm(name,idCode,returnType,ret)){
  738. reduceVisitCount(hashKey,key);
  739. return ret;
  740. }
  741. // 直接引用远程的wsdl文件
  742. JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  743. factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口
  744. factory.setAddress(url);//"http://127.0.0.1/nciic_ws/services/NciicServices"
  745. NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象
  746. // 设置客户端的配置信息,超时等.
  747. Client proxy = ClientProxy.getClient(nciicServices);
  748. HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
  749. HTTPClientPolicy policy = new HTTPClientPolicy();
  750. policy.setConnectionTimeout(outTime); // 连接超时时间
  751. policy.setReceiveTimeout(outTime);// 请求超时时间.
  752. conduit.setClient(policy);
  753. String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE
  754. .replace("{fsd}", idCode.substring(0, 6))
  755. .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX)
  756. .replace("{idCode}", idCode)
  757. .replace("{name}", name)
  758. .replace("{photo}", photo);
  759. photo = null;
  760. //String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ROWS><ROW no=\"1\"><INPUT><gmsfhm>610430199209130514</gmsfhm><xm>于博博</xm></INPUT><OUTPUT><ITEM><errormesage>服务结果:上传相片质量校验不合格,请重新拍摄上传</errormesage></ITEM><ITEM><errormesagecol></errormesagecol></ITEM></OUTPUT></ROW></ROWS>";
  761. String result = nciicServices.nciicCompare(SjjhConstant.PHOTO_IDENTITY_SECRET_KEY, paramXml);
  762. log.info("photoIdentityCheck上游返回xml:{}", result);
  763. upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result,key+SjjhConstant.key_subStr,channelId);
  764. }catch (WebServiceException exception){
  765. log.info("supplier10000043.photoIdentityCheck接口-WebServiceException:{}", exception);
  766. ErrorUtils.captureException(exception);
  767. ret.setCode(Constant.REQUEST_TIMEOUT);
  768. } catch (Exception ioe) {
  769. log.info("supplier10000043.photoIdentityCheck接口-Exception:{}", ioe);
  770. ErrorUtils.captureException(ioe);
  771. ret.setCode(Constant.FAIL);
  772. }
  773. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  774. return ret;
  775. }
  776. private String setPhotoIdentityCheckResponse(ChannelTypeHandleResponseObject ret, String returnType, String responseXml,String key,String channelId) {
  777. String resultCode;
  778. try {
  779. if (responseXml.contains(SjjhConstant.RESULT_NOT_FIND)) {
  780. resultCode = SjjhConstant.REQUEST_NOT_FIND;
  781. setNotFindResponse(ret, returnType);
  782. }else if (responseXml.contains(SjjhConstant.ERROR_CODE)) {
  783. resultCode = setErrorResponse(ret, returnType, responseXml);
  784. if("-53".equals(resultCode)){
  785. //不是规定时间出现的,只是超时,进行切换
  786. ret.setCode(Constant.REQUEST_TIMEOUT);
  787. //时间范围判断
  788. int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
  789. if(hour>=supplierProperties.getHour()){
  790. String hashKey = commonUtil.getKey();
  791. boolean flag = stringRedisTemplate.boundHashOps(hashKey).putIfAbsent(key,"1");
  792. if(flag){
  793. testNotify(channelId,3);
  794. }
  795. //规定的时间之后出现的,才是达量,覆盖超时码
  796. ret.setCode(Constant.REQUEST_LIMIT);
  797. }
  798. return resultCode;
  799. }
  800. } else if (responseXml.contains(SjjhConstant.ERROR_MESSAGE)) {
  801. resultCode = SjjhConstant.REQUEST_ERROR;
  802. setPhotoIdentityErrorResponse(ret, returnType, responseXml);
  803. } else {
  804. resultCode = SjjhConstant.REQUEST_SUCCESS;
  805. setPhotoIdentityCheckSuccessResponse(ret, returnType, responseXml);
  806. }
  807. ret.setCode(Constant.SUCCESS);
  808. } catch (JAXBException jaxb) {
  809. resultCode = SjjhConstant.PARSE_FAILURE;
  810. log.info("supplier10000043.setPhotoIdentityCheckResponse接口-解析上游返回xml失败:{}", jaxb.getMessage());
  811. ErrorUtils.captureException(jaxb);
  812. ret.setCode(Constant.FAIL);
  813. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  814. ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
  815. } else {
  816. ret.setResultCode(Constant.OTHER_ERROR_CODE);
  817. }
  818. ret.setResultBody(Constant.OTHER_ERROR);
  819. ret.setResultDesc(Constant.OTHER_ERROR);
  820. }
  821. return resultCode;
  822. }
  823. private void setPhotoIdentityCheckSuccessResponse(ChannelTypeHandleResponseObject ret, String returnType,
  824. String responseXml) throws JAXBException {
  825. JAXBContext context = JAXBContext.newInstance(PhotoIdentityResponseObject.class);
  826. Unmarshaller unmarshaller = context.createUnmarshaller();
  827. PhotoIdentityResponseObject responseObject = (PhotoIdentityResponseObject) unmarshaller.unmarshal(new StringReader(responseXml));
  828. String idCodeNameResult = SjjhConstant.RESULT_MATCH;
  829. String photoResult = "";
  830. String photoResultScore = "";
  831. List<PhotoIdentityResponseObject.PhotoIdentityResponseItem> items = responseObject.getRow().get(0).getOutput().getItems();
  832. for (PhotoIdentityResponseObject.PhotoIdentityResponseItem item : items) {
  833. if (item.getIdCodeResult() != null && item.getIdCodeResult().equals(SjjhConstant.RESULT_UN_MATCH)) {
  834. idCodeNameResult = SjjhConstant.RESULT_UN_MATCH;
  835. }
  836. if (item.getNameResult() != null && item.getNameResult().equals(SjjhConstant.RESULT_UN_MATCH)) {
  837. idCodeNameResult = SjjhConstant.RESULT_UN_MATCH;
  838. }
  839. if (StringUtils.isNotBlank(item.getPhotoResult())) {
  840. photoResult = item.getPhotoResult();
  841. }
  842. if (StringUtils.isNotBlank(item.getPhotoResultScore())) {
  843. photoResultScore = item.getPhotoResultScore();
  844. }
  845. }
  846. JSONObject resultObject = new JSONObject();
  847. resultObject.put("verificationScore", photoResultScore);
  848. if (idCodeNameResult.equals(SjjhConstant.RESULT_MATCH)) {
  849. if (photoResult.equals(SjjhConstant.RESPONSE_PHOTO_MATCH)) {
  850. // 身份证号与姓名匹配,系统判断为同一人
  851. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  852. ret.setResultCode(Constant.JK_RETURN_CODE_1143);
  853. } else {
  854. ret.setResultCode(Constant.ZW_RETURN_CODE_68);
  855. }
  856. resultObject.put("message", Constant.RETURN_MESSAGE_68);
  857. ret.setResultBody(resultObject.toJSONString());
  858. ret.setResultDesc(resultObject.toJSONString());
  859. } else if (photoResult.equals(SjjhConstant.RESPONSE_PHOTO_UN_MATCH)) {
  860. // 身份证号与姓名匹配,系统判断为不同人
  861. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  862. ret.setResultCode(Constant.JK_RETURN_CODE_1145);
  863. } else {
  864. ret.setResultCode(Constant.ZW_RETURN_CODE_70);
  865. }
  866. resultObject.put("message", Constant.RETURN_MESSAGE_70);
  867. ret.setResultBody(resultObject.toJSONString());
  868. ret.setResultDesc(resultObject.toJSONString());
  869. } else if (photoResult.equals(SjjhConstant.RESPONSE_PHOTO_UNCERTAINTY)) {
  870. // 身份证号与姓名匹配,不能确定是否为同一人
  871. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  872. ret.setResultCode(Constant.JK_RETURN_CODE_1144);
  873. } else {
  874. ret.setResultCode(Constant.ZW_RETURN_CODE_69);
  875. }
  876. resultObject.put("message", Constant.RETURN_MESSAGE_69);
  877. ret.setResultBody(resultObject.toJSONString());
  878. ret.setResultDesc(resultObject.toJSONString());
  879. } else if (photoResult.equals(SjjhConstant.RESPONSE_NO_PHOTO)) {
  880. // 身份证号与姓名匹配,库中无照片
  881. // 修改日期:2020-11-11
  882. // 修改原因:开发时上游文档没有“库中无照片”的说明,客户需要将库中无照片与照片检测失败两个message区分开,返回码为1147
  883. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  884. ret.setResultCode(Constant.JK_RETURN_CODE_1147);
  885. } else {
  886. ret.setResultCode(Constant.ZW_RETURN_CODE_72);
  887. }
  888. resultObject.put("message", Constant.RETURN_MESSAGE_72);
  889. ret.setResultBody(resultObject.toJSONString());
  890. ret.setResultDesc(resultObject.toJSONString());
  891. } else {
  892. // 身份证号与姓名匹配,照片检测失败
  893. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  894. ret.setResultCode(Constant.JK_RETURN_CODE_1148);
  895. } else {
  896. ret.setResultCode(Constant.ZW_RETURN_CODE_73);
  897. }
  898. resultObject.put("message", Constant.RETURN_MESSAGE_73);
  899. ret.setResultBody(resultObject.toJSONString());
  900. ret.setResultDesc(resultObject.toJSONString());
  901. }
  902. ret.setIsCharge(Constant.IS_CHARGE);
  903. } else {
  904. // 身份证号与姓名不匹配
  905. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  906. ret.setResultCode(Constant.JK_RETURN_CODE_1146);
  907. } else {
  908. ret.setResultCode(Constant.ZW_RETURN_CODE_71);
  909. }
  910. resultObject.put("message", Constant.RETURN_MESSAGE_71);
  911. ret.setResultBody(resultObject.toJSONString());
  912. ret.setResultDesc(resultObject.toJSONString());
  913. ret.setIsCharge(Constant.IS_CHARGE);
  914. }
  915. }
  916. private void setPhotoIdentityErrorResponse(ChannelTypeHandleResponseObject ret,
  917. String returnType, String responseXml) throws JAXBException {
  918. JAXBContext context = JAXBContext.newInstance(PhotoIdentityErrorResponseObject.class);
  919. Unmarshaller unmarshaller = context.createUnmarshaller();
  920. PhotoIdentityErrorResponseObject errorResponseObject = (PhotoIdentityErrorResponseObject) unmarshaller.unmarshal(new StringReader(responseXml));
  921. JSONObject resultObject = new JSONObject();
  922. String errorMessage = "";
  923. for (PhotoIdentityErrorResponseObject.PhotoIdentityErrorResponseItem item : errorResponseObject.getRow().get(0).getOutput().getItem()) {
  924. if (StringUtils.isNotBlank(item.getErrorMesage())) {
  925. errorMessage = item.getErrorMesage();
  926. }
  927. }
  928. if (errorMessage.equals(SjjhConstant.RESPONSE_ERROR_PHOTO_QUALITY)
  929. || errorMessage.equals(SjjhConstant.RESPONSE_ERROR_PHOTO_SIZE)) {
  930. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  931. ret.setResultCode(Constant.JK_RETURN_CODE_1149);
  932. } else {
  933. ret.setResultCode(Constant.ZW_RETURN_CODE_74);
  934. }
  935. resultObject.put("message", Constant.RETURN_MESSAGE_74);
  936. resultObject.put("verificationScore", "");
  937. ret.setResultBody(resultObject.toJSONString());
  938. ret.setResultDesc(resultObject.toJSONString());
  939. } else {
  940. // 查询错误
  941. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  942. ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
  943. } else {
  944. ret.setResultCode(Constant.OTHER_ERROR_CODE);
  945. }
  946. ret.setResultBody(Constant.OTHER_ERROR);
  947. ret.setResultDesc(Constant.OTHER_ERROR);
  948. }
  949. }
  950. @Override
  951. public ChannelTypeHandleResponseObject photoIdentityCheckV2(HttpServletRequest request, String customBody, int outTime, String decodeType) {
  952. ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
  953. ret.setCode(Constant.SUCCESS);
  954. ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
  955. String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
  956. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  957. String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
  958. if (StringUtils.isBlank(returnType)) {
  959. returnType = Constant.CUSTOMER_RETURN_ZW;
  960. }
  961. if (outTime <= SjjhConstant.PARA_ZERO) {
  962. outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
  963. }
  964. String channelId = request.getHeader("channelId");
  965. String key="url2"+photoIdentityMethod;
  966. LocalDateTime now = LocalDateTime.now();
  967. String ymd = dateTimeFormatter.format(now);
  968. String hashKey = "043-"+ymd;
  969. boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrl2PhotoUp(),channelId);
  970. if(!flag){
  971. countOver(ret,returnType);
  972. return ret;
  973. }
  974. log.info("supplier10000043.photoIdentityCheckV2---customBody={},outTime={}", customBody, outTime);
  975. if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) {
  976. customBody = decodeParams(ret, returnType, customBody, decodeType);
  977. if (StringUtils.isBlank(customBody)) {
  978. reduceVisitCount(hashKey,key);
  979. ret.setCode(Constant.SUCCESS);
  980. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  981. return ret;
  982. }
  983. }
  984. try {
  985. JSONObject jsonObject = JSON.parseObject(customBody);
  986. String name = jsonObject.getString("name");//requestObject.getName();
  987. String idCode = jsonObject.getString("idCode");
  988. String photo = jsonObject.getString("photo");
  989. customBody = null;
  990. jsonObject.put("photo", "图片base64");
  991. request.setAttribute(Constant.CHANNEL_LOG_QUERY,
  992. Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE)));
  993. jsonObject = null;
  994. if(!checkParm(name,idCode,returnType,ret)){
  995. reduceVisitCount(hashKey,key);
  996. return ret;
  997. }
  998. JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  999. factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口
  1000. factory.setAddress(urlV2);
  1001. NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象
  1002. // 设置客户端的配置信息,超时等.
  1003. Client proxy = ClientProxy.getClient(nciicServices);
  1004. HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
  1005. HTTPClientPolicy policy = new HTTPClientPolicy();
  1006. policy.setConnectionTimeout(outTime); // 连接超时时间
  1007. policy.setReceiveTimeout(outTime);// 请求超时时间.
  1008. conduit.setClient(policy);
  1009. String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE_V2
  1010. .replace("{fsd}", idCode.substring(0, 6))
  1011. .replace("{ywlx}", SjjhConstant.PARAMETER_JZSC)
  1012. .replace("{idCode}", idCode)
  1013. .replace("{name}", name)
  1014. .replace("{photo}", photo);
  1015. String result = nciicServices.nciicCompare(SjjhConstant.PHOTO_IDENTITY_SECRET_KEY_V2,paramXml);
  1016. log.info("photoIdentityCheck上游返回xml:{}", result);
  1017. upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result,key+SjjhConstant.key_subStr,channelId);
  1018. } catch (WebServiceException ste) {
  1019. log.info("supplier10000043.photoIdentityCheckV2接口-WebServiceException:{}", ste);
  1020. ErrorUtils.captureException(ste);
  1021. ret.setCode(Constant.REQUEST_TIMEOUT);
  1022. } catch (Exception ioe) {
  1023. log.info("supplier10000043.photoIdentityCheckV2接口-Exception:{}", ioe);
  1024. ErrorUtils.captureException(ioe);
  1025. ret.setCode(Constant.FAIL);
  1026. }
  1027. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  1028. return ret;
  1029. }
  1030. public ChannelTypeHandleResponseObject photoIdentityCheckV2New(HttpServletRequest request, String customBody, int outTime, String decodeType) {
  1031. ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
  1032. ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
  1033. ret.setCode(Constant.SUCCESS);
  1034. String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
  1035. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  1036. String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
  1037. if (StringUtils.isBlank(returnType)) {
  1038. returnType = Constant.CUSTOMER_RETURN_ZW;
  1039. }
  1040. if (outTime <= SjjhConstant.PARA_ZERO) {
  1041. outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
  1042. }
  1043. String channelId = request.getHeader("channelId");
  1044. String key="url2"+photoIdentityMethod;
  1045. LocalDateTime now = LocalDateTime.now();
  1046. String ymd = dateTimeFormatter.format(now);
  1047. String hashKey = "043-"+ymd;
  1048. boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrl2PhotoUp(),channelId);
  1049. if(!flag){
  1050. countOver(ret,returnType);
  1051. return ret;
  1052. }
  1053. log.info("supplier10000043.photoIdentityCheckV2New---customBody={},outTime={}", customBody, outTime);
  1054. if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) {
  1055. customBody = decodeParams(ret, returnType, customBody, decodeType);
  1056. if (StringUtils.isBlank(customBody)) {
  1057. reduceVisitCount(hashKey,key);
  1058. ret.setCode(Constant.SUCCESS);
  1059. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  1060. return ret;
  1061. }
  1062. }
  1063. try {
  1064. JSONObject jsonObject = JSON.parseObject(customBody);
  1065. String name = jsonObject.getString("name");//requestObject.getName();
  1066. String idCode = jsonObject.getString("idCode");
  1067. String photo = jsonObject.getString("photo");
  1068. customBody = null;
  1069. jsonObject.put("photo", "图片base64");
  1070. request.setAttribute(Constant.CHANNEL_LOG_QUERY,
  1071. Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE)));
  1072. jsonObject = null;
  1073. if(!checkParm(name,idCode,returnType,ret)){
  1074. reduceVisitCount(hashKey,key);
  1075. return ret;
  1076. }
  1077. JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  1078. factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口
  1079. factory.setAddress(urlV2);
  1080. NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象
  1081. // 设置客户端的配置信息,超时等.
  1082. Client proxy = ClientProxy.getClient(nciicServices);
  1083. HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
  1084. HTTPClientPolicy policy = new HTTPClientPolicy();
  1085. policy.setConnectionTimeout(outTime); // 连接超时时间
  1086. policy.setReceiveTimeout(outTime);// 请求超时时间.
  1087. conduit.setClient(policy);
  1088. String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE_V2
  1089. .replace("{fsd}", idCode.substring(0, 6))
  1090. .replace("{ywlx}", SjjhConstant.PARAMETER_JZSC)
  1091. .replace("{idCode}", idCode)
  1092. .replace("{name}", name)
  1093. .replace("{photo}", photo);
  1094. String result = nciicServices.nciicCompare(SjjhConstant.PHOTO_IDENTITY_SECRET_KEY_V2,paramXml);
  1095. log.info("photoIdentityCheck上游返回xml:{}", result);
  1096. upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result,key+SjjhConstant.key_subStr,channelId);
  1097. }catch (WebServiceException exception){
  1098. log.info("supplier10000043.photoIdentityCheck接口-WebServiceException:{}", exception);
  1099. ErrorUtils.captureException(exception);
  1100. ret.setCode(Constant.REQUEST_TIMEOUT);
  1101. } catch (Exception ioe) {
  1102. log.info("supplier10000043.photoIdentityCheckV2New接口-Exception:{}", ioe);
  1103. ErrorUtils.captureException(ioe);
  1104. ret.setCode(Constant.FAIL);
  1105. }
  1106. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  1107. return ret;
  1108. }
  1109. public boolean checkVisitCount(String hashKey,String key,long upCount,String channelId){
  1110. //查看是否有超过权限的标志
  1111. /*Map map =SjjhConstant.hashMap.get(hashKey);
  1112. if(map!=null&&map.get(key+SjjhConstant.key_subStr)!=null && map.get(key+SjjhConstant.key_subStr).equals(Boolean.TRUE)){
  1113. return false;
  1114. }*/
  1115. String countStr = (String)stringRedisTemplate.boundHashOps(hashKey).get(key);
  1116. log.info("countStr:{}",countStr);
  1117. if(countStr!=null && Long.parseLong(countStr)>=upCount){
  1118. return false;
  1119. }
  1120. if(stringRedisTemplate.boundHashOps(hashKey).hasKey(key+SjjhConstant.key_subStr)){
  1121. return false;
  1122. }
  1123. long visitCount = stringRedisTemplate.boundHashOps(hashKey).increment(key,1);
  1124. if(visitCount==1){
  1125. stringRedisTemplate.boundValueOps(hashKey).expire(1, TimeUnit.DAYS);
  1126. }
  1127. if(upCount-visitCount==supplierProperties.getNotityLimit()){
  1128. //起一个线程,处理此逻辑
  1129. testNotify(channelId,1);
  1130. }
  1131. if(upCount-visitCount==0){
  1132. //起一个线程,处理此逻辑,
  1133. testNotify(channelId,2);
  1134. }
  1135. if(visitCount>upCount){
  1136. reduceVisitCount(hashKey,key);
  1137. return false;
  1138. }
  1139. return true;
  1140. }
  1141. private JSONObject getDecodeIdCard(JSONObject requestParamObject, Integer outTime, String decodeType) {
  1142. DecodeThreeElementRequestObject.DecodeThreeElementRequestData dataObject = new DecodeThreeElementRequestObject.DecodeThreeElementRequestData();
  1143. dataObject.setId_number(requestParamObject.getString("idCode"));
  1144. dataObject.setName(requestParamObject.getString("name"));
  1145. dataObject.setEncrypt(decodeType);
  1146. DecodeThreeElementRequestObject requestObject = new DecodeThreeElementRequestObject();
  1147. requestObject.setApi(decodeApi);
  1148. requestObject.setAppKey(decodeAppKey);
  1149. requestObject.setAppSecret(decodeAppSecret);
  1150. requestObject.setData(dataObject);
  1151. MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
  1152. RequestBody requestBody = RequestBody.create(mediaType, JSON.toJSONString(requestObject));
  1153. Request okHttpRequest = new Request.Builder()
  1154. .post(requestBody)
  1155. .url(decodeUrl)
  1156. .build();
  1157. OkHttpClient decodeClient = new OkHttpClient.Builder()
  1158. .connectTimeout(outTime, TimeUnit.MILLISECONDS)
  1159. .readTimeout(outTime, TimeUnit.MILLISECONDS)
  1160. .writeTimeout(outTime, TimeUnit.MILLISECONDS)
  1161. .build();
  1162. try {
  1163. Response decodeResponse = decodeClient.newCall(okHttpRequest).execute();
  1164. String decodeResponseContext = "";
  1165. if (decodeResponse.body() != null) {
  1166. decodeResponseContext = decodeResponse.body().string();
  1167. }
  1168. log.info("supplier100000043.scmDecodeIdCode接口decodeResponseContext={}", decodeResponseContext);
  1169. JSONObject decodeResponseObject = JSON.parseObject(decodeResponseContext);
  1170. if (decodeResponseObject != null && decodeResponseObject.getString("code").equals("200") && decodeResponseObject.getString("data").equals("1")) {
  1171. JSONObject msg = JSON.parseObject(JSON.toJSONString(decodeResponseObject.get("msg")));
  1172. requestParamObject.put("idCode", msg.getString("idcard"));
  1173. requestParamObject.put("name", msg.getString("name"));
  1174. return requestParamObject;
  1175. } else {
  1176. return null;
  1177. }
  1178. } catch (SocketTimeoutException ste) {
  1179. ErrorUtils.captureException(ste);
  1180. log.info("supplier100000043.getDecodeIdCard接口SocketTimeoutException={}", ste);
  1181. return null;
  1182. } catch (Exception e) {
  1183. ErrorUtils.captureException(e);
  1184. log.info("supplier100000043.decodeIdCode接口Exception={}", e);
  1185. return null;
  1186. }
  1187. }
  1188. public void reduceVisitCount(String hashKey,String key){
  1189. long visitCount = stringRedisTemplate.boundHashOps(hashKey).increment(key,-1);
  1190. }
  1191. public void countOver(ChannelTypeHandleResponseObject ret,String returnType){
  1192. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  1193. ret.setResultCode(Constant.OTHER_ERROR_CODE);
  1194. } else {
  1195. ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
  1196. }
  1197. ret.setCode(Constant.REQUEST_LIMIT);
  1198. }
  1199. public static void main(String[] args) {
  1200. int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
  1201. System.out.println(hour);
  1202. }
  1203. public void testNotify(String channelId,int type){
  1204. String traceId= tracer.currentSpan().context().traceIdString();
  1205. NotifySms notifySms =new NotifySms();
  1206. notifySms.setSupplierProperties(supplierProperties);
  1207. notifySms.setSmsActionInterface(smsActionInterface);
  1208. notifySms.setChannelActionInterface(channelActionInterface);
  1209. notifySms.setChannId(channelId);
  1210. notifySms.setTraceId(traceId);
  1211. notifySms.setType(type);
  1212. notifySms.setCount(0);
  1213. Timer timer =new Timer();
  1214. log.info("test..................,notify:{}",notifySms);
  1215. timer.schedule(new NotifyThread(notifySms),1*60*1000);
  1216. }
  1217. /* public void norify(String channelId,int type){
  1218. boolean flag = stringRedisTemplate.boundHashOps(Constant.rx_warn_key).putIfAbsent("sign","1");
  1219. if(flag == ){
  1220. }
  1221. }*/
  1222. public ChannelTypeHandleResponseObject photoIdentityCheckV3New(HttpServletRequest request, String customBody, int outTime, String decodeType) {
  1223. ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
  1224. ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
  1225. ret.setCode(Constant.SUCCESS);
  1226. String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
  1227. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  1228. String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
  1229. if (StringUtils.isBlank(returnType)) {
  1230. returnType = Constant.CUSTOMER_RETURN_ZW;
  1231. }
  1232. if (outTime <= SjjhConstant.PARA_ZERO) {
  1233. outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
  1234. }
  1235. String channelId = request.getHeader("channelId");
  1236. String key="url3"+photoIdentityMethod;
  1237. LocalDateTime now = LocalDateTime.now();
  1238. String ymd = dateTimeFormatter.format(now);
  1239. String hashKey = "043-"+ymd;
  1240. boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrl3PhotoUp(),channelId);
  1241. if(!flag){
  1242. countOver(ret,returnType);
  1243. return ret;
  1244. }
  1245. log.info("supplier10000043.photoIdentityCheckV3New---customBody={},outTime={}", customBody, outTime);
  1246. if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) {
  1247. customBody = decodeParams(ret, returnType, customBody, decodeType);
  1248. if (StringUtils.isBlank(customBody)) {
  1249. reduceVisitCount(hashKey,key);
  1250. ret.setCode(Constant.SUCCESS);
  1251. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  1252. return ret;
  1253. }
  1254. }
  1255. try {
  1256. JSONObject jsonObject = JSON.parseObject(customBody);
  1257. String name = jsonObject.getString("name");//requestObject.getName();
  1258. String idCode = jsonObject.getString("idCode");
  1259. String photo = jsonObject.getString("photo");
  1260. customBody = null;
  1261. jsonObject.put("photo", "图片base64");
  1262. request.setAttribute(Constant.CHANNEL_LOG_QUERY,
  1263. Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE)));
  1264. jsonObject = null;
  1265. if(!checkParm(name,idCode,returnType,ret)){
  1266. reduceVisitCount(hashKey,key);
  1267. return ret;
  1268. }
  1269. JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  1270. factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口
  1271. factory.setAddress(urlV3);
  1272. NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象
  1273. // 设置客户端的配置信息,超时等.
  1274. Client proxy = ClientProxy.getClient(nciicServices);
  1275. HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
  1276. HTTPClientPolicy policy = new HTTPClientPolicy();
  1277. policy.setConnectionTimeout(outTime); // 连接超时时间
  1278. policy.setReceiveTimeout(outTime);// 请求超时时间.
  1279. conduit.setClient(policy);
  1280. String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE_V3
  1281. .replace("{fsd}", idCode.substring(0, 6))
  1282. .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX_BQ)
  1283. .replace("{idCode}", idCode)
  1284. .replace("{name}", name)
  1285. .replace("{photo}", photo);
  1286. String result = nciicServices.nciicCompare(SjjhConstant.PHOTO_IDENTITY_SECRET_KEY_V3,paramXml);
  1287. log.info("photoIdentityCheck上游返回xml:{}", result);
  1288. upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result,key+SjjhConstant.key_subStr,channelId);
  1289. }catch (WebServiceException exception){
  1290. log.info("supplier10000043.photoIdentityCheckV3接口-WebServiceException:{}", exception);
  1291. ErrorUtils.captureException(exception);
  1292. ret.setCode(Constant.REQUEST_TIMEOUT);
  1293. } catch (Exception ioe) {
  1294. log.info("supplier10000043.photoIdentityCheckV3New接口-Exception:{}", ioe);
  1295. ErrorUtils.captureException(ioe);
  1296. ret.setCode(Constant.FAIL);
  1297. }
  1298. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  1299. return ret;
  1300. }
  1301. @Override
  1302. public ChannelTypeHandleResponseObject photoIdentityCheckV4New(HttpServletRequest request, String customBody, int outTime, String decodeType) {
  1303. ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
  1304. ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
  1305. ret.setCode(Constant.SUCCESS);
  1306. String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
  1307. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  1308. String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
  1309. if (StringUtils.isBlank(returnType)) {
  1310. returnType = Constant.CUSTOMER_RETURN_ZW;
  1311. }
  1312. if (outTime <= SjjhConstant.PARA_ZERO) {
  1313. outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
  1314. }
  1315. String channelId = request.getHeader("channelId");
  1316. String key="url4"+photoIdentityMethod;
  1317. LocalDateTime now = LocalDateTime.now();
  1318. String ymd = dateTimeFormatter.format(now);
  1319. String hashKey = "043-"+ymd;
  1320. boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrl4PhotoUp(),channelId);
  1321. if(!flag){
  1322. countOver(ret,returnType);
  1323. return ret;
  1324. }
  1325. log.info("supplier10000043.photoIdentityCheckV4New---customBody={},outTime={}", customBody, outTime);
  1326. if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) {
  1327. customBody = decodeParams(ret, returnType, customBody, decodeType);
  1328. if (StringUtils.isBlank(customBody)) {
  1329. reduceVisitCount(hashKey,key);
  1330. ret.setCode(Constant.SUCCESS);
  1331. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  1332. return ret;
  1333. }
  1334. }
  1335. try {
  1336. JSONObject jsonObject = JSON.parseObject(customBody);
  1337. String name = jsonObject.getString("name");//requestObject.getName();
  1338. String idCode = jsonObject.getString("idCode");
  1339. String photo = jsonObject.getString("photo");
  1340. customBody = null;
  1341. jsonObject.put("photo", "图片base64");
  1342. request.setAttribute(Constant.CHANNEL_LOG_QUERY,
  1343. Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE)));
  1344. jsonObject = null;
  1345. if(!checkParm(name,idCode,returnType,ret)){
  1346. reduceVisitCount(hashKey,key);
  1347. return ret;
  1348. }
  1349. JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  1350. factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口
  1351. factory.setAddress(urlV4);
  1352. NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象
  1353. // 设置客户端的配置信息,超时等.
  1354. Client proxy = ClientProxy.getClient(nciicServices);
  1355. HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
  1356. HTTPClientPolicy policy = new HTTPClientPolicy();
  1357. policy.setConnectionTimeout(outTime); // 连接超时时间
  1358. policy.setReceiveTimeout(outTime);// 请求超时时间.
  1359. conduit.setClient(policy);
  1360. String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE_V4
  1361. .replace("{fsd}", idCode.substring(0, 6))
  1362. .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX_YTST)
  1363. .replace("{idCode}", idCode)
  1364. .replace("{name}", name)
  1365. .replace("{photo}", photo);
  1366. String result = nciicServices.nciicCompare(SjjhConstant.PHOTO_IDENTITY_SECRET_KEY_V4,paramXml);
  1367. log.info("photoIdentityCheck上游返回xml:{}", result);
  1368. upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result,key+SjjhConstant.key_subStr,channelId);
  1369. }catch (WebServiceException exception){
  1370. log.info("supplier10000043.photoIdentityCheckV4New接口-WebServiceException:{}", exception);
  1371. ErrorUtils.captureException(exception);
  1372. ret.setCode(Constant.REQUEST_TIMEOUT);
  1373. } catch (Exception ioe) {
  1374. log.info("supplier10000043.photoIdentityCheckV4New接口-Exception:{}", ioe);
  1375. ErrorUtils.captureException(ioe);
  1376. ret.setCode(Constant.FAIL);
  1377. }
  1378. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  1379. return ret;
  1380. }
  1381. }