InsCBITController.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. package com.ydtech.modules.ins.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.fasterxml.jackson.databind.ObjectMapper;
  5. import com.fasterxml.jackson.databind.ObjectReader;
  6. import com.ydtech.core.page.HttpResult;
  7. import com.ydtech.modules.admin.model.SysCbitError;
  8. import com.ydtech.modules.admin.model.SysCbitLog;
  9. import com.ydtech.modules.base.controller.BaseController;
  10. import com.ydtech.modules.ins.model.cbit.*;
  11. import com.ydtech.modules.ins.model.vo.CarModelQryVo;
  12. import com.ydtech.modules.ins.model.vo.QuoteInfoVo;
  13. import com.ydtech.modules.ins.service.SysCbitErrorService;
  14. import com.ydtech.modules.ins.service.SysCbitLogService;
  15. import com.ydtech.utils.HttpsPostUtil;
  16. import com.ydtech.utils.RSA.RSAUtils;
  17. import org.slf4j.Logger;
  18. import org.slf4j.LoggerFactory;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.beans.factory.annotation.Value;
  21. import org.springframework.core.env.Environment;
  22. import org.springframework.util.StringUtils;
  23. import org.springframework.web.bind.annotation.PostMapping;
  24. import org.springframework.web.bind.annotation.RequestBody;
  25. import org.springframework.web.bind.annotation.RequestMapping;
  26. import org.springframework.web.bind.annotation.RestController;
  27. import javax.servlet.ServletOutputStream;
  28. import javax.servlet.http.HttpServletRequest;
  29. import javax.servlet.http.HttpServletResponse;
  30. import java.io.IOException;
  31. import java.text.SimpleDateFormat;
  32. import java.util.Date;
  33. import java.util.HashMap;
  34. import java.util.Map;
  35. import java.util.UUID;
  36. /**
  37. * @author gws
  38. * @version 1.0.0
  39. * @description InsCBITController
  40. * @since 2021/11/7 9:22
  41. */
  42. @RestController
  43. @RequestMapping("/CBITAPI/insCBIT")
  44. public class InsCBITController extends BaseController {
  45. Logger logger = LoggerFactory.getLogger(InsCBITController.class);
  46. @Autowired
  47. Environment environment;
  48. @Autowired
  49. SysCbitLogService sysCbitLogService;
  50. @Autowired
  51. SysCbitErrorService sysCbitErrorService;
  52. //接口域名
  53. @Value("${cbit.url_pre}")
  54. String url_pre = "";
  55. //中介机构编码
  56. @Value("${cbit.franchiserId}")
  57. String franchiserId = "";
  58. //ip
  59. @Value("${cbit.ip}")
  60. String franchiserIp = "";
  61. //中介平台-加解密秘钥对 私钥+公钥
  62. @Value("${cbit.ZJPT_PUBLIC_KEY}")
  63. private String ZJPT_PUBLIC_KEY = "";
  64. //合作伙伴-加解密秘钥对 私钥+公钥
  65. @Value("${cbit.HZHB_PRIVATE_KEY}")
  66. private String HZHB_PRIVATE_KEY = "";
  67. /**
  68. * 3.2初始化参数获取接口
  69. * insurerId 保险公司id
  70. * insurerBranchCode 二级机构编码
  71. * franchiserChannelId 传中介网点代码
  72. */
  73. @PostMapping(value = "/initParamAPI")
  74. public InitResultData initParamAPI(@RequestBody CBITBaseparam req_baseparam) {
  75. String url = url_pre + environment.getProperty("cbit.api2");
  76. String req_desc = "3.2初始化参数获取接口";
  77. InitResultData initResultData = null;
  78. try {
  79. checkBaseparam(req_baseparam);
  80. String reqno = geneReqNo();//请求流水号
  81. String reqtype = "Z00001";
  82. logger.info(req_desc + "--请求接口地址-->" + url);
  83. //1.生成初始化参数
  84. //CBITBaseparam baseparam=new CBITBaseparam(req_baseparam.getInsurerId(),reqno,"Z00001",req_baseparam.getInsurerBranchCode(),req_baseparam.getFranchiserChannel().getFranchiserChannelId());
  85. req_baseparam.setRequestNo(reqno);
  86. req_baseparam.setRequestType(reqtype);
  87. CBITReqParam reqParam = geneReqParam(req_baseparam);
  88. //2.调用保信接口
  89. String req_json = JSON.toJSONString(reqParam);
  90. logger.info(req_desc + "--请求参数-->" + req_json);
  91. String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
  92. logger.info(req_desc + "--返回结果-->" + resp_json);
  93. //3.插入调保信接口日志表
  94. insertCbitLog(url, req_desc, reqno, req_json, resp_json);
  95. //4.处理保信接口返回数据
  96. ObjectMapper objectMapper = new ObjectMapper();
  97. ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
  98. CBITResponse res;
  99. try {
  100. res = reader.readValue(resp_json);
  101. } catch (IOException e) {
  102. res = null;
  103. logger.error("反序列化失败", e);
  104. }
  105. if (res == null) {
  106. throw new Exception("反序列化失败");
  107. }
  108. if (!"Z00001".equals(res.getStatus())) {
  109. throw new Exception("保信接口返回错误:" + res.getMsg());
  110. } else {//5.接口交互成功,返回数据处理
  111. initResultData = JSON.parseObject(JSON.toJSONString(res.getData()), InitResultData.class);
  112. }
  113. } catch (Exception e) {
  114. e.printStackTrace();
  115. HttpResult.error(e.getMessage());
  116. }
  117. return initResultData;
  118. }
  119. /**
  120. * 3.3订单号生成接口
  121. */
  122. @PostMapping(value = "/geneOrder")
  123. public HttpResult geneOrder(@RequestBody CBITBaseparam req_baseparam) {
  124. String url = url_pre + environment.getProperty("cbit.api3");
  125. String req_desc = "3.3订单号生成接口";
  126. String orderNo = "";
  127. try {
  128. checkBaseparam(req_baseparam);
  129. String reqno = geneReqNo();//请求流水号
  130. String reqtype = "Z00002";
  131. //1.生成初始化参数
  132. //CBITBaseparam baseparam=new CBITBaseparam(req_baseparam.getInsurerId(),reqno,reqtype,req_baseparam.getInsurerBranchCode(),req_baseparam.getFranchiserChannel().getFranchiserChannelId());
  133. req_baseparam.setRequestNo(reqno);
  134. req_baseparam.setRequestType(reqtype);
  135. CBITReqParam reqParam = geneReqParam(req_baseparam);
  136. //2.调用保信接口
  137. String req_json = JSON.toJSONString(reqParam);
  138. logger.info(req_desc + "--请求参数-->" + req_json);
  139. String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
  140. logger.info(req_desc + "--返回结果-->" + resp_json);
  141. //3.插入调保信接口日志表
  142. insertCbitLog(url, req_desc, reqno, req_json, resp_json);
  143. //4.处理保信接口返回数据
  144. ObjectMapper objectMapper = new ObjectMapper();
  145. ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
  146. CBITResponse res;
  147. try {
  148. res = reader.readValue(resp_json);
  149. } catch (IOException e) {
  150. res = null;
  151. logger.error("反序列化失败", e);
  152. }
  153. if (res == null) {
  154. throw new Exception("反序列化失败");
  155. }
  156. if (!"Z00001".equals(res.getStatus())) {
  157. return HttpResult.error("订单号生成错误,错误信息:" + res.getMsg());
  158. } else {//5.接口交互成功,返回数据处理
  159. JSONObject data = res.getData();
  160. orderNo = data.getString("orderNo");
  161. }
  162. } catch (Exception e) {
  163. e.printStackTrace();
  164. return HttpResult.error(e.getMessage());
  165. }
  166. return HttpResult.ok(orderNo);
  167. }
  168. /**
  169. * 3.5车型查询接口
  170. */
  171. @PostMapping(value = "/queryModel")
  172. public HttpResult queryModel(@RequestBody CarModelQryVo carModelQryVo) {
  173. String url = url_pre + environment.getProperty("cbit.api5");
  174. String req_desc = "3.5车型查询接口";
  175. CBITModelInfo cbitModelInfo = null;
  176. try {
  177. String reqno = geneReqNo();//请求流水号
  178. CBITBaseparam baseparam = carModelQryVo.getBaseParam();
  179. String insurerId = baseparam.getInsurerId();//
  180. String reqtype = "Z00004";
  181. baseparam.setRequestNo(reqno);
  182. baseparam.setRequestType(reqtype);
  183. String insurerBranchCode = baseparam.getInsurerBranchCode();
  184. String franchiserChannelId = baseparam.getFranchiserChannel().getFranchiserChannelId();
  185. if (StringUtils.isEmpty(franchiserChannelId)//中介网点代码
  186. || StringUtils.isEmpty(insurerId)//保险公司
  187. || StringUtils.isEmpty(insurerBranchCode)//二级机构编码
  188. ) {
  189. throw new Exception("insurerId/insurerBranchCode/franchiserChannelId,不能为空!");
  190. }
  191. if (StringUtils.isEmpty(baseparam.getOrderNo()) || StringUtils.isEmpty(carModelQryVo.getModelCName())//车辆型号
  192. || StringUtils.isEmpty(carModelQryVo.getEngineNo())//发动机号
  193. || StringUtils.isEmpty(carModelQryVo.getVin())//车架号
  194. || StringUtils.isEmpty(carModelQryVo.getNewVehicleFlag())//0:非新车,1:新车
  195. ) {
  196. throw new Exception("orderNo/modelCName/engineNo/vin/newVehicleFlag,不能为空!");
  197. }
  198. //1.生成初始化参数
  199. CBITReqParam reqParam = geneReqParam(baseparam);
  200. reqParam.setVehicleBrandModelKey(carModelQryVo.getModelCName());//车辆型号
  201. reqParam.setEngineNo(carModelQryVo.getEngineNo());//发动机号
  202. reqParam.setVin(carModelQryVo.getVin());//车架号
  203. reqParam.setNewVehicleFlag(carModelQryVo.getNewVehicleFlag());//0:非新车,1:新车
  204. //2.调用保信接口
  205. String req_json = JSON.toJSONString(reqParam);
  206. logger.info(req_desc + "--请求参数-->" + req_json);
  207. String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
  208. logger.info(req_desc + "--返回结果-->" + resp_json);
  209. //3.插入调保信接口日志表
  210. insertCbitLog(url, req_desc, reqno, req_json, resp_json);
  211. //4.处理保信接口返回数据
  212. ObjectMapper objectMapper = new ObjectMapper();
  213. ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
  214. CBITResponse res;
  215. try {
  216. res = reader.readValue(resp_json);
  217. } catch (IOException e) {
  218. res = null;
  219. logger.error("反序列化失败", e);
  220. }
  221. if (res == null) {
  222. throw new Exception("反序列化失败");
  223. }
  224. if (!"Z00001".equals(res.getStatus())) {
  225. return HttpResult.error(req_desc + "返回错误,错误信息:" + res.getMsg());
  226. } else {//5.接口交互成功,返回数据处理
  227. cbitModelInfo = JSON.parseObject(JSON.toJSONString(res.getData()), CBITModelInfo.class);
  228. }
  229. } catch (Exception e) {
  230. e.printStackTrace();
  231. return HttpResult.error(e.getMessage());
  232. }
  233. return HttpResult.ok(cbitModelInfo);
  234. }
  235. /**
  236. * 3.6车辆确认接口
  237. *
  238. * @param reqParam_in
  239. * @return
  240. */
  241. @PostMapping("/confirmVehicle")
  242. public HttpResult confirmVehicle(@RequestBody CBITReqParam reqParam_in) {
  243. String url = url_pre + environment.getProperty("cbit.api6");
  244. String req_desc = "3.6车辆确认接口";
  245. ConfirmVehicleResqData confirmVehicleResqData = null;
  246. try {
  247. String reqno = geneReqNo();//请求流水号
  248. CBITBaseparam baseparam = reqParam_in.getBaseParam();
  249. checkBaseparam(baseparam);
  250. String reqtype = "Z00005";
  251. baseparam.setRequestNo(reqno);
  252. baseparam.setRequestType(reqtype);
  253. //1.生成初始化参数
  254. CBITReqParam reqParam = geneReqParam(baseparam);
  255. reqParam.setCarOwner(reqParam_in.getCarOwner());
  256. reqParam.setHolder(reqParam_in.getHolder());
  257. reqParam.setInsureder(reqParam_in.getInsureder());
  258. reqParam.setVehicle(reqParam_in.getVehicle());
  259. //2.调用保信接口
  260. String req_json = JSON.toJSONString(reqParam);
  261. logger.info(req_desc + "--请求参数-->" + req_json);
  262. String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
  263. logger.info(req_desc + "--返回结果-->" + resp_json);
  264. //3.插入调保信接口日志表
  265. insertCbitLog(url, req_desc, reqno, req_json, resp_json);
  266. //4.处理保信接口返回数据
  267. ObjectMapper objectMapper = new ObjectMapper();
  268. ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
  269. CBITResponse res;
  270. try {
  271. res = reader.readValue(resp_json);
  272. } catch (IOException e) {
  273. res = null;
  274. logger.error("反序列化失败", e);
  275. }
  276. if (res == null) {
  277. throw new Exception("反序列化失败");
  278. }
  279. if (!"Z00001".equals(res.getStatus())) {
  280. return HttpResult.error(req_desc + "错误,错误信息:" + res.getMsg());
  281. } else {//5.接口交互成功,返回数据处理
  282. confirmVehicleResqData = JSON.parseObject(JSON.toJSONString(res.getData()), ConfirmVehicleResqData.class);
  283. }
  284. } catch (Exception e) {
  285. e.printStackTrace();
  286. return HttpResult.error(e.getMessage());
  287. }
  288. return HttpResult.ok(confirmVehicleResqData);
  289. }
  290. /**
  291. * 3.7报价
  292. *
  293. * @param quoteInfo
  294. * @return
  295. */
  296. @PostMapping("/quote")
  297. public HttpResult quote(@RequestBody QuoteInfoVo quoteInfo) {
  298. String url = url_pre + environment.getProperty("cbit.api7");
  299. String req_desc = "3.7报价";
  300. QuoteRespData quoteRespData = null;
  301. try {
  302. String reqno = geneReqNo();//请求流水号
  303. String reqtype = "Z00006";
  304. CBITBaseparam baseparam = quoteInfo.getBaseParam();
  305. checkBaseparam(baseparam);
  306. baseparam.setRequestNo(reqno);
  307. baseparam.setRequestType(reqtype);
  308. if (StringUtils.isEmpty(baseparam.getOrderNo())//订单号
  309. ) {
  310. throw new Exception("orderNo,不能为空!");
  311. }
  312. if (quoteInfo.getKindList() == null || quoteInfo.getKindList().size() == 0) {
  313. throw new Exception("kindList,不能为空!");
  314. }
  315. //1.生成初始化参数
  316. CBITReqParam reqParam = geneReqParam(baseparam);
  317. TrafficPolicy trafficPolicy = new TrafficPolicy(quoteInfo.getStartDate(), "T", "0");
  318. BusinessPolicy businessPolicy = new BusinessPolicy(quoteInfo.getStartDate(), quoteInfo.getKindList());
  319. reqParam.setTrafficPolicy(trafficPolicy);//需修改
  320. reqParam.setBusinessPolicy(businessPolicy);//需修改
  321. reqParam.setArgueSolution("1");
  322. reqParam.setCarVin(quoteInfo.getCarInfo().getVinNo());
  323. //2.调用保信接口
  324. String req_json = JSON.toJSONString(reqParam);
  325. logger.info(req_desc + "--请求参数-->" + req_json);
  326. String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
  327. logger.info(req_desc + "--返回结果-->" + resp_json);
  328. //3.插入调保信接口日志表
  329. insertCbitLog(url, req_desc, reqno, req_json, resp_json);
  330. //4.处理保信接口返回数据
  331. ObjectMapper objectMapper = new ObjectMapper();
  332. ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
  333. CBITResponse res;
  334. try {
  335. res = reader.readValue(resp_json);
  336. } catch (IOException e) {
  337. res = null;
  338. logger.error("反序列化失败", e);
  339. }
  340. if (res == null) {
  341. throw new Exception("反序列化失败");
  342. }
  343. if (!"Z00001".equals(res.getStatus())) {
  344. return HttpResult.error(req_desc + "错误,错误信息:" + res.getMsg());
  345. } else {//5.接口交互成功,返回数据处理
  346. quoteRespData = JSON.parseObject(JSON.toJSONString(res.getData()), QuoteRespData.class);
  347. }
  348. } catch (Exception e) {
  349. e.printStackTrace();
  350. return HttpResult.error(e.getMessage());
  351. }
  352. return HttpResult.ok(quoteRespData);
  353. }
  354. /**
  355. * 3.8核保接口
  356. *
  357. * @param reqParam_in
  358. * @return
  359. */
  360. @PostMapping("/submitAudit")
  361. public HttpResult submitAudit(@RequestBody CBITReqParam reqParam_in) {
  362. String url = url_pre + environment.getProperty("cbit.api8");
  363. String req_desc = "3.8核保接口";
  364. String reqno = geneReqNo();//请求流水号
  365. String reqtype = "Z00007";
  366. AuditRespData auditRespData = null;
  367. try {
  368. CBITBaseparam baseparam = reqParam_in.getBaseParam();
  369. checkBaseparam(baseparam);
  370. baseparam.setRequestNo(reqno);
  371. baseparam.setRequestType(reqtype);
  372. if (StringUtils.isEmpty(baseparam.getOrderNo())//订单号
  373. ) {
  374. throw new Exception("orderNo,不能为空!");
  375. }
  376. //1.生成初始化参数
  377. CBITReqParam reqParam = geneReqParam(baseparam);
  378. reqParam.setBusinessPolicy(reqParam_in.getBusinessPolicy());
  379. reqParam.setTrafficPolicy(reqParam_in.getTrafficPolicy());
  380. //2.调用保信接口
  381. String req_json = JSON.toJSONString(reqParam);
  382. logger.info(req_desc + "--请求参数-->" + req_json);
  383. String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
  384. logger.info(req_desc + "--返回结果-->" + resp_json);
  385. //3.插入调保信接口日志表
  386. insertCbitLog(url, req_desc, reqno, req_json, resp_json);
  387. //4.处理保信接口返回数据
  388. ObjectMapper objectMapper = new ObjectMapper();
  389. ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
  390. CBITResponse res;
  391. try {
  392. res = reader.readValue(resp_json);
  393. } catch (IOException e) {
  394. res = null;
  395. logger.error("反序列化失败", e);
  396. }
  397. if (res == null) {
  398. throw new Exception("反序列化失败");
  399. }
  400. if (!"Z00001".equals(res.getStatus())) {
  401. return HttpResult.error(req_desc + "错误,错误信息:" + res.getMsg());
  402. } else {//5.接口交互成功,返回数据处理
  403. auditRespData = JSON.parseObject(JSON.toJSONString(res.getData()), AuditRespData.class);
  404. }
  405. } catch (Exception e) {
  406. e.printStackTrace();
  407. return HttpResult.error(e.getMessage());
  408. }
  409. return HttpResult.ok(auditRespData);
  410. }
  411. /**
  412. * 3.14电子签名支付接口
  413. *
  414. * @return
  415. */
  416. @PostMapping("/pay_eleSign")
  417. public HttpResult eleSignPay(@RequestBody CBITBaseparam req_baseparam) {
  418. String url = url_pre + environment.getProperty("cbit.api14");
  419. String req_desc = "3.14电子签名支付接口";
  420. String reqno = geneReqNo();//请求流水号
  421. String reqtype = "Z00013";
  422. SignPayResqData signPayResqData = null;
  423. try {
  424. checkBaseparam(req_baseparam);
  425. if (StringUtils.isEmpty(req_baseparam.getOrderNo())//订单号
  426. ) {
  427. throw new Exception("orderNo,不能为空!");
  428. }
  429. //1.生成初始化参数
  430. req_baseparam.setRequestNo(reqno);
  431. req_baseparam.setRequestType(reqtype);
  432. CBITReqParam reqParam = geneReqParam(req_baseparam);
  433. //2.调用保信接口
  434. String req_json = JSON.toJSONString(reqParam);
  435. logger.info(req_desc + "--请求参数-->" + req_json);
  436. String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
  437. logger.info(req_desc + "--返回结果-->" + resp_json);
  438. //3.插入调保信接口日志表
  439. insertCbitLog(url, req_desc, reqno, req_json, resp_json);
  440. //4.处理保信接口返回数据
  441. ObjectMapper objectMapper = new ObjectMapper();
  442. ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
  443. CBITResponse res;
  444. try {
  445. res = reader.readValue(resp_json);
  446. } catch (IOException e) {
  447. res = null;
  448. logger.error("反序列化失败", e);
  449. }
  450. if (res == null) {
  451. throw new Exception("反序列化失败");
  452. }
  453. if (!"Z00001".equals(res.getStatus())) {
  454. return HttpResult.error(req_desc + "错误,错误信息:" + res.getMsg());
  455. } else {//5.接口交互成功,返回数据处理
  456. signPayResqData = JSON.parseObject(JSON.toJSONString(res.getData()), SignPayResqData.class);
  457. }
  458. } catch (Exception e) {
  459. e.printStackTrace();
  460. return HttpResult.error(e.getMessage());
  461. }
  462. return HttpResult.ok(signPayResqData);
  463. }
  464. /**
  465. * 3.17投保单继续支付接口
  466. *
  467. * @return
  468. */
  469. @PostMapping("/pay_application")
  470. public HttpResult pay_application(@RequestBody CBITBaseparam req_baseparam) {
  471. String url = url_pre + environment.getProperty("cbit.api17");
  472. String req_desc = "3.17投保单继续支付接口";
  473. String reqno = geneReqNo();//请求流水号
  474. String reqtype = "Z00016";
  475. String data = "";
  476. try {
  477. checkBaseparam(req_baseparam);
  478. if (StringUtils.isEmpty(req_baseparam.getOrderNo())//订单号
  479. ) {
  480. throw new Exception("orderNo,不能为空!");
  481. }
  482. //1.生成初始化参数
  483. req_baseparam.setRequestNo(reqno);
  484. req_baseparam.setRequestType(reqtype);
  485. CBITReqParam reqParam = geneReqParam(req_baseparam);
  486. //2.调用保信接口
  487. String req_json = JSON.toJSONString(reqParam);
  488. logger.info(req_desc + "--请求参数-->" + req_json);
  489. String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
  490. logger.info(req_desc + "--返回结果-->" + resp_json);
  491. //3.插入调保信接口日志表
  492. insertCbitLog(url, req_desc, reqno, req_json, resp_json);
  493. //4.处理保信接口返回数据
  494. JSONObject resultMap = JSON.parseObject(resp_json.toString());
  495. String status = resultMap.getString("status");
  496. if (!"Z00001".equals(status)) {
  497. return HttpResult.error(req_desc + "错误,错误信息:" + resultMap.getString("msg"));
  498. } else {//5.接口交互成功,返回数据处理
  499. data = resultMap.getString("data");
  500. }
  501. } catch (Exception e) {
  502. e.printStackTrace();
  503. return HttpResult.error(e.getMessage());
  504. }
  505. return HttpResult.ok("", data);
  506. }
  507. /**
  508. * 3.18续保查询接口
  509. *
  510. * @return
  511. */
  512. @PostMapping("/queryPolicy")
  513. public HttpResult queryPolicy(@RequestBody CBITBaseparam req_baseparam) {
  514. String url = url_pre + environment.getProperty("cbit.api18");
  515. String req_desc = "3.18续保查询接口";
  516. String reqno = geneReqNo();//请求流水号
  517. String reqtype = "Z00017";
  518. String data = "";
  519. try {
  520. checkBaseparam(req_baseparam);
  521. //1.生成初始化参数
  522. req_baseparam.setRequestNo(reqno);
  523. req_baseparam.setRequestType(reqtype);
  524. CBITReqParam reqParam = geneReqParam(req_baseparam);
  525. reqParam.setCarVin("LNN3VKVKX57A22WWK");
  526. reqParam.setEngineNo("ENGTFE9QDKFU");
  527. //2.调用保信接口
  528. String req_json = JSON.toJSONString(reqParam);
  529. logger.info(req_desc + "--请求参数-->" + req_json);
  530. String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
  531. logger.info(req_desc + "--返回结果-->" + resp_json);
  532. //3.插入调保信接口日志表
  533. insertCbitLog(url, req_desc, reqno, req_json, resp_json);
  534. //4.处理保信接口返回数据
  535. JSONObject resultMap = JSON.parseObject(resp_json.toString());
  536. String status = resultMap.getString("status");
  537. if (!"Z00001".equals(status)) {
  538. return HttpResult.error(req_desc + "错误,错误信息:" + resultMap.getString("msg"));
  539. } else {//5.接口交互成功,返回数据处理
  540. data = resultMap.getString("data");
  541. }
  542. } catch (Exception e) {
  543. e.printStackTrace();
  544. return HttpResult.error(e.getMessage());
  545. }
  546. return HttpResult.ok("", data);
  547. }
  548. /**
  549. * 3.19支付信息回调接口
  550. *
  551. * @return
  552. */
  553. @PostMapping("/updatePayInfo")
  554. public HttpServletResponse updatePayInfo(HttpServletRequest request, HttpServletResponse http_resp, @RequestBody Map<String, String> reqMap) {
  555. ReqParamCBIT reqParam_cbit = null;
  556. try {
  557. String req_bizContent = reqMap.get("bizContent");
  558. String req_sign = request.getHeader("Signature");
  559. String reqGetContent = RSAUtils.checkSignAndDecrypt(req_bizContent, req_sign, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY, "UTF-8", true, true);
  560. System.out.println("解密后的请求参数reqGetContent=" + reqGetContent);
  561. reqParam_cbit = JSON.parseObject(reqGetContent, ReqParamCBIT.class);
  562. String orderNo = reqParam_cbit.getOrderNo();
  563. String payResult = reqParam_cbit.getPayResult();
  564. //-------具体系统状态更新逻辑---------
  565. //拼装返回信息
  566. geneResponse(http_resp, reqParam_cbit);
  567. } catch (Exception e) {
  568. //记录报错日志表
  569. e.printStackTrace();
  570. String api_url = "/API/insCBIT/updatePayInfo";
  571. String errorinfo = e.getMessage();
  572. insertCbitError(reqParam_cbit, api_url, errorinfo);
  573. }
  574. return http_resp;
  575. }
  576. /**
  577. * 3.20保单结果回调接口
  578. *
  579. * @return
  580. */
  581. @PostMapping("/updatePolicyStatus")
  582. public HttpServletResponse updatePolicyStatus(HttpServletRequest request, HttpServletResponse http_resp, @RequestBody Map<String, String> reqMap) {
  583. ReqParamCBIT reqParam_cbit = null;
  584. try {
  585. String req_bizContent = reqMap.get("bizContent");
  586. String req_sign = request.getHeader("Signature");
  587. String reqGetContent = RSAUtils.checkSignAndDecrypt(req_bizContent, req_sign, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY, "UTF-8", true, true);
  588. System.out.println("解密后的请求参数reqGetContent=" + reqGetContent);
  589. reqParam_cbit = JSON.parseObject(reqGetContent, ReqParamCBIT.class);
  590. //-------具体系统状态更新逻辑---------
  591. //拼装返回信息
  592. geneResponse(http_resp, reqParam_cbit);
  593. } catch (Exception e) {
  594. //记录报错日志表
  595. e.printStackTrace();
  596. String api_url = "/API/insCBIT/updatePolicyStatus";
  597. String errorinfo = e.getMessage();
  598. insertCbitError(reqParam_cbit, api_url, errorinfo);
  599. }
  600. return http_resp;
  601. }
  602. private void geneResponse(HttpServletResponse http_resp, ReqParamCBIT reqParam_cbit) throws Exception {
  603. CBITBaseparam baseParam = new CBITBaseparam();
  604. baseParam.setRequestNo(reqParam_cbit.getBaseParam().getRequestNo());
  605. ResponseCBIT resp = new ResponseCBIT("Z00001", "处理成功", baseParam);
  606. String resp_str = JSON.toJSONString(resp);
  607. System.out.println("加密前返回参数resp_bizContent=" + resp_str);
  608. Map<String, String> encry = RSAUtils.encryptAndSign(resp_str, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY, "UTF-8", true, true);
  609. String resp_bizContent = encry.get("CONTENT");//密文
  610. System.out.println("加密后返回参数resp_bizContent=" + resp_bizContent);
  611. String resp_sign = encry.get("SIGNATURE");//签名,放在请求头中
  612. System.out.println("最终返回头中的签名resp_sign=" + resp_sign);
  613. Map<String, String> resp_Map = new HashMap<>();
  614. resp_Map.put("bizContent", resp_bizContent);
  615. String resp_Content = JSON.toJSONString(resp_Map);
  616. http_resp.setContentType("application/json;charset=utf-8");
  617. http_resp.addHeader("Accept", "application/json;charset=utf-8");
  618. http_resp.addHeader("Signature", resp_sign);
  619. http_resp.addHeader("PartnerCode", "p_taiyuantianqin");
  620. ServletOutputStream out = http_resp.getOutputStream();
  621. out.write(resp_Content.getBytes("UTF-8"));
  622. out.close();
  623. }
  624. @PostMapping(value = "/testCBIT")
  625. public void testjson() {
  626. System.out.println("--------------/testCBIT");
  627. String resp_json = environment.getProperty("resp_json");
  628. try {
  629. JSONObject resultMap = JSON.parseObject(resp_json.toString());
  630. String status = resultMap.getString("status");
  631. if (!"Z00001".equals(status)) {
  632. HttpResult.error("错误,错误信息:" + resultMap.getString("msg"));
  633. } else {//5.接口交互成功,返回数据处理
  634. String data = resultMap.getString("data");
  635. System.out.println(data);
  636. }
  637. } catch (Exception e) {
  638. e.printStackTrace();
  639. }
  640. }
  641. private void insertCbitLog(String url, String req_desc, String reqno, String req_json, String resp_json) {
  642. SysCbitLog cbitLog = new SysCbitLog();
  643. cbitLog.setReqNo(reqno);
  644. cbitLog.setUsercode("");
  645. // cbitLog.setUsercode(SecurityUtils.getUsername());
  646. cbitLog.setReqUrl(url);
  647. cbitLog.setDescription(req_desc);
  648. cbitLog.setReqParam(req_json);
  649. cbitLog.setResponse(resp_json);
  650. cbitLog.setCreatetime(new Date());
  651. sysCbitLogService.insert(cbitLog);
  652. }
  653. private String geneReqNo() {
  654. //中介机构id+UUID,每次请求需生成一个不重复的流水号,响应时原样返回
  655. return franchiserId + UUID.randomUUID();
  656. }
  657. private CBITReqParam geneReqParam(CBITBaseparam baseparam) throws Exception {
  658. CBITReqParam CBITReqParam = new CBITReqParam();
  659. //不能为空校验
  660. //String insurerId,String reqno,String reqtype,String insurerBranchCode,String franchiserChannelId
  661. if (StringUtils.isEmpty(baseparam.getInsurerId()) || StringUtils.isEmpty(baseparam.getRequestNo()) || StringUtils.isEmpty(baseparam.getRequestType()) || StringUtils.isEmpty(baseparam.getInsurerBranchCode()) || StringUtils.isEmpty(baseparam.getFranchiserChannel().getFranchiserChannelId())) {
  662. throw new Exception("insurerId, reqno, reqtype, insurerBranchCode, franchiserChannelId 这些参数不能为空!");
  663. }
  664. CBITBaseparam reqParam = new CBITBaseparam();
  665. reqParam.setFranchiserId(franchiserId);
  666. reqParam.setInsurerId(baseparam.getInsurerId());
  667. reqParam.setOrderNo(StringUtils.isEmpty(baseparam.getOrderNo()) ? "" : baseparam.getOrderNo());
  668. reqParam.setRequestNo(baseparam.getRequestNo());
  669. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  670. reqParam.setRequestTime(df.format(new Date()));
  671. reqParam.setRequestType(baseparam.getRequestType());
  672. reqParam.setIp(franchiserIp);
  673. reqParam.setInsurerBranchCode(baseparam.getInsurerBranchCode());
  674. reqParam.setPjOrderSourceCode(StringUtils.isEmpty(baseparam.getPjOrderSourceCode()) ? "" : baseparam.getPjOrderSourceCode());
  675. reqParam.setSysProductVersion(StringUtils.isEmpty(baseparam.getSysProductVersion()) ? "" : baseparam.getSysProductVersion());
  676. reqParam.setSysVersion(StringUtils.isEmpty(baseparam.getSysVersion()) ? "" : baseparam.getSysVersion());
  677. reqParam.setFranchiserInstitutionCode(StringUtils.isEmpty(baseparam.getFranchiserInstitutionCode()) ? "" : baseparam.getFranchiserInstitutionCode());
  678. reqParam.setFranchiserChannel(baseparam.getFranchiserChannel());
  679. CBITReqParam.setBaseParam(reqParam);
  680. return CBITReqParam;
  681. }
  682. private void checkBaseparam(CBITBaseparam baseparam) throws Exception {
  683. if (baseparam == null || StringUtils.isEmpty(baseparam.getFranchiserChannel().getFranchiserChannelId())//中介网点代码
  684. || StringUtils.isEmpty(baseparam.getInsurerId())//保险公司
  685. || StringUtils.isEmpty(baseparam.getInsurerBranchCode())//二级机构编码
  686. ) {
  687. throw new Exception("insurerId/insurerBranchCode/franchiserChannelId,不能为空!");
  688. }
  689. }
  690. private void insertCbitError(@RequestBody ReqParamCBIT reqParam_cbit, String api_url, String errorinfo) {
  691. SysCbitError sysCbitError = new SysCbitError();
  692. sysCbitError.setReqno(reqParam_cbit.getBaseParam().getRequestNo());
  693. sysCbitError.setRequrl(api_url);
  694. sysCbitError.setReqparam(JSON.toJSONString(reqParam_cbit));
  695. sysCbitError.setErrorinfo(errorinfo);
  696. sysCbitErrorService.insert(sysCbitError);
  697. }
  698. }