package com.nova.sankuai.infra.utils.wolaidai; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.map.MapUtil; // 工具类:Map工具 import cn.hutool.core.util.IdUtil; // 工具类:Id工具 import cn.hutool.crypto.symmetric.AES; // 工具类:AES import cn.hutool.json.JSONObject; // JSON处理类 import cn.hutool.json.JSONUtil; // JSON工具类 import com.alibaba.fastjson.JSON; // FastJson库 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; // MyBatis条件查询 import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.nova.sankuai.domain.api.rongbei.ApplyData; // 申请数据类 import com.nova.sankuai.domain.api.rongbei.RbResponse; // 响应结果类 import com.nova.sankuai.domain.api.yinsheng.SerialGenerator; import com.nova.sankuai.domain.dto.rongbei.ApplyDto; // 申请DTO import com.nova.sankuai.domain.dto.rongbei.ContactListDto; // 联系人列表DTO import com.nova.sankuai.domain.dto.rongbei.ProfileDictDto; import com.nova.sankuai.domain.dto.rongbei.RongBeBasicDto; // 融贝基础DTO import com.nova.sankuai.domain.entity.*; import com.nova.sankuai.infra.utils.ConstantsUtil; import com.nova.sankuai.infra.utils.eshidai.EsdUtil; import com.nova.sankuai.infra.utils.hht.HhtUtil; import com.nova.sankuai.infra.utils.hjqb.HjqbUtil; import com.nova.sankuai.infra.utils.qinghuayoupin.QingHuaYouPinUtil; import com.nova.sankuai.infra.utils.rongbei.RsaSupport; // RSA支持类 import com.nova.sankuai.infra.utils.sms.FirstMessage; import com.nova.sankuai.infra.utils.sms.shandongMessage.ShanDongMessageSendUtil; import com.nova.sankuai.infra.utils.syh.SyhUtil; import com.nova.sankuai.security.HttpClientUtil; // HTTP客户端工具类 import com.nova.sankuai.service.*; import lombok.Getter; import lombok.RequiredArgsConstructor; // Lombok的构造函数生成器 import org.apache.commons.lang3.StringUtils; // 字符串工具类 import org.jetbrains.annotations.NotNull; // NotNull注解 import org.slf4j.Logger; // 日志类 import org.slf4j.LoggerFactory; // 日志工厂类 import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; // Spring属性注入 import org.springframework.stereotype.Component; // 组件标识 import java.util.*; @Component @RequiredArgsConstructor // 构造器注入 public class WolaidaiUtil { private static final Logger log = LoggerFactory.getLogger("capitalLogger"); // 定义日志对象 // 定义请求常量 private static final String HUI_QIAN = "慧钱"; // 定义常量:慧钱 private static final String HUI_JIE = "慧借钱包"; // 定义常量:慧借钱包 private static final String SUI_BEI = "随呗"; // 定义常量:随呗 private static final String SHANG_CHENG = "商城"; // 定义常量:商城 private static final String MANG_XIAO_CHENG = "芒小橙-WLD"; // 定义常量:芒小橙品牌名,后缀为-WLD private static final String YI_CHENG_YOU_PIN = "易橙优品-WLD"; // 定义常量:易橙优品品牌名,后缀为-WLD private static final String HUI_GOU = "汇购-WLD"; // 定义常量:易橙优品品牌名,后缀为-WLD private static final String YING_XIANG_HUA = "盈享花-WLD"; // 定义常量:易橙优品品牌名,后缀为-WLD private static final int FUND_TYPE_BANK_LOAN = 1; // 资金类型:银行直贷 private static final int ENABLE_FLAG = 1; // 启用标志 private static final int DISABLE_FLAG = 0; // 禁用标志 private static final String SUCCESS_CODE = "0"; // 成功返回码 // 各种密钥和ID的注入 @Value("${rongbei.publicKey}") private String rbPublicKey; // 融呗公钥 @Value("${rongbei.wolaidai.publicKey}") private String wldPublicKey; // 我来贷公钥 @Value("${rongbei.privateKey}") private String privateKey; // 私钥 @Value("${rongbei.encryptKey}") private String encryptKey; // 加密密钥 @Value("${rongbei.partner_id}") private String RbPartnerId; // 融呗合作伙伴ID @Value("${rongbei.h5Url}") private String rbH5Url; // 融呗h5Url @Value("${rongbei.h5HalfUrl}") private String h5HalfUrl; // 融呗非半流程h5Url @Value("${rongbei.wolaidai.url}") private String wldUrl; // 我来贷URL @Value("${rongbei.shangcheng.ip}") private String scUrl; // 商城URL @Value("${rongbei.shangcheng.h5Url}") private String scH5Url; // 商城h5Url @Value("${rongbei.shangcheng.partner_id}") private String scParentId; // 商城合作伙伴ID @Value("${rongbei.shangcheng.publicKey}") private String scPublicKey; // 商城公钥 @Value("${rongbei.hjqb.ip}") private String hjUrl; // 慧钱URL @Value("${rongbei.hjqb.h5Url}") private String hjH5Url; // 慧钱h5Url @Value("${rongbei.hjqb.partner_id}") private String hjParnterId; // 慧钱合作伙伴ID @Value("${rongbei.hjqb.publicKey}") private String hjPublicKey; // 慧钱公钥 @Value("${rongbei.mxch.ip}") private String mxchUrl; // 芒小橙URL @Value("${rongbei.mxch.h5Url}") private String mxchH5Url; // 芒小橙h5Url @Value("${rongbei.mxch.partner_id}") private String mxchParnterId; // 芒小橙ID @Value("${rongbei.mxch.publicKey}") private String mxchPublicKey; // 芒小橙公钥 @Value("${rongbei.ycyp.ip}") private String ycypUrl; // 易橙优品URL @Value("${rongbei.ycyp.h5Url}") private String ycypH5Url; // 易橙优品h5Url @Value("${rongbei.ycyp.partner_id}") private String ycypParnterId; // 易橙优品ID @Value("${rongbei.ycyp.publicKey}") private String ycypPublicKey; // 易橙优品公钥 @Value("${rongbei.huigou.ip}") private String hgUrl; // 汇购URL @Value("${rongbei.huigou.h5Url}") private String hgH5Url; // 汇购h5Url @Value("${rongbei.huigou.partner_id}") private String hgParnterId; // 汇购ID @Value("${rongbei.huigou.publicKey}") private String hgPublicKey; // 汇购公钥 @Value("${rongbei.yingxianghua.ip}") private String yxhUrl; // 盈享花URL @Value("${rongbei.yingxianghua.h5Url}") private String yxhH5Url; // 盈享花品h5Url @Value("${rongbei.yingxianghua.partner_id}") private String yxhParnterId; // 盈享花ID @Value("${rongbei.yingxianghua.publicKey}") private String yxhPublicKey; // 盈享花公钥 @Value("${rongbei.wld.ip}") private String wlddUrl; // 随呗URL @Value("${rongbei.wld.h5Url}") private String wldH5Url; // 慧钱h5Url @Value("${rongbei.wld.partner_id}") private String wlddParnterId; // 随呗代理合作伙伴ID @Value("${rongbei.wld.publicKey}") private String wlddPublicKey; // 我来贷代理公钥 @Value("${rongbei.wolaidai.sms_notify_url}") private String smsNotifyUrl; // 我来贷短信通知URL private final ICustomerZcyService customerZcyService; // 客户ZCY服务 private final ICustomerApplyOrderService customerApplyOrderService; // 客户申请订单服务 private final ICustomerCheckRecordService customerCheckRecordService; // 用户准入务 private final ICustomerH5ClickService customerH5ClickService; // H5用户点击埋点服务 private final ICapitalInfoService capitalInfoService; // 资金信息服务 private final EsdUtil esdUtil; private final HjqbUtil hjqbUtil; private final SyhUtil syhUtil; private final HhtUtil hhtUtil; private final QingHuaYouPinUtil qingHuaYouPinUtil; public RbResponse saveH5ClickRecord(String mobile, Integer type){ CustomerH5Click customerH5Click = new CustomerH5Click(); customerH5Click.setMobile(mobile); customerH5Click.setType(type); customerH5ClickService.save(customerH5Click); RbResponse resp = new RbResponse(); resp.setCode("0"); resp.setMsg("保存成功"); return resp; } /** * 设置公共的查询条件 * @return LambdaQueryWrapper */ private LambdaQueryWrapper getWrapper(){ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); // 创建查询条件 wrapper.eq(CapitalInfo::getFundType, FUND_TYPE_BANK_LOAN); // 资金类型:银行直贷 wrapper.eq(CapitalInfo::getEnableFlag, ENABLE_FLAG); // 是否启用:启用 wrapper.eq(CapitalInfo::getAuditSwitch, DISABLE_FLAG); // 审核开关:不启用 return wrapper; } /** * 获取要推送的半流程资方 * @return 资金信息列表 */ private List getCapitalInfoList() { LambdaQueryWrapper wrapper = this.getWrapper(); // 创建查询条件 wrapper.eq(CapitalInfo::getIsTopView, DISABLE_FLAG); // 显示主界面顶部:否 wrapper.eq(CapitalInfo::getIsShowPage, DISABLE_FLAG); // 是否显示首页:否 wrapper.eq(CapitalInfo::getAutoPush, ENABLE_FLAG); // 自动推送:不启用 wrapper.eq(CapitalInfo::getCollionMode, ENABLE_FLAG); // 联登模式:半流程 wrapper.isNull(CapitalInfo::getAlwayShow); // 是否一直显示:是 wrapper.orderByAsc(CapitalInfo::getSeq); // 按序号升序排列 return capitalInfoService.list(wrapper); // 返回匹配的资金信息列表 } /** * 获取要推送的非半流程资方 * @return 资金信息列表 */ private List getNotHalfCapitalInfoList() { LambdaQueryWrapper wrapper = this.getWrapper(); wrapper.eq(CapitalInfo::getAutoPush, DISABLE_FLAG); // 自动推送:启用 wrapper.eq(CapitalInfo::getCollionMode, DISABLE_FLAG); // 联登模式:非半流程 wrapper.orderByAsc(CapitalInfo::getSeq); // 按序号升序排列 return capitalInfoService.list(wrapper); // 返回匹配的资金信息列表 } /** * 获取要推送的非半流程资金类型线上资方 * @return 资金信息列表 */ private List getNotHalfFundTypeCapitalInfoList() { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); wrapper.eq(CapitalInfo::getFundType, 0); // 资金类型:线上贷款 wrapper.eq(CapitalInfo::getEnableFlag, ENABLE_FLAG); // 是否启用:启用 wrapper.eq(CapitalInfo::getAutoPush, DISABLE_FLAG); // 自动推送:启用 wrapper.eq(CapitalInfo::getCollionMode, DISABLE_FLAG); // 联登模式:非半流程 wrapper.eq(CapitalInfo::getIsCollion, DISABLE_FLAG);//联登开关 不启用 wrapper.eq(CapitalInfo::getAuditSwitch, DISABLE_FLAG); // 审核开关:不启用 wrapper.eq(CapitalInfo::getExternalSwitch, ENABLE_FLAG); wrapper.isNull(CapitalInfo::getAlwayShow);//是否一直显示 是 wrapper.orderByAsc(CapitalInfo::getSeq); // 按序号升序排列 return capitalInfoService.list(wrapper); // 返回匹配的资金信息列表 } /** * 根据资金名获取配置 * @param capitalName 资金名 * @return 配置映射 */ private Map getConfigByCapitalName(String capitalName) { // 创建配置映射 Map config = new HashMap<>(); switch (capitalName) { case HUI_QIAN: // 如果是慧钱 config.put("partnerId", hjParnterId); // 设置合作伙伴ID config.put("publicKey", hjPublicKey); // 设置公钥 config.put("basicUrl", hjUrl); // 设置基础URL config.put("h5Url", hjH5Url); // 设置H5Url break; case SUI_BEI: // 如果是随呗 config.put("partnerId", wlddParnterId); // 设置合作伙伴ID config.put("publicKey", wlddPublicKey); // 设置公钥 config.put("basicUrl", wlddUrl); // 设置基础URL config.put("h5Url", wldH5Url); // 设置H5Url break; case SHANG_CHENG: // 如果是商城 config.put("partnerId", scParentId); // 设置合作伙伴ID config.put("publicKey", scPublicKey); // 设置公钥 config.put("basicUrl", scUrl); // 设置基础URL config.put("h5Url", scH5Url); // 设置H5Url break; case MANG_XIAO_CHENG: // 如果是芒小橙 config.put("partnerId", mxchParnterId); // 设置合作伙伴ID config.put("publicKey", mxchPublicKey); // 设置公钥 config.put("basicUrl", mxchUrl); // 设置基础URL config.put("h5Url", mxchH5Url); // 设置H5Url break; case YI_CHENG_YOU_PIN: // 如果是易橙优品 config.put("partnerId", ycypParnterId); // 设置合作伙伴ID config.put("publicKey", ycypPublicKey); // 设置公钥 config.put("basicUrl", ycypUrl); // 设置基础URL config.put("h5Url", ycypH5Url); // 设置H5Url break; case HUI_GOU: // 如果是汇购 config.put("partnerId", hgParnterId); // 设置合作伙伴ID config.put("publicKey", hgPublicKey); // 设置公钥 config.put("basicUrl", hgUrl); // 设置基础URL config.put("h5Url", hgH5Url); // 设置H5Url break; case YING_XIANG_HUA: // 如果是盈享花 config.put("partnerId", yxhParnterId); // 设置合作伙伴ID config.put("publicKey", yxhPublicKey); // 设置公钥 config.put("basicUrl", yxhUrl); // 设置基础URL config.put("h5Url", yxhH5Url); // 设置H5Url break; default: // 其他情况,保持为空 break; } return config; // 返回配置映射 } @Getter private enum ActionEnum { CHECK("check", "准入接口"), APPLY("apply", "进件接口"), ORDER_STATUS("order_status", "查询订单状态接口"), CONCLUSION("conclusion", "查询授信结果"), REPAY_INFO("repay_info", "查询还款计划接口"), H5_URL("h5_url", "获取跳转H5页面地址接口"); private final String actionName; // 动作名称 private final String targetName; // 目标名称 ActionEnum(String actionName, String targetName) { this.actionName = actionName; this.targetName = targetName; } } /** * 根据方法名返回相应的数据 * @param action 方法名 * @return 配置映射 */ private Map getBasicInfoByAction(String action) { // 创建配置映射 Map basicInfo = new HashMap<>(); // 根据输入的动作名称进行配置映射 for (ActionEnum enumAction : ActionEnum.values()) { if (enumAction.getActionName().equals(action)) { basicInfo.put("targetName", enumAction.getTargetName()); basicInfo.put("url", enumAction.getActionName()); break; } } return basicInfo; // 返回配置映射 } /** * 接收我来贷请求的数据并中转给下游资方 * @param body 请求体 * @param action 方法名 * @return RbResponse */ public RbResponse wld2ThirdPlatform(RongBeBasicDto body, String action) { RbResponse resp = new RbResponse(); // 初始化响应对象 String logNumber = IdUtil.randomUUID(); // 生成日志编号 JSONObject hjData = new JSONObject();// 创建返回数据的JSON对象 Map basicInfo = getBasicInfoByAction(action); boolean flag = false; String decryptStr = ""; resp.setMsg("成功"); try { log.info("日志编号:{} , {}方法:{}, 接收到的数据:{}", logNumber, basicInfo.get("targetName"), action, body); // 记录接收的数据 JSONObject getFullData = new JSONObject(); // 创建JSON对象存储数据 getFullData.putOpt("partner_id", body.getPartner_id()); // 存储合作伙伴ID getFullData.putOpt("timestamp", body.getTimestamp()); // 存储时间戳 getFullData.putOpt("biz_data", body.getBiz_data()); // 存储业务数据 // 解密+验签 decryptStr = decrypt(getFullData, body.getSign(), wldPublicKey);// 解密 String chnOrderId = ""; log.info("日志编号:{}, , {}方法:{}, 解密接收到的数据:{}", logNumber, basicInfo.get("targetName"), action, decryptStr); // 记录解密数据 if (StringUtils.isNotEmpty(decryptStr)) { // 判断解密结果是否有效 Customer customer = new Customer(); if (Objects.equals(action, "apply")) { // 修改借款额度,采用随机生成 Random random = new Random(); int lowerBound = 5000; // 最小值 int upperBound = 50000; // 最大值 // 生成随机的100倍数 int randomValue = lowerBound + (random.nextInt((upperBound - lowerBound) / 100 + 1) * 100); // 数据保存到数据库中 ApplyDto applyDto = JSON.parseObject(decryptStr, ApplyDto.class); ProfileDictDto profileDictDto = applyDto.getProfile_dict(); profileDictDto.setRequest_amount(String.valueOf(randomValue)); applyDto.setProfile_dict(profileDictDto); chnOrderId = applyDto.getChn_order_id(); log.info("日志编号:{},{}方法:{}, 保存进件数据:{}", logNumber, basicInfo.get("targetName"), action, applyDto); customer = saveData(applyDto); JSON.toJSONString(applyDto); decryptStr = JSON.toJSONString(applyDto); //发送短信通知(等待供应商审批短信模板 申请完后在恢复注释) //smsNotify(profileDictDto.getPhone()); } String bizDataStr = ""; String fBizDataStr = ""; String capitalName = ""; String fCapitalName = ""; if (Objects.equals(action, "h5_url")) { JSONObject h5 = JSON.parseObject(decryptStr, JSONObject.class); LambdaQueryWrapper wr = new LambdaQueryWrapper<>(); wr.eq(CustomerApplyOrder::getChnOrderId, h5.getStr("chn_order_id")); wr.eq(CustomerApplyOrder::getPartnerFlowId, h5.getStr("partner_flow_id")); wr.last(" limit 1 "); CustomerApplyOrder customerApplyOrder = customerApplyOrderService.getOne(wr); if (!Objects.isNull(customerApplyOrder)) { JSONObject obj = new JSONObject(); Long capitalId = customerApplyOrder.getCapitalId(); String h5Url = ""; // 如果是慧钱,随易花,e时贷,好汇推,则转为乐享融的指定id:28 if (capitalId == 12L || capitalId == 41L || capitalId == 36L || capitalId == 25L || capitalId == 4L) { h5Url = h5HalfUrl + "&capitalId="+ capitalId + "&mobile=" + customerApplyOrder.getPhone(); //h5Url = rbH5Url + "&capitalId=28"; }else{ //h5Url = rbH5Url + "&capitalId="+ capitalId + "&mobile=" + customerApplyOrder.getPhone(); h5Url = rbH5Url + "&capitalId="+ capitalId; } obj.putOpt("url", h5Url); obj.putOpt("remind", ""); bizDataStr = String.valueOf(obj); capitalName = customerApplyOrder.getCapitalName(); flag = true; } }else { // 遍历半流程资金信息列表 List capitalInfoList = getCapitalInfoList(); for (CapitalInfo capitalInfo : capitalInfoList) { Map config = getConfigByCapitalName(capitalInfo.getName());// 获取对应的配置 log.info("日志编号:{},{}方法:{}, 资方名:【{}】,config配置信息: {}", logNumber, basicInfo.get("targetName"), action, capitalInfo.getName(), config); // 记录资金信息 JSONObject fullData = new JSONObject();// 创建完整数据的JSON对象 fullData.putOpt("partner_id", config.get("partnerId")); // 设置合作伙伴ID fullData.putOpt("timestamp", System.currentTimeMillis());// 设置当前时间戳 fullData.putOpt("biz_data", encrypt(decryptStr)); // 设置业务数据 //生成新的签名 fullData.putOpt("sign", getSign(fullData, config.get("publicKey")));// 计算签名 String result = null;// 初始化结果 if (StringUtils.isNotEmpty(config.get("basicUrl"))) {// 如果基础URL有效 try { result = HttpClientUtil.getInstance().postJsonData(config.get("basicUrl") + basicInfo.get("url"), String.valueOf(fullData)); // 调用接口 log.info("日志编号:{},{}方法:{},资方名:【{}】,参数:{},result: {}", logNumber, basicInfo.get("targetName"), action, capitalInfo.getName(), fullData, result);// 记录接口结果 } catch (Exception ex) { // 处理请求异常 resp.setMsg(ex.getMessage());// 设置响应消息 log.error("日志编号:{},{}方法:{}, 资方名:【{}】,传参:{} ex:{}", logNumber, basicInfo.get("targetName"), action, capitalInfo.getName(), fullData, ex.getMessage());//记录异常堆栈 } // 将result解析为响应对象 try { if (result != null) { // 确保result不为空 resp = JSON.parseObject(result, RbResponse.class);// 解析响应 String data = resp.getData();// 获取数据部分 RongBeBasicDto rb = JSON.parseObject(data, RongBeBasicDto.class); // 解析业务DTO hjData.putOpt("biz_data", rb.getBiz_data());// 获取业务数据 if (Objects.equals(resp.getCode(), SUCCESS_CODE)) { // // 判断是否成功 // 解密biz_data hjData.putOpt("partner_id", rb.getPartner_id()); // 设置合作伙伴ID为融呗,我来贷只认融呗的信息 hjData.putOpt("timestamp", rb.getTimestamp()); // 设置时间戳 String decryptHjStr = decrypt(hjData, rb.getSign(), config.get("publicKey"));// 解密hjData if (StringUtils.isNotEmpty(decryptHjStr)) {// 判断解密结果 if (Objects.equals(action, "check")) { JSONObject de = JSON.parseObject(decryptHjStr, JSONObject.class); /*if (de.getInt("status") == 1) { if (StringUtils.isEmpty(bizDataStr)) { bizDataStr = decryptHjStr; capitalName = capitalInfo.getName(); } }else { if (StringUtils.isEmpty(fBizDataStr)) { fBizDataStr = decryptHjStr; fCapitalName = capitalInfo.getName(); } }*/ // ab修改于2024-10-20号,应张小明的提的需求,准入默认全部为通过状态 if (StringUtils.isEmpty(bizDataStr)) { JSONObject obj = new JSONObject(); obj.putOpt("status", 1); obj.putOpt("retry_ts", (System.currentTimeMillis() + (1000 * 60 * 60 * 24)) / 1000); bizDataStr = String.valueOf(obj); capitalName = capitalInfo.getName(); } // 保存准入记录 CustomerCheckRecord customerCheckRecord = getCustomerCheckRecord(capitalInfo.getId(), capitalInfo.getName(), decryptStr, de.getInt("status")); customerCheckRecordService.save(customerCheckRecord); } else if (Objects.equals(action, "apply")) { ApplyData applyData = JSON.parseObject(decryptHjStr, ApplyData.class); if (applyData.getStatus() == 0) { // 进件成功后才保存 if (StringUtils.isEmpty(bizDataStr)) { bizDataStr = decryptHjStr; capitalName = capitalInfo.getName(); } // 进件成功后,调用接受订单状态接口推送数据给我来贷 OrderStatusByWld(chnOrderId, applyData.getPartner_flow_id()); // 调用接受授信结果接口推送授信结果给我来贷 autoPushCreditResult(chnOrderId, applyData.getPartner_flow_id()); }else { if (StringUtils.isEmpty(fBizDataStr)) { fBizDataStr = decryptHjStr; fCapitalName = capitalInfo.getName(); } } // 保存进件记录 CustomerApplyOrder customerApplyOrder = getCustomerApplyOrder(chnOrderId, applyData, capitalInfo, config.get("partnerId"), decryptStr); customerApplyOrderService.save(customerApplyOrder); } else if (Objects.equals(action, "h5_url")) { // 如果是获取h5跳转链接地址,则重置链接为融呗 JSONObject h5UrlData = JSON.parseObject(decryptHjStr, JSONObject.class); h5UrlData.putOpt("url", config.get("h5Url")); bizDataStr = String.valueOf(h5UrlData); if (StringUtils.isEmpty(bizDataStr)) { bizDataStr = decryptHjStr; capitalName = capitalInfo.getName(); } } else { if (StringUtils.isEmpty(bizDataStr)) { bizDataStr = decryptHjStr; capitalName = capitalInfo.getName(); } } flag = true; resp.setMsg("成功"); log.info("日志编号:{},【{}】,{}解密结果:{}", logNumber, capitalInfo.getName(), basicInfo.get("targetName"), decryptHjStr); } else { log.error("日志编号:{}, 【{}】,{}解密结果失败:{}", logNumber, capitalInfo.getName(), basicInfo.get("targetName"), decryptHjStr); } } else { log.error("日志编号:{},【{}】{}检测失败:{}", logNumber, capitalInfo.getName(), basicInfo.get("targetName"), result); } } } catch (Exception ex) { log.error("日志编号:{}, 【{}】{}推送原始返回参数转换失败,jsonData:{} ex:{}", logNumber, capitalInfo.getName(), basicInfo.get("targetName"), fullData, ex.getMessage());// 记录解析异常 } } } // 遍历非半流程资金信息列表 boolean halfFlag = false; List lst = getNotHalfCapitalInfoList(); log.info("日志编号:{},{}方法:{}, 非半流程的资方列表:【{}】", logNumber, basicInfo.get("targetName"), action, lst); // 非半流程的资方列表 if (!flag) { if (Objects.equals(action, "check")) { if (!lst.isEmpty()) { if (StringUtils.isEmpty(bizDataStr)) { JSONObject obj = new JSONObject(); obj.putOpt("status", 1); obj.putOpt("retry_ts", (System.currentTimeMillis() + (1000 * 60 * 60 * 24)) / 1000); bizDataStr = String.valueOf(obj); capitalName = lst.get(0).getName(); flag = true; } } } } for (CapitalInfo capitalInfo : lst) { log.info("日志编号:{},{}方法:{}, 非半流程资方名:【{}】", logNumber, basicInfo.get("targetName"), action, capitalInfo.getName()); // 记录资金信息 if (Objects.equals(action, "check")) { // 保存准入记录 CustomerCheckRecord customerCheckRecord = getCustomerCheckRecord(capitalInfo.getId(), capitalInfo.getName(), decryptStr, 1); customerCheckRecordService.save(customerCheckRecord); }else if (Objects.equals(action, "apply")) { ApplyData applyData = new ApplyData(); applyData.setStatus(1); applyData.setPartner_flow_id(""); //调用对应资方的推送机制 if (capitalInfo.getId() == 25L) { //e时贷 halfFlag = esdUtil.wldPushToEsd(customer, logNumber); if (halfFlag) { applyData.setStatus(0); applyData.setPartner_flow_id(SerialGenerator.getOrder()); flag = true; } } else if (capitalInfo.getId() == 12L) { //慧借钱包 halfFlag = hjqbUtil.wldPushToHjqb(customer, logNumber); if (halfFlag) { applyData.setStatus(0); applyData.setPartner_flow_id(SerialGenerator.getOrder()); flag = true; } } else if (capitalInfo.getId() == 41L) { //好汇推 halfFlag = hhtUtil.wldPushToHht(customer, logNumber); if (halfFlag) { applyData.setStatus(0); applyData.setPartner_flow_id(SerialGenerator.getOrder()); flag = true; } } else if (capitalInfo.getId() == 36L) { //随易花 halfFlag = syhUtil.wldPushToSyh(customer, logNumber); if (halfFlag) { applyData.setStatus(0); applyData.setPartner_flow_id(SerialGenerator.getOrder()); flag = true; } } if (StringUtils.isEmpty(bizDataStr) && StringUtils.isEmpty(fBizDataStr)) { bizDataStr = JSONUtil.toJsonStr(applyData); capitalName = capitalInfo.getName(); } if (halfFlag) { // 进件成功后,调用接受订单状态接口推送数据给我来贷 OrderStatusByWld(chnOrderId, applyData.getPartner_flow_id()); // 调用接受授信结果接口推送授信结果给我来贷 autoPushCreditResult(chnOrderId, applyData.getPartner_flow_id()); } // 保存进件记录 CustomerApplyOrder customerApplyOrder = getCustomerApplyOrder(chnOrderId, applyData, capitalInfo, "28", decryptStr); customerApplyOrderService.save(customerApplyOrder); } } // 遍历非半流程资金方式线上贷款信息列表 List notHalfFundTypeCapitalInfoList = getNotHalfFundTypeCapitalInfoList(); boolean halfFundTypeFlag = false; for (CapitalInfo capitalInfo : notHalfFundTypeCapitalInfoList) { log.info("日志编号:{},{}方法:{}, 资方名:【{}】", logNumber, basicInfo.get("targetName"), action, capitalInfo.getName()); // 记录资金信息 if (Objects.equals(action, "check")) { // 保存准入记录 CustomerCheckRecord customerCheckRecord = getCustomerCheckRecord(capitalInfo.getId(), capitalInfo.getName(), decryptStr, 1); customerCheckRecordService.save(customerCheckRecord); } else if (Objects.equals(action, "apply")) { ApplyData applyData = new ApplyData(); applyData.setStatus(1); applyData.setPartner_flow_id(""); //调用对应资方的推送机制 if (capitalInfo.getId() == 4L) { //青花优品 ApplyDto applyDto = JSON.parseObject(decryptStr, ApplyDto.class); customer.setCreditNo(ConstantsUtil.getCreditNo()); halfFundTypeFlag = qingHuaYouPinUtil.wldPushToQHYP(capitalInfo, applyDto, customer, logNumber); if (halfFundTypeFlag) { applyData.setStatus(0); applyData.setPartner_flow_id(customer.getCreditNo()); flag = true; } } if (StringUtils.isEmpty(bizDataStr) && StringUtils.isEmpty(fBizDataStr)) { bizDataStr = JSONUtil.toJsonStr(applyData); capitalName = capitalInfo.getName(); } if (halfFundTypeFlag) { // 进件成功后,调用接受订单状态接口推送数据给我来贷 OrderStatusByWld(chnOrderId, applyData.getPartner_flow_id()); // 调用接受授信结果接口推送授信结果给我来贷 autoPushCreditResult(chnOrderId, applyData.getPartner_flow_id()); } // 保存进件记录 CustomerApplyOrder customerApplyOrder = getCustomerApplyOrder(chnOrderId, applyData, capitalInfo, "28", decryptStr); customerApplyOrderService.save(customerApplyOrder); } } } if (flag) { if (StringUtils.isEmpty(bizDataStr)) { bizDataStr = fBizDataStr; capitalName = fCapitalName; } // 返回最小序号的数据给我来贷 log.info("日志编号:{},{}方法返回最小资方【{}】的数据:{}", logNumber, action, capitalName, bizDataStr); hjData.putOpt("partner_id", RbPartnerId); hjData.putOpt("timestamp", System.currentTimeMillis()); hjData.putOpt("biz_data", encrypt(bizDataStr)); // 重新签名 hjData.putOpt("sign", getSign(hjData, wldPublicKey)); } } else { resp.setMsg("验签失败"); log.error("日志编号:{},【我来贷】{}参数验签失败,jsonData:{} ex:{}", logNumber, basicInfo.get("targetName"), body, "验签失败"); } } catch (Exception e) { resp.setMsg(e.getMessage()); log.error("日志编号:{},【我来贷】{},请求失败:{} 错误原因:{}", logNumber, basicInfo.get("targetName"), body, e.getMessage()); } if (!flag) { // 数据检测不过,则返回对应的数据格式 hjData.putOpt("partner_id", RbPartnerId); hjData.putOpt("timestamp", System.currentTimeMillis()); JSONObject bizData = new JSONObject(); if (Objects.equals(action, "check")) { bizData.putOpt("status", 2); //最好是1天以上 bizData.putOpt("retry_ts", (System.currentTimeMillis() + (1000 * 60 * 60 * 24)) / 1000); // 保存准入记录 CustomerCheckRecord customerCheckRecord = getCustomerCheckRecord(0L, "", decryptStr, 0); customerCheckRecordService.save(customerCheckRecord); }else if (Objects.equals(action, "apply")) { bizData.putOpt("status", 1); bizData.putOpt("partner_flow_id", ""); bizData.putOpt("msg", "请求失败"); }else if (Objects.equals(action, "order_status")) { bizData.putOpt("status", 100); bizData.putOpt("chn_order_id", ""); bizData.putOpt("update_time", System.currentTimeMillis() / 1000); }else if (Objects.equals(action, "h5_url")) { bizData.putOpt("url", ""); bizData.putOpt("remind", ""); }else{ bizData.putOpt("status", 1); bizData.putOpt("msg", "请求失败"); } hjData.putOpt("biz_data", encrypt(String.valueOf(bizData))); hjData.putOpt("sign", getSign(hjData, wldPublicKey)); } resp.setCode("0"); resp.setData(String.valueOf(hjData)); return resp; } private static @NotNull CustomerApplyOrder getCustomerApplyOrder(String chnOrderId, ApplyData applyData, CapitalInfo capitalInfo, String partnerId, String decryptStr) { CustomerApplyOrder customerApplyOrder = new CustomerApplyOrder(); customerApplyOrder.setCapitalId(capitalInfo.getId()); customerApplyOrder.setCapitalName(capitalInfo.getName()); customerApplyOrder.setChnOrderId(chnOrderId); customerApplyOrder.setPartnerFlowId(applyData.getPartner_flow_id()); customerApplyOrder.setStatus(applyData.getStatus() == 0 ? 0 : 1); customerApplyOrder.setType(1); customerApplyOrder.setPartnerId(partnerId); JSONObject de = JSON.parseObject(decryptStr, JSONObject.class); customerApplyOrder.setName(de.getJSONObject("profile_dict").getStr("name")); customerApplyOrder.setPhone(de.getJSONObject("profile_dict").getStr("phone")); log.error("日志编号:{},【{}】保存进件记录开始,customerApplyOrder:{}", IdUtil.randomUUID(), capitalInfo.getName(), customerApplyOrder); return customerApplyOrder; } private static @NotNull CustomerCheckRecord getCustomerCheckRecord(Long capitalId, String capitalName, String decryptStr, Integer status) { CustomerCheckRecord customerCheckRecord = new CustomerCheckRecord(); JSONObject de = JSON.parseObject(decryptStr, JSONObject.class); customerCheckRecord.setCapitalId(capitalId); customerCheckRecord.setCapitalName(capitalName); customerCheckRecord.setMd5Phone(de.getStr("md5_phone")); customerCheckRecord.setMd5Idcard(de.getStr("md5_idcard")); customerCheckRecord.setMd5Name(de.getStr("md5_name")); customerCheckRecord.setPreIdNo(de.getStr("pre_id_no")); customerCheckRecord.setMaskPhone(de.getStr("mask_phone")); customerCheckRecord.setMaskIdcard(de.getStr("mask_idcard")); customerCheckRecord.setStatus(status == 1 ? status : 0); customerCheckRecord.setType(1); log.error("日志编号:{},【{}】保存准入记录开始,customerCheckRecord:{}", IdUtil.randomUUID(), capitalName, customerCheckRecord); return customerCheckRecord; } /** * 保存数据 * @param applyDto 数据对象 */ private Customer saveData(ApplyDto applyDto) { LambdaQueryWrapper wr = new LambdaQueryWrapper<>(); wr.eq(CustomerZcy::getPhone, applyDto.getProfile_dict().getPhone()); wr.last(" limit 1 "); CustomerZcy customerZcy = customerZcyService.getOne(wr); if (Objects.isNull(customerZcy)) { customerZcy = new CustomerZcy(); //联系人列表(两个联系人) List contList = applyDto.getContact_list(); int conSize = contList.size(); for (int j = 0; j < conSize; j++) { ContactListDto dto = contList.get(j); String relationShip = getRelationShip(dto); if (j == 0) { customerZcy.setRelationshipName(dto.getName()); customerZcy.setRelationshipPhone(dto.getPhone()); customerZcy.setRelationship(relationShip); } if (j == 1) { customerZcy.setRelationship1Name(dto.getName()); customerZcy.setRelationship1Phone(dto.getPhone()); customerZcy.setRelationship1(relationShip); } } // 详细资料 customerZcy.setName(applyDto.getProfile_dict().getName()); customerZcy.setPhone(applyDto.getProfile_dict().getPhone()); customerZcy.setLoanAmount(Double.valueOf(applyDto.getProfile_dict().getRequest_amount())); Random random = new Random(); int[] values = {1, 2, 3, 4, 5}; // 指定的字符集合 customerZcy.setLoanTerm(values[random.nextInt(values.length)]); customerZcy.setIdCard(applyDto.getProfile_dict().getId_card()); customerZcy.setIdCardFrontPath(applyDto.getProfile_dict().getId_card_front()); customerZcy.setIdCardBackPath(applyDto.getProfile_dict().getId_card_back()); customerZcy.setNation(applyDto.getProfile_dict().getNation()); customerZcy.setSignOrganization(applyDto.getProfile_dict().getIssued_by()); String valid_date = applyDto.getProfile_dict().getValid_date(); if (StringUtils.isNotBlank(valid_date)) { String[] valid_dates = valid_date.split("-"); customerZcy.setIdValidDateBegin(valid_dates[0]); String endTime = valid_dates[1]; customerZcy.setIdValidDateEnd(endTime); if ("⻓期".equals(endTime)) { customerZcy.setIdLongTerm("1"); } } customerZcy.setCityName(applyDto.getProfile_dict().getCity()); customerZcy.setAddress(applyDto.getProfile_dict().getAddress()); //sesame_point int sesame = applyDto.getProfile_dict().getSesame_point(); if (sesame == 2) { sesame = 1; }else if (sesame == 3) { sesame = 2; }else if (sesame == 4) { sesame = 3; }else { sesame = random.nextInt(3) + 1; } customerZcy.setSesame(sesame); String area = applyDto.getProfile_dict().getCity(); if (StringUtils.isNotBlank(area)) { String[] areas = area.split("-"); customerZcy.setLiveProvince(areas[0]); customerZcy.setCityName(areas[1]); customerZcy.setLiveArea(areas[2]); } customerZcy.setHouseStatus(applyDto.getProfile_dict().isHas_house() ? 1 : 0); customerZcy.setCarStatus(applyDto.getProfile_dict().isHas_car() ? 1 : 0); customerZcy.setInsurancePolicy(applyDto.getProfile_dict().isInsurance() ? 1 : 0); customerZcy.setProvidentFund(applyDto.getProfile_dict().isHas_fund() ? 1 : 0); customerZcy.setSocialSecurity(applyDto.getProfile_dict().isHas_social() ? 1 : 0); // 学历 String education = applyDto.getProfile_dict().getEducation(); if ("2".equals(education)) { education = "1"; }else if ("3".equals(education)) { education = "2"; }else if ("4".equals(education)) { education = "3"; }else { education = "4"; } // 1. 高中及以下 2. 专科 3. 本科 4. 研究生及以上 customerZcy.setEducation("0"+education); customerZcy.setCompanyName(applyDto.getProfile_dict().getOrganize_name()); //婚姻状况 String maritalStatus = applyDto.getProfile_dict().getMarital_status().toString(); if ("2".equals(maritalStatus)) { maritalStatus = "3"; }else if ("3".equals(maritalStatus) || "4".equals(maritalStatus) || "5".equals(maritalStatus) || "7".equals(maritalStatus)) { maritalStatus = "2"; }else if ("6".equals(maritalStatus)) { maritalStatus = "4"; }else { int num = random.nextInt(4) + 1; maritalStatus = String.valueOf(num); } customerZcy.setMaritalStatus(maritalStatus); String gender = applyDto.getProfile_dict().getGender(); customerZcy.setAge("male".equals(gender) ? 1 : 2); customerZcy.setBirthday(applyDto.getProfile_dict().getBirthday()); Integer monthlyIncome = applyDto.getProfile_dict().getMonthly_income(); int mi = Objects.isNull(monthlyIncome) ? 0 : monthlyIncome.intValue(); if (mi < 10000) { //'10000以下' mi = 3; }else if (mi < 30000){ //'10000-30000' mi = 4; }else { //'30000以上' mi = 13; } customerZcy.setMonthlyIncome(mi); //借款用途 customerZcy.setUseOfLoan(applyDto.getProfile_dict().getLoan_usage()); /** * (我来贷)所属行业 --> 融呗( (A:农、林、牧、渔业,B:采矿业,C:制造业,D:电力、热力、燃气及水生产和供应业,E:建筑业,F:批发和零售业,G:交通运输、仓储和邮储业,H:住宿和餐饮业,I:信息传输、软件和信息技术服务,J:金融业,K:房地产业,L:租赁和商务服务业,M:科学研究和技术服务业,N:水利、环境和公共设施管理业,O:居民服务、修理和其他服务业,P:教育,Q:卫生和社会工作,R:文化、体育和娱乐业,S:公共管理、社会保障和社会组织,T:国际组织,9:未知)) * 1. 建筑业 -->(E) * 2. 电力,热力,燃气及水生产和供应业 -->(D) * 3. 交通运输、仓储和邮政业 -->(G) * 4. 教育 -->(P) * 5. 房地产业 -->(K) * 6. 住宿和餐饮业 -->(H) * 7. 批发和零售业 -->(F) * 8. 租赁和商务服务业 -->(L) * 9. 信息传输、软件和信息技术服务业 -->(I) * 10. 金融业 -->(J) * 11. 文化、体育和娱乐业 -->(R) * 12. 制造业 -->(C) * 13. 水利、环境和公共设施管理业 -->(N) * 14. 采矿业 -->(B) * 15. 农、林、牧、渔业 -->(A) * 16. 居民服务、修理和其他服务业 -->(O) * 17. 卫生和社会工作 -->(Q) * 18. 科学研究和技术服务业 -->(M) * 19. 公共管理、社会保障和社会组织 -->(S) */ String companyTrade = applyDto.getProfile_dict().getIndustry(); if ("1".equals(companyTrade)) { //建筑业 companyTrade = "E"; }else if ("2".equals(companyTrade)) { //电力,热力,燃气及水生产和供应业 companyTrade = "D"; }else if ("3".equals(companyTrade)) { //交通运输、仓储和邮政业 companyTrade = "G"; }else if ("4".equals(companyTrade)) { //教育 companyTrade = "P"; }else if ("5".equals(companyTrade)) { //房地产业 companyTrade = "K"; }else if ("6".equals(companyTrade)) { //住宿和餐饮业 companyTrade = "H"; }else if ("7".equals(companyTrade)) { //批发和零售业 companyTrade = "F"; }else if ("8".equals(companyTrade)) { //租赁和商务服务业 companyTrade = "L"; }else if ("9".equals(companyTrade)) { //信息传输、软件和信息技术服务业 companyTrade = "I"; }else if ("10".equals(companyTrade)) { //金融业 companyTrade = "J"; }else if ("11".equals(companyTrade)) { //文化、体育和娱乐业 companyTrade = "R"; }else if ("12".equals(companyTrade)) { //制造业 companyTrade = "C"; }else if ("13".equals(companyTrade)) { //水利、环境和公共设施管理业 companyTrade = "N"; }else if ("14".equals(companyTrade)) { //采矿业 companyTrade = "B"; }else if ("15".equals(companyTrade)) { //农、林、牧、渔业 companyTrade = "A"; }else if ("16".equals(companyTrade)) { //居民服务、修理和其他服务业 companyTrade = "O"; }else if ("17".equals(companyTrade)) { //卫生和社会工作 companyTrade = "Q"; }else if ("18".equals(companyTrade)) { //科学研究和技术服务业 companyTrade = "M"; }else if ("19".equals(companyTrade)) { //公共管理、社会保障和社会组织 companyTrade = "S"; } customerZcy.setCompanyTrade(companyTrade); /** * 职业类型 * 1. 上班 * 2. 兼职 * 3. 企业主 * 4. 无业 * 5. 个体户 * 转融呗 * 1. 自由职业 * 2. 上班族 * 3. 企业主 * 4. 公务员/事业单位/国企 */ String jobType = applyDto.getProfile_dict().getJob_type(); int professionInfo = 1; if ("1".equals(jobType)) { professionInfo = 2; }else if ("3".equals(jobType)) { professionInfo = 3; }else { professionInfo = random.nextInt(4) + 1; } customerZcy.setProfessionInfo(professionInfo); String companyCity = applyDto.getProfile_dict().getCompany_address(); if (StringUtils.isNotEmpty(companyCity)) { String[] companyAddress = companyCity.split("-"); customerZcy.setCompanyProvince(companyAddress[0]); customerZcy.setCompanyCity(companyAddress[1]); customerZcy.setCompanyArea(companyAddress[2]); } customerZcy.setCompanyAddress(applyDto.getProfile_dict().getCompany_address_detail()); //活体对比数据 if (!Objects.isNull(applyDto.getLive_info().getLive_data())) { // 活体分类 customerZcy.setVerifySimilarity(applyDto.getLive_info().getLive_data().getFace_score()); } customerZcy.setVerifySimilarityName(applyDto.getLive_info().getService_provider()); customerZcy.setFacePhotoPath(applyDto.getLive_info().getBest_face_image()); //设备信息 customerZcy.setOs(applyDto.getDevice_info().getOs()); customerZcy.setClientIp(applyDto.getDevice_info().getIp()); String gps = applyDto.getDevice_info().getGps(); if (StringUtils.isNotEmpty(gps)) { String[] gpsArray = gps.split(","); if (gpsArray.length == 2) { customerZcy.setLng(gpsArray[0]); customerZcy.setLat(gpsArray[1]); } } // 标记为我来数科的数据 customerZcy.setMark(2); customerZcyService.save(customerZcy); } Customer cust = new Customer(); BeanUtils.copyProperties(customerZcy, cust); return cust; } private static @NotNull String getRelationShip(ContactListDto dto) { int relation = dto.getRelation(); if (relation == 1) { relation = 2; }else if (relation == 2) { relation = 1; }else if (relation >=5){ Random random = new Random(); int[] values = {2, 3, 4}; relation = values[random.nextInt(values.length)]; } return "0"+ relation; } /** * 从我来贷请求查询接受订单状态接口 * @param body 请求体 * @return RbResponse */ public RbResponse checkOrderStatusByWld(RongBeBasicDto body) { RbResponse resp = new RbResponse(); String logNumber = IdUtil.randomUUID(); try { //解密biz_data JSONObject fullData = new JSONObject(); fullData.putOpt("partner_id", body.getPartner_id()); fullData.putOpt("timestamp", body.getTimestamp()); fullData.putOpt("biz_data", body.getBiz_data()); String decryptStr = decrypt(fullData, body.getSign(), wldPublicKey); if (StringUtils.isNotEmpty(decryptStr)) { // 用融呗的配置信息重新生成签名 fullData.putOpt("partner_id", RbPartnerId); fullData.putOpt("timestamp", System.currentTimeMillis()); fullData.putOpt("sign", getSign(fullData, rbPublicKey)); try { String result = HttpClientUtil.getInstance().postJsonData(wldUrl + "order_status", String.valueOf(fullData)); resp = JSON.parseObject(result, RbResponse.class); return resp; } catch (Exception ex) { log.error("日志编号:{}, 【我来贷】查询接受订单状态接口请求失败,传参:{} ex:{}",logNumber, fullData, ex.getMessage()); } try { resp.setCode("0"); } catch (Exception ex) { log.error("日志编号:{},【我来贷】查询接受订单状态接口请求原始返回参数转换失败,jsonData:{} ex:{}", logNumber, fullData, ex.getMessage()); } } else { resp.setCode("500"); } return resp; } catch (Exception e) { resp.setCode("500"); resp.setMsg(e.getMessage()); log.error("日志编号:{} 【我来贷】查询接受订单状态接口请求失败:{} 错误原因:{}", logNumber, body, e.getMessage()); return resp; } } /** * 从我来贷请求查询接受订单状态接口 */ public void OrderStatusByWld(String chnOrderId, String partnerFlowId) { String logNumber = IdUtil.randomUUID(); try { //解密biz_data JSONObject fullData = new JSONObject(); JSONObject bizData = new JSONObject(); bizData.putOpt("chn_order_id",chnOrderId); bizData.putOpt("partner_flow_id", partnerFlowId); bizData.putOpt("status", 101); bizData.putOpt("update_time", System.currentTimeMillis() / 1000); fullData.putOpt("biz_data", encrypt(String.valueOf(bizData))); fullData.putOpt("partner_id", RbPartnerId); fullData.putOpt("timestamp", System.currentTimeMillis()); fullData.putOpt("sign", getSign(fullData, rbPublicKey)); String result = null; try { result = HttpClientUtil.getInstance().postJsonData(wldUrl + "order_status", String.valueOf(fullData)); log.info("日志编号:{} 【我来贷】查询接受订单状态接口请求失败,传参:{},返回结果:{}", logNumber, fullData, result); } catch (Exception ex) { log.error("日志编号:{} 【我来贷】查询接受订单状态接口请求,传参:{} ex:{}",logNumber, fullData, ex.getMessage()); } try { if (result != null) { log.info("日志编号:{} 【我来贷】查询接受订单状态接口数据处理,传参:{},返回结果:{}", logNumber, fullData, result); } } catch (Exception ex) { log.error("日志编号:{} 【我来贷】查询接受订单状态接口请求原始返回参数转换失败,jsonData:{} ex:{}", logNumber, fullData, ex.getMessage()); } } catch (Exception e) { log.error("日志编号:{} 【我来贷】查询接受订单状态接口请求失败:{},{} 错误原因:{}", logNumber, chnOrderId, partnerFlowId, e.getMessage()); } } /** * 从我来贷请求接受授信结果接口 */ public void autoPushCreditResult(String chnOrderId, String partnerFlowId) { String logNumber = IdUtil.randomUUID(); try { //解密biz_data JSONObject fullData = new JSONObject(); JSONObject bizData = new JSONObject(); bizData.putOpt("chn_order_id", chnOrderId); bizData.putOpt("partner_flow_id", partnerFlowId); long currentTimestamp = System.currentTimeMillis(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTimestamp); calendar.add(Calendar.YEAR, 1); // 在当前时间上加一年 // 获取一年后的时间戳(秒级时间戳) long nextYearTimestamp = calendar.getTimeInMillis() / 1000; bizData.putOpt("expired_ts", nextYearTimestamp); bizData.putOpt("max_amount", 5000000); bizData.putOpt("min_amount", 80000); bizData.putOpt("range_amount", 10000); Random random = new Random(); int[] values = {3, 6, 9, 12}; int[] loanTerms = new int[1]; int val = values[random.nextInt(values.length)]; loanTerms[0] = val; bizData.putOpt("loan_terms", loanTerms); bizData.putOpt("withdraw_type", 1); log.info("日志编号:{} 【我来贷】接受授信结果接口请求结果 bizData:{}", logNumber, bizData); fullData.putOpt("biz_data", encrypt(String.valueOf(bizData))); fullData.putOpt("partner_id", RbPartnerId); fullData.putOpt("timestamp", System.currentTimeMillis()); // 用融呗的配置信息重新生成签名 fullData.putOpt("sign", getSign(fullData, rbPublicKey)); String result = null; try { result = HttpClientUtil.getInstance().postJsonData(wldUrl + "credit_result", String.valueOf(fullData)); log.info("日志编号:{} 【我来贷】接受授信结果接口请求结果:{}", logNumber, result); } catch (Exception ex) { log.error("日志编号:{} 【我来贷】接受授信结果接口请求失败,传参:{} ex:{}", logNumber, fullData, ex.getMessage()); } try { if ( result != null) { log.info("日志编号:{} 【我来贷】接受授信结果接口数据处理:{}", logNumber, result); } } catch (Exception ex) { log.error("日志编号:{} 【我来贷】接受授信结果接口请求原始返回参数转换失败,jsonData:{} ex:{}", logNumber, fullData, ex.getMessage()); } } catch (Exception e) { log.error("日志编号:{} 【我来贷】接受授信结果接口请求失败,参数:{}-{},错误原因:{}", logNumber, chnOrderId, partnerFlowId, e.getMessage()); } } /** * 从我来贷请求接受授信结果接口 * @return RbResponse */ public RbResponse creditResultByWld(RongBeBasicDto body) { RbResponse resp = new RbResponse(); String logNumber = IdUtil.randomUUID(); try { //解密biz_data JSONObject fullData = new JSONObject(); fullData.putOpt("partner_id", body.getPartner_id()); fullData.putOpt("timestamp", body.getTimestamp()); fullData.putOpt("biz_data", body.getBiz_data()); String decryptStr = decrypt(fullData, body.getSign(), wldPublicKey); if (StringUtils.isNotEmpty(decryptStr)) { fullData.putOpt("partner_id", RbPartnerId); fullData.putOpt("timestamp", System.currentTimeMillis()); // 用融呗的配置信息重新生成签名 fullData.putOpt("sign", getSign(fullData, rbPublicKey)); try { String result = HttpClientUtil.getInstance().postJsonData(wldUrl + "credit_result", String.valueOf(fullData)); log.info("日志编号:{} 【我来贷】接受授信结果接口请求返回结果:{}", logNumber, result); resp = JSON.parseObject(result, RbResponse.class); return resp; } catch (Exception ex) { log.error("日志编号:{}, 【我来贷】接受授信结果接口请求,传参:{} ex:{}", logNumber, fullData, ex.getMessage()); } try { resp.setCode("0"); } catch (Exception ex) { log.error("日志编号:{},【我来贷】接受授信结果接口请求原始返回参数转换失败,jsonData:{} ex:{}", logNumber, fullData, ex.getMessage()); } } else { resp.setCode("5000"); } return resp; } catch (Exception e) { resp.setCode("5000"); resp.setMsg(e.getMessage()); log.error("日志编号:{} 【我来贷】接受授信结果接口请求失败:{} 错误原因:{}", logNumber, resp, e.getMessage()); return resp; } } /** * 从我来贷请求接受还款计划接口 * @param body 请求体 * @return RbResponse */ public RbResponse repayInfoByWld(RongBeBasicDto body) { RbResponse resp = new RbResponse(); String logNumber = IdUtil.randomUUID(); try { //解密biz_data JSONObject fullData = new JSONObject(); fullData.putOpt("partner_id", body.getPartner_id()); fullData.putOpt("timestamp", body.getTimestamp()); fullData.putOpt("biz_data", body.getBiz_data()); String decryptStr = decrypt(fullData, body.getSign(), wldPublicKey); if (StringUtils.isNotEmpty(decryptStr)) { // 用融呗的配置信息重新生成签名 fullData.putOpt("partner_id", RbPartnerId); fullData.putOpt("timestamp", System.currentTimeMillis()); fullData.putOpt("sign", getSign(fullData, rbPublicKey)); try { String result = HttpClientUtil.getInstance().postJsonData(wldUrl + "repay_info", String.valueOf(fullData)); resp = JSON.parseObject(result, RbResponse.class); return resp; } catch (Exception ex) { log.error("日志编号:, 【我来贷】接受还款计划接口请求失败,传参:{} ex:{}", logNumber, fullData, ex); } try { resp.setCode("0"); } catch (Exception ex) { log.error("日志编号:{} 【我来贷】接受还款计划接口请求原始返回参数转换失败,jsonData:{} ex:{}", logNumber, fullData, ex.getMessage()); } } else { resp.setCode("500"); } return resp; } catch (Exception e) { resp.setCode("500"); resp.setMsg(e.getMessage()); log.error("日志编号:{} 【我来贷】查询订单状态接口请求失败:{} 错误原因:{}", logNumber, body, e.getMessage()); return resp; } } /** * 加密 * @param oriData 要加密的内容串 * @return String */ public String encrypt(String oriData) { AES aes = new AES("ECB", "PKCS5Padding", encryptKey.getBytes()); String encryptString = aes.encryptBase64(oriData); log.info("加密后的数据:{}", encryptString); return encryptString; } /** * 生成签名(融呗私钥加密) * @param fullData 用于签名的对象 * @param publicKey 公钥 * @return String */ public String getSign(JSONObject fullData, String publicKey) { //排序 TreeMap treeMap = JSONUtil.toBean(fullData, TreeMap.class); String oriSignData = MapUtil.sortJoin(treeMap, "&", "=", true); RsaSupport rsaSupport = new RsaSupport("RSA", "SHA256WithRSA","RSA/ECB/PKCS1Padding", "utf-8", publicKey, privateKey); return rsaSupport.signByPrivateKey(oriSignData); } /** * 解密(公钥解密) * @param fullData 要解密的内容 * @param publicKey 公钥 * @return String */ private String decrypt(JSONObject fullData, String sign, String publicKey) { log.info("publicKey:{}", publicKey); RsaSupport rsaSupport = new RsaSupport("RSA", "SHA256WithRSA", "RSA/ECB/PKCS1Padding", "utf-8", publicKey, privateKey); AES aes = new AES("ECB", "PKCS5Padding", encryptKey.getBytes()); log.info("fullData:{}", fullData); //排序 TreeMap treeMap = JSONUtil.toBean(fullData, TreeMap.class); String oriSignData = MapUtil.sortJoin(treeMap, "&", "=", true); log.info("oriSignData:{}", oriSignData); log.info("sign:{}", sign); boolean flag = rsaSupport.verifyByPublicKey(oriSignData, sign); log.info("验签结果:{}", flag); if (flag) { String decryptStr = aes.decryptStr(fullData.getStr("biz_data")); log.info("解密出来的数据:{}", decryptStr); return decryptStr; } else { return null; } } /** * 提供我来贷进件发送短信 * @param phone */ public void smsNotify(String phone) { String content = "您申请的信用额已通过审核,请1小时内查看【" + smsNotifyUrl + "】 过期作废!拒收请回复R"; ShanDongMessageSendUtil.sendSMSContent(phone, content); } }