| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743 |
- package com.ydtech.modules.ins.controller;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.fasterxml.jackson.databind.ObjectReader;
- import com.ydtech.core.page.HttpResult;
- import com.ydtech.modules.admin.model.SysCbitError;
- import com.ydtech.modules.admin.model.SysCbitLog;
- import com.ydtech.modules.base.controller.BaseController;
- import com.ydtech.modules.ins.model.cbit.*;
- import com.ydtech.modules.ins.model.vo.CarModelQryVo;
- import com.ydtech.modules.ins.model.vo.QuoteInfoVo;
- import com.ydtech.modules.ins.service.SysCbitErrorService;
- import com.ydtech.modules.ins.service.SysCbitLogService;
- import com.ydtech.utils.HttpsPostUtil;
- import com.ydtech.utils.RSA.RSAUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.core.env.Environment;
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import javax.servlet.ServletOutputStream;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.UUID;
- /**
- * @author gws
- * @version 1.0.0
- * @description InsCBITController
- * @since 2021/11/7 9:22
- */
- @RestController
- @RequestMapping("/CBITAPI/insCBIT")
- public class InsCBITController extends BaseController {
- Logger logger = LoggerFactory.getLogger(InsCBITController.class);
- @Autowired
- Environment environment;
- @Autowired
- SysCbitLogService sysCbitLogService;
- @Autowired
- SysCbitErrorService sysCbitErrorService;
- //接口域名
- @Value("${cbit.url_pre}")
- String url_pre = "";
- //中介机构编码
- @Value("${cbit.franchiserId}")
- String franchiserId = "";
- //ip
- @Value("${cbit.ip}")
- String franchiserIp = "";
- //中介平台-加解密秘钥对 私钥+公钥
- @Value("${cbit.ZJPT_PUBLIC_KEY}")
- private String ZJPT_PUBLIC_KEY = "";
- //合作伙伴-加解密秘钥对 私钥+公钥
- @Value("${cbit.HZHB_PRIVATE_KEY}")
- private String HZHB_PRIVATE_KEY = "";
- /**
- * 3.2初始化参数获取接口
- * insurerId 保险公司id
- * insurerBranchCode 二级机构编码
- * franchiserChannelId 传中介网点代码
- */
- @PostMapping(value = "/initParamAPI")
- public InitResultData initParamAPI(@RequestBody CBITBaseparam req_baseparam) {
- String url = url_pre + environment.getProperty("cbit.api2");
- String req_desc = "3.2初始化参数获取接口";
- InitResultData initResultData = null;
- try {
- checkBaseparam(req_baseparam);
- String reqno = geneReqNo();//请求流水号
- String reqtype = "Z00001";
- logger.info(req_desc + "--请求接口地址-->" + url);
- //1.生成初始化参数
- //CBITBaseparam baseparam=new CBITBaseparam(req_baseparam.getInsurerId(),reqno,"Z00001",req_baseparam.getInsurerBranchCode(),req_baseparam.getFranchiserChannel().getFranchiserChannelId());
- req_baseparam.setRequestNo(reqno);
- req_baseparam.setRequestType(reqtype);
- CBITReqParam reqParam = geneReqParam(req_baseparam);
- //2.调用保信接口
- String req_json = JSON.toJSONString(reqParam);
- logger.info(req_desc + "--请求参数-->" + req_json);
- String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
- logger.info(req_desc + "--返回结果-->" + resp_json);
- //3.插入调保信接口日志表
- insertCbitLog(url, req_desc, reqno, req_json, resp_json);
- //4.处理保信接口返回数据
- ObjectMapper objectMapper = new ObjectMapper();
- ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
- CBITResponse res;
- try {
- res = reader.readValue(resp_json);
- } catch (IOException e) {
- res = null;
- logger.error("反序列化失败", e);
- }
- if (res == null) {
- throw new Exception("反序列化失败");
- }
- if (!"Z00001".equals(res.getStatus())) {
- throw new Exception("保信接口返回错误:" + res.getMsg());
- } else {//5.接口交互成功,返回数据处理
- initResultData = JSON.parseObject(JSON.toJSONString(res.getData()), InitResultData.class);
- }
- } catch (Exception e) {
- e.printStackTrace();
- HttpResult.error(e.getMessage());
- }
- return initResultData;
- }
- /**
- * 3.3订单号生成接口
- */
- @PostMapping(value = "/geneOrder")
- public HttpResult geneOrder(@RequestBody CBITBaseparam req_baseparam) {
- String url = url_pre + environment.getProperty("cbit.api3");
- String req_desc = "3.3订单号生成接口";
- String orderNo = "";
- try {
- checkBaseparam(req_baseparam);
- String reqno = geneReqNo();//请求流水号
- String reqtype = "Z00002";
- //1.生成初始化参数
- //CBITBaseparam baseparam=new CBITBaseparam(req_baseparam.getInsurerId(),reqno,reqtype,req_baseparam.getInsurerBranchCode(),req_baseparam.getFranchiserChannel().getFranchiserChannelId());
- req_baseparam.setRequestNo(reqno);
- req_baseparam.setRequestType(reqtype);
- CBITReqParam reqParam = geneReqParam(req_baseparam);
- //2.调用保信接口
- String req_json = JSON.toJSONString(reqParam);
- logger.info(req_desc + "--请求参数-->" + req_json);
- String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
- logger.info(req_desc + "--返回结果-->" + resp_json);
- //3.插入调保信接口日志表
- insertCbitLog(url, req_desc, reqno, req_json, resp_json);
- //4.处理保信接口返回数据
- ObjectMapper objectMapper = new ObjectMapper();
- ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
- CBITResponse res;
- try {
- res = reader.readValue(resp_json);
- } catch (IOException e) {
- res = null;
- logger.error("反序列化失败", e);
- }
- if (res == null) {
- throw new Exception("反序列化失败");
- }
- if (!"Z00001".equals(res.getStatus())) {
- return HttpResult.error("订单号生成错误,错误信息:" + res.getMsg());
- } else {//5.接口交互成功,返回数据处理
- JSONObject data = res.getData();
- orderNo = data.getString("orderNo");
- }
- } catch (Exception e) {
- e.printStackTrace();
- return HttpResult.error(e.getMessage());
- }
- return HttpResult.ok(orderNo);
- }
- /**
- * 3.5车型查询接口
- */
- @PostMapping(value = "/queryModel")
- public HttpResult queryModel(@RequestBody CarModelQryVo carModelQryVo) {
- String url = url_pre + environment.getProperty("cbit.api5");
- String req_desc = "3.5车型查询接口";
- CBITModelInfo cbitModelInfo = null;
- try {
- String reqno = geneReqNo();//请求流水号
- CBITBaseparam baseparam = carModelQryVo.getBaseParam();
- String insurerId = baseparam.getInsurerId();//
- String reqtype = "Z00004";
- baseparam.setRequestNo(reqno);
- baseparam.setRequestType(reqtype);
- String insurerBranchCode = baseparam.getInsurerBranchCode();
- String franchiserChannelId = baseparam.getFranchiserChannel().getFranchiserChannelId();
- if (StringUtils.isEmpty(franchiserChannelId)//中介网点代码
- || StringUtils.isEmpty(insurerId)//保险公司
- || StringUtils.isEmpty(insurerBranchCode)//二级机构编码
- ) {
- throw new Exception("insurerId/insurerBranchCode/franchiserChannelId,不能为空!");
- }
- if (StringUtils.isEmpty(baseparam.getOrderNo()) || StringUtils.isEmpty(carModelQryVo.getModelCName())//车辆型号
- || StringUtils.isEmpty(carModelQryVo.getEngineNo())//发动机号
- || StringUtils.isEmpty(carModelQryVo.getVin())//车架号
- || StringUtils.isEmpty(carModelQryVo.getNewVehicleFlag())//0:非新车,1:新车
- ) {
- throw new Exception("orderNo/modelCName/engineNo/vin/newVehicleFlag,不能为空!");
- }
- //1.生成初始化参数
- CBITReqParam reqParam = geneReqParam(baseparam);
- reqParam.setVehicleBrandModelKey(carModelQryVo.getModelCName());//车辆型号
- reqParam.setEngineNo(carModelQryVo.getEngineNo());//发动机号
- reqParam.setVin(carModelQryVo.getVin());//车架号
- reqParam.setNewVehicleFlag(carModelQryVo.getNewVehicleFlag());//0:非新车,1:新车
- //2.调用保信接口
- String req_json = JSON.toJSONString(reqParam);
- logger.info(req_desc + "--请求参数-->" + req_json);
- String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
- logger.info(req_desc + "--返回结果-->" + resp_json);
- //3.插入调保信接口日志表
- insertCbitLog(url, req_desc, reqno, req_json, resp_json);
- //4.处理保信接口返回数据
- ObjectMapper objectMapper = new ObjectMapper();
- ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
- CBITResponse res;
- try {
- res = reader.readValue(resp_json);
- } catch (IOException e) {
- res = null;
- logger.error("反序列化失败", e);
- }
- if (res == null) {
- throw new Exception("反序列化失败");
- }
- if (!"Z00001".equals(res.getStatus())) {
- return HttpResult.error(req_desc + "返回错误,错误信息:" + res.getMsg());
- } else {//5.接口交互成功,返回数据处理
- cbitModelInfo = JSON.parseObject(JSON.toJSONString(res.getData()), CBITModelInfo.class);
- }
- } catch (Exception e) {
- e.printStackTrace();
- return HttpResult.error(e.getMessage());
- }
- return HttpResult.ok(cbitModelInfo);
- }
- /**
- * 3.6车辆确认接口
- *
- * @param reqParam_in
- * @return
- */
- @PostMapping("/confirmVehicle")
- public HttpResult confirmVehicle(@RequestBody CBITReqParam reqParam_in) {
- String url = url_pre + environment.getProperty("cbit.api6");
- String req_desc = "3.6车辆确认接口";
- ConfirmVehicleResqData confirmVehicleResqData = null;
- try {
- String reqno = geneReqNo();//请求流水号
- CBITBaseparam baseparam = reqParam_in.getBaseParam();
- checkBaseparam(baseparam);
- String reqtype = "Z00005";
- baseparam.setRequestNo(reqno);
- baseparam.setRequestType(reqtype);
- //1.生成初始化参数
- CBITReqParam reqParam = geneReqParam(baseparam);
- reqParam.setCarOwner(reqParam_in.getCarOwner());
- reqParam.setHolder(reqParam_in.getHolder());
- reqParam.setInsureder(reqParam_in.getInsureder());
- reqParam.setVehicle(reqParam_in.getVehicle());
- //2.调用保信接口
- String req_json = JSON.toJSONString(reqParam);
- logger.info(req_desc + "--请求参数-->" + req_json);
- String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
- logger.info(req_desc + "--返回结果-->" + resp_json);
- //3.插入调保信接口日志表
- insertCbitLog(url, req_desc, reqno, req_json, resp_json);
- //4.处理保信接口返回数据
- ObjectMapper objectMapper = new ObjectMapper();
- ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
- CBITResponse res;
- try {
- res = reader.readValue(resp_json);
- } catch (IOException e) {
- res = null;
- logger.error("反序列化失败", e);
- }
- if (res == null) {
- throw new Exception("反序列化失败");
- }
- if (!"Z00001".equals(res.getStatus())) {
- return HttpResult.error(req_desc + "错误,错误信息:" + res.getMsg());
- } else {//5.接口交互成功,返回数据处理
- confirmVehicleResqData = JSON.parseObject(JSON.toJSONString(res.getData()), ConfirmVehicleResqData.class);
- }
- } catch (Exception e) {
- e.printStackTrace();
- return HttpResult.error(e.getMessage());
- }
- return HttpResult.ok(confirmVehicleResqData);
- }
- /**
- * 3.7报价
- *
- * @param quoteInfo
- * @return
- */
- @PostMapping("/quote")
- public HttpResult quote(@RequestBody QuoteInfoVo quoteInfo) {
- String url = url_pre + environment.getProperty("cbit.api7");
- String req_desc = "3.7报价";
- QuoteRespData quoteRespData = null;
- try {
- String reqno = geneReqNo();//请求流水号
- String reqtype = "Z00006";
- CBITBaseparam baseparam = quoteInfo.getBaseParam();
- checkBaseparam(baseparam);
- baseparam.setRequestNo(reqno);
- baseparam.setRequestType(reqtype);
- if (StringUtils.isEmpty(baseparam.getOrderNo())//订单号
- ) {
- throw new Exception("orderNo,不能为空!");
- }
- if (quoteInfo.getKindList() == null || quoteInfo.getKindList().size() == 0) {
- throw new Exception("kindList,不能为空!");
- }
- //1.生成初始化参数
- CBITReqParam reqParam = geneReqParam(baseparam);
- TrafficPolicy trafficPolicy = new TrafficPolicy(quoteInfo.getStartDate(), "T", "0");
- BusinessPolicy businessPolicy = new BusinessPolicy(quoteInfo.getStartDate(), quoteInfo.getKindList());
- reqParam.setTrafficPolicy(trafficPolicy);//需修改
- reqParam.setBusinessPolicy(businessPolicy);//需修改
- reqParam.setArgueSolution("1");
- reqParam.setCarVin(quoteInfo.getCarInfo().getVinNo());
- //2.调用保信接口
- String req_json = JSON.toJSONString(reqParam);
- logger.info(req_desc + "--请求参数-->" + req_json);
- String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
- logger.info(req_desc + "--返回结果-->" + resp_json);
- //3.插入调保信接口日志表
- insertCbitLog(url, req_desc, reqno, req_json, resp_json);
- //4.处理保信接口返回数据
- ObjectMapper objectMapper = new ObjectMapper();
- ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
- CBITResponse res;
- try {
- res = reader.readValue(resp_json);
- } catch (IOException e) {
- res = null;
- logger.error("反序列化失败", e);
- }
- if (res == null) {
- throw new Exception("反序列化失败");
- }
- if (!"Z00001".equals(res.getStatus())) {
- return HttpResult.error(req_desc + "错误,错误信息:" + res.getMsg());
- } else {//5.接口交互成功,返回数据处理
- quoteRespData = JSON.parseObject(JSON.toJSONString(res.getData()), QuoteRespData.class);
- }
- } catch (Exception e) {
- e.printStackTrace();
- return HttpResult.error(e.getMessage());
- }
- return HttpResult.ok(quoteRespData);
- }
- /**
- * 3.8核保接口
- *
- * @param reqParam_in
- * @return
- */
- @PostMapping("/submitAudit")
- public HttpResult submitAudit(@RequestBody CBITReqParam reqParam_in) {
- String url = url_pre + environment.getProperty("cbit.api8");
- String req_desc = "3.8核保接口";
- String reqno = geneReqNo();//请求流水号
- String reqtype = "Z00007";
- AuditRespData auditRespData = null;
- try {
- CBITBaseparam baseparam = reqParam_in.getBaseParam();
- checkBaseparam(baseparam);
- baseparam.setRequestNo(reqno);
- baseparam.setRequestType(reqtype);
- if (StringUtils.isEmpty(baseparam.getOrderNo())//订单号
- ) {
- throw new Exception("orderNo,不能为空!");
- }
- //1.生成初始化参数
- CBITReqParam reqParam = geneReqParam(baseparam);
- reqParam.setBusinessPolicy(reqParam_in.getBusinessPolicy());
- reqParam.setTrafficPolicy(reqParam_in.getTrafficPolicy());
- //2.调用保信接口
- String req_json = JSON.toJSONString(reqParam);
- logger.info(req_desc + "--请求参数-->" + req_json);
- String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
- logger.info(req_desc + "--返回结果-->" + resp_json);
- //3.插入调保信接口日志表
- insertCbitLog(url, req_desc, reqno, req_json, resp_json);
- //4.处理保信接口返回数据
- ObjectMapper objectMapper = new ObjectMapper();
- ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
- CBITResponse res;
- try {
- res = reader.readValue(resp_json);
- } catch (IOException e) {
- res = null;
- logger.error("反序列化失败", e);
- }
- if (res == null) {
- throw new Exception("反序列化失败");
- }
- if (!"Z00001".equals(res.getStatus())) {
- return HttpResult.error(req_desc + "错误,错误信息:" + res.getMsg());
- } else {//5.接口交互成功,返回数据处理
- auditRespData = JSON.parseObject(JSON.toJSONString(res.getData()), AuditRespData.class);
- }
- } catch (Exception e) {
- e.printStackTrace();
- return HttpResult.error(e.getMessage());
- }
- return HttpResult.ok(auditRespData);
- }
- /**
- * 3.14电子签名支付接口
- *
- * @return
- */
- @PostMapping("/pay_eleSign")
- public HttpResult eleSignPay(@RequestBody CBITBaseparam req_baseparam) {
- String url = url_pre + environment.getProperty("cbit.api14");
- String req_desc = "3.14电子签名支付接口";
- String reqno = geneReqNo();//请求流水号
- String reqtype = "Z00013";
- SignPayResqData signPayResqData = null;
- try {
- checkBaseparam(req_baseparam);
- if (StringUtils.isEmpty(req_baseparam.getOrderNo())//订单号
- ) {
- throw new Exception("orderNo,不能为空!");
- }
- //1.生成初始化参数
- req_baseparam.setRequestNo(reqno);
- req_baseparam.setRequestType(reqtype);
- CBITReqParam reqParam = geneReqParam(req_baseparam);
- //2.调用保信接口
- String req_json = JSON.toJSONString(reqParam);
- logger.info(req_desc + "--请求参数-->" + req_json);
- String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
- logger.info(req_desc + "--返回结果-->" + resp_json);
- //3.插入调保信接口日志表
- insertCbitLog(url, req_desc, reqno, req_json, resp_json);
- //4.处理保信接口返回数据
- ObjectMapper objectMapper = new ObjectMapper();
- ObjectReader reader = objectMapper.readerFor(CBITResponse.class);
- CBITResponse res;
- try {
- res = reader.readValue(resp_json);
- } catch (IOException e) {
- res = null;
- logger.error("反序列化失败", e);
- }
- if (res == null) {
- throw new Exception("反序列化失败");
- }
- if (!"Z00001".equals(res.getStatus())) {
- return HttpResult.error(req_desc + "错误,错误信息:" + res.getMsg());
- } else {//5.接口交互成功,返回数据处理
- signPayResqData = JSON.parseObject(JSON.toJSONString(res.getData()), SignPayResqData.class);
- }
- } catch (Exception e) {
- e.printStackTrace();
- return HttpResult.error(e.getMessage());
- }
- return HttpResult.ok(signPayResqData);
- }
- /**
- * 3.17投保单继续支付接口
- *
- * @return
- */
- @PostMapping("/pay_application")
- public HttpResult pay_application(@RequestBody CBITBaseparam req_baseparam) {
- String url = url_pre + environment.getProperty("cbit.api17");
- String req_desc = "3.17投保单继续支付接口";
- String reqno = geneReqNo();//请求流水号
- String reqtype = "Z00016";
- String data = "";
- try {
- checkBaseparam(req_baseparam);
- if (StringUtils.isEmpty(req_baseparam.getOrderNo())//订单号
- ) {
- throw new Exception("orderNo,不能为空!");
- }
- //1.生成初始化参数
- req_baseparam.setRequestNo(reqno);
- req_baseparam.setRequestType(reqtype);
- CBITReqParam reqParam = geneReqParam(req_baseparam);
- //2.调用保信接口
- String req_json = JSON.toJSONString(reqParam);
- logger.info(req_desc + "--请求参数-->" + req_json);
- String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
- logger.info(req_desc + "--返回结果-->" + resp_json);
- //3.插入调保信接口日志表
- insertCbitLog(url, req_desc, reqno, req_json, resp_json);
- //4.处理保信接口返回数据
- JSONObject resultMap = JSON.parseObject(resp_json.toString());
- String status = resultMap.getString("status");
- if (!"Z00001".equals(status)) {
- return HttpResult.error(req_desc + "错误,错误信息:" + resultMap.getString("msg"));
- } else {//5.接口交互成功,返回数据处理
- data = resultMap.getString("data");
- }
- } catch (Exception e) {
- e.printStackTrace();
- return HttpResult.error(e.getMessage());
- }
- return HttpResult.ok("", data);
- }
- /**
- * 3.18续保查询接口
- *
- * @return
- */
- @PostMapping("/queryPolicy")
- public HttpResult queryPolicy(@RequestBody CBITBaseparam req_baseparam) {
- String url = url_pre + environment.getProperty("cbit.api18");
- String req_desc = "3.18续保查询接口";
- String reqno = geneReqNo();//请求流水号
- String reqtype = "Z00017";
- String data = "";
- try {
- checkBaseparam(req_baseparam);
- //1.生成初始化参数
- req_baseparam.setRequestNo(reqno);
- req_baseparam.setRequestType(reqtype);
- CBITReqParam reqParam = geneReqParam(req_baseparam);
- reqParam.setCarVin("LNN3VKVKX57A22WWK");
- reqParam.setEngineNo("ENGTFE9QDKFU");
- //2.调用保信接口
- String req_json = JSON.toJSONString(reqParam);
- logger.info(req_desc + "--请求参数-->" + req_json);
- String resp_json = HttpsPostUtil.sendCBITPost(url, req_json, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY);
- logger.info(req_desc + "--返回结果-->" + resp_json);
- //3.插入调保信接口日志表
- insertCbitLog(url, req_desc, reqno, req_json, resp_json);
- //4.处理保信接口返回数据
- JSONObject resultMap = JSON.parseObject(resp_json.toString());
- String status = resultMap.getString("status");
- if (!"Z00001".equals(status)) {
- return HttpResult.error(req_desc + "错误,错误信息:" + resultMap.getString("msg"));
- } else {//5.接口交互成功,返回数据处理
- data = resultMap.getString("data");
- }
- } catch (Exception e) {
- e.printStackTrace();
- return HttpResult.error(e.getMessage());
- }
- return HttpResult.ok("", data);
- }
- /**
- * 3.19支付信息回调接口
- *
- * @return
- */
- @PostMapping("/updatePayInfo")
- public HttpServletResponse updatePayInfo(HttpServletRequest request, HttpServletResponse http_resp, @RequestBody Map<String, String> reqMap) {
- ReqParamCBIT reqParam_cbit = null;
- try {
- String req_bizContent = reqMap.get("bizContent");
- String req_sign = request.getHeader("Signature");
- String reqGetContent = RSAUtils.checkSignAndDecrypt(req_bizContent, req_sign, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY, "UTF-8", true, true);
- System.out.println("解密后的请求参数reqGetContent=" + reqGetContent);
- reqParam_cbit = JSON.parseObject(reqGetContent, ReqParamCBIT.class);
- String orderNo = reqParam_cbit.getOrderNo();
- String payResult = reqParam_cbit.getPayResult();
- //-------具体系统状态更新逻辑---------
- //拼装返回信息
- geneResponse(http_resp, reqParam_cbit);
- } catch (Exception e) {
- //记录报错日志表
- e.printStackTrace();
- String api_url = "/API/insCBIT/updatePayInfo";
- String errorinfo = e.getMessage();
- insertCbitError(reqParam_cbit, api_url, errorinfo);
- }
- return http_resp;
- }
- /**
- * 3.20保单结果回调接口
- *
- * @return
- */
- @PostMapping("/updatePolicyStatus")
- public HttpServletResponse updatePolicyStatus(HttpServletRequest request, HttpServletResponse http_resp, @RequestBody Map<String, String> reqMap) {
- ReqParamCBIT reqParam_cbit = null;
- try {
- String req_bizContent = reqMap.get("bizContent");
- String req_sign = request.getHeader("Signature");
- String reqGetContent = RSAUtils.checkSignAndDecrypt(req_bizContent, req_sign, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY, "UTF-8", true, true);
- System.out.println("解密后的请求参数reqGetContent=" + reqGetContent);
- reqParam_cbit = JSON.parseObject(reqGetContent, ReqParamCBIT.class);
- //-------具体系统状态更新逻辑---------
- //拼装返回信息
- geneResponse(http_resp, reqParam_cbit);
- } catch (Exception e) {
- //记录报错日志表
- e.printStackTrace();
- String api_url = "/API/insCBIT/updatePolicyStatus";
- String errorinfo = e.getMessage();
- insertCbitError(reqParam_cbit, api_url, errorinfo);
- }
- return http_resp;
- }
- private void geneResponse(HttpServletResponse http_resp, ReqParamCBIT reqParam_cbit) throws Exception {
- CBITBaseparam baseParam = new CBITBaseparam();
- baseParam.setRequestNo(reqParam_cbit.getBaseParam().getRequestNo());
- ResponseCBIT resp = new ResponseCBIT("Z00001", "处理成功", baseParam);
- String resp_str = JSON.toJSONString(resp);
- System.out.println("加密前返回参数resp_bizContent=" + resp_str);
- Map<String, String> encry = RSAUtils.encryptAndSign(resp_str, ZJPT_PUBLIC_KEY, HZHB_PRIVATE_KEY, "UTF-8", true, true);
- String resp_bizContent = encry.get("CONTENT");//密文
- System.out.println("加密后返回参数resp_bizContent=" + resp_bizContent);
- String resp_sign = encry.get("SIGNATURE");//签名,放在请求头中
- System.out.println("最终返回头中的签名resp_sign=" + resp_sign);
- Map<String, String> resp_Map = new HashMap<>();
- resp_Map.put("bizContent", resp_bizContent);
- String resp_Content = JSON.toJSONString(resp_Map);
- http_resp.setContentType("application/json;charset=utf-8");
- http_resp.addHeader("Accept", "application/json;charset=utf-8");
- http_resp.addHeader("Signature", resp_sign);
- http_resp.addHeader("PartnerCode", "p_taiyuantianqin");
- ServletOutputStream out = http_resp.getOutputStream();
- out.write(resp_Content.getBytes("UTF-8"));
- out.close();
- }
- @PostMapping(value = "/testCBIT")
- public void testjson() {
- System.out.println("--------------/testCBIT");
- String resp_json = environment.getProperty("resp_json");
- try {
- JSONObject resultMap = JSON.parseObject(resp_json.toString());
- String status = resultMap.getString("status");
- if (!"Z00001".equals(status)) {
- HttpResult.error("错误,错误信息:" + resultMap.getString("msg"));
- } else {//5.接口交互成功,返回数据处理
- String data = resultMap.getString("data");
- System.out.println(data);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void insertCbitLog(String url, String req_desc, String reqno, String req_json, String resp_json) {
- SysCbitLog cbitLog = new SysCbitLog();
- cbitLog.setReqNo(reqno);
- cbitLog.setUsercode("");
- // cbitLog.setUsercode(SecurityUtils.getUsername());
- cbitLog.setReqUrl(url);
- cbitLog.setDescription(req_desc);
- cbitLog.setReqParam(req_json);
- cbitLog.setResponse(resp_json);
- cbitLog.setCreatetime(new Date());
- sysCbitLogService.insert(cbitLog);
- }
- private String geneReqNo() {
- //中介机构id+UUID,每次请求需生成一个不重复的流水号,响应时原样返回
- return franchiserId + UUID.randomUUID();
- }
- private CBITReqParam geneReqParam(CBITBaseparam baseparam) throws Exception {
- CBITReqParam CBITReqParam = new CBITReqParam();
- //不能为空校验
- //String insurerId,String reqno,String reqtype,String insurerBranchCode,String franchiserChannelId
- if (StringUtils.isEmpty(baseparam.getInsurerId()) || StringUtils.isEmpty(baseparam.getRequestNo()) || StringUtils.isEmpty(baseparam.getRequestType()) || StringUtils.isEmpty(baseparam.getInsurerBranchCode()) || StringUtils.isEmpty(baseparam.getFranchiserChannel().getFranchiserChannelId())) {
- throw new Exception("insurerId, reqno, reqtype, insurerBranchCode, franchiserChannelId 这些参数不能为空!");
- }
- CBITBaseparam reqParam = new CBITBaseparam();
- reqParam.setFranchiserId(franchiserId);
- reqParam.setInsurerId(baseparam.getInsurerId());
- reqParam.setOrderNo(StringUtils.isEmpty(baseparam.getOrderNo()) ? "" : baseparam.getOrderNo());
- reqParam.setRequestNo(baseparam.getRequestNo());
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
- reqParam.setRequestTime(df.format(new Date()));
- reqParam.setRequestType(baseparam.getRequestType());
- reqParam.setIp(franchiserIp);
- reqParam.setInsurerBranchCode(baseparam.getInsurerBranchCode());
- reqParam.setPjOrderSourceCode(StringUtils.isEmpty(baseparam.getPjOrderSourceCode()) ? "" : baseparam.getPjOrderSourceCode());
- reqParam.setSysProductVersion(StringUtils.isEmpty(baseparam.getSysProductVersion()) ? "" : baseparam.getSysProductVersion());
- reqParam.setSysVersion(StringUtils.isEmpty(baseparam.getSysVersion()) ? "" : baseparam.getSysVersion());
- reqParam.setFranchiserInstitutionCode(StringUtils.isEmpty(baseparam.getFranchiserInstitutionCode()) ? "" : baseparam.getFranchiserInstitutionCode());
- reqParam.setFranchiserChannel(baseparam.getFranchiserChannel());
- CBITReqParam.setBaseParam(reqParam);
- return CBITReqParam;
- }
- private void checkBaseparam(CBITBaseparam baseparam) throws Exception {
- if (baseparam == null || StringUtils.isEmpty(baseparam.getFranchiserChannel().getFranchiserChannelId())//中介网点代码
- || StringUtils.isEmpty(baseparam.getInsurerId())//保险公司
- || StringUtils.isEmpty(baseparam.getInsurerBranchCode())//二级机构编码
- ) {
- throw new Exception("insurerId/insurerBranchCode/franchiserChannelId,不能为空!");
- }
- }
- private void insertCbitError(@RequestBody ReqParamCBIT reqParam_cbit, String api_url, String errorinfo) {
- SysCbitError sysCbitError = new SysCbitError();
- sysCbitError.setReqno(reqParam_cbit.getBaseParam().getRequestNo());
- sysCbitError.setRequrl(api_url);
- sysCbitError.setReqparam(JSON.toJSONString(reqParam_cbit));
- sysCbitError.setErrorinfo(errorinfo);
- sysCbitErrorService.insert(sysCbitError);
- }
- }
|