package com.nova.sankuai.domain.api.jinxiushuke; import com.alibaba.fastjson.JSONObject; import com.nova.sankuai.domain.api.nanjingmingtuo.AesUtil; import com.nova.sankuai.domain.dto.CustomerCompareDto; import com.nova.sankuai.domain.entity.Customer; import com.nova.sankuai.domain.enums.customerinfo.HousePaymentEnum; import com.nova.sankuai.domain.enums.customerinfo.SesameStatusEnum; import io.swagger.annotations.ApiModel; import lombok.Data; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.DigestUtils; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.nio.charset.StandardCharsets; /** *
* 锦绣数科公司接口对接 *
* * @author: zcj 2022/2/15 */ @Data @ApiModel(value = "锦绣数科公司接口对接") public class JinXiuShuKeUtil { public static final String HIT_URL = "https://jiekou.miaodaimao.com/sem/check_mobile.html"; public static final String COMMIT_URL = "https://jiekou.miaodaimao.com/sem/loan_do.html"; public static final String SOURCE = "bq1ldxd"; public static final String KEY = "axW9zT4BD9siImpC"; public static final Integer SUCCESS = 100; private static final Logger log = LoggerFactory.getLogger("apiCompanyInfoLogger"); public static JSONObject parseHitParam(Customer customer) { JSONObject object = new JSONObject(); object.put("mobile", DigestUtils.md5DigestAsHex(customer.getPhone().getBytes())); if (StringUtils.isNotEmpty(customer.getCityName()) && customer.getCityName().endsWith("市")) { object.put("city", customer.getCityName().substring(0, customer.getCityName().indexOf("市"))); } else { object.put("city", customer.getCityName()); } object.put("source", SOURCE); return object; } public static JSONObject parseCommitParam(Customer customer) { CustomerCompareDto parse = CustomerCompareDto.parse(customer); JSONObject object = new JSONObject(); object.put("name", customer.getName()); object.put("mobile", customer.getPhone()); if (StringUtils.isNotEmpty(customer.getCityName()) && customer.getCityName().endsWith("市")) { object.put("city", customer.getCityName().substring(0, customer.getCityName().indexOf("市"))); } else { object.put("city", customer.getCityName()); } object.put("source", SOURCE); object.put("ip", customer.getIpAddres()); object.put("car", parse.isCarStatus() ? "有" : "无"); object.put("age", customer.getAge() == null ? 30 : customer.getAge()); object.put("job", StringUtils.isNotEmpty(customer.getCompanyName()) ? "有" : "无"); object.put("house", parse.isHouseStatus() ? "有" : "无"); object.put("baodan_is", parse.isInsurancePolicy() ? "有" : "无"); object.put("sex", customer.getSex()); float moneyFloat = parse.getQuota() / 10000f; int moneyInt = parse.getQuota() / 10000; if (moneyFloat - moneyInt > 0.45) { ++moneyInt; } object.put("money", moneyInt); object.put("shebao", parse.isSocialSecurity() ? "有" : "无"); object.put("gongjijin", parse.isProvidentFund() ? "有" : "无"); object.put("credit_card", parse.isCreditCard() ? "有" : "无"); object.put("time", System.currentTimeMillis() / 1000); object.put("weili", 0); object.put("zhima", getSesameCode(customer.getSesame())); object.put("loan_type", "信用贷"); String housePayMentValue = getHousePayMentValue(customer.getHousePayment()); if (housePayMentValue != null) { object.put("housestatus", housePayMentValue); } log.info("锦绣数科推送数据开始,原始数据发送:" + object); String dataParam = JSONObject.toJSONString(object); String data = null; try { data = AesUtil.encrypt(dataParam, KEY); data = org.apache.commons.codec.binary.Base64.encodeBase64String(data.getBytes(StandardCharsets.UTF_8)); log.info("锦绣数科推送数据开始,原始数据加密数据:" + data); } catch (Exception e) { log.info("锦绣数科推送数据开始,原始数据加密数据失败"); e.printStackTrace(); } JSONObject body = new JSONObject(); body.put("is_jm", 2); body.put("source", SOURCE); body.put("data", data); return body; } private static Integer getSesameCode(Integer sesame) { if (sesame != null && !sesame.equals(SesameStatusEnum.Sesame_1.getCode())) { if (sesame.equals(SesameStatusEnum.Sesame_2)) { return 2; } if (sesame.equals(SesameStatusEnum.Sesame_3)) { return 2; } if (sesame.equals(SesameStatusEnum.Sesame_4) || sesame.equals(SesameStatusEnum.Sesame_5)) { return 3; } } return 0; } private static String getHousePayMentValue(Integer housePayMent) { if (housePayMent != null && !HousePaymentEnum.HousePayment_1.equals(housePayMent)) { if (HousePaymentEnum.HousePayment_2.equals(housePayMent)) { return "按揭"; } if (HousePaymentEnum.HousePayment_3.equals(housePayMent)) { return "全款"; } } return null; } private static Integer getMicroLoanCode(Integer microLoan) { if (microLoan != null) { if (5000 <= microLoan && 10000 > microLoan) { return 1; } if (10000 <= microLoan && 20000 > microLoan) { return 2; } if (20000 <= microLoan && 30000 > microLoan) { return 3; } if (30000 <= microLoan && 40000 > microLoan) { return 4; } if (40000 <= microLoan && 50000 > microLoan) { return 5; } if (50000 <= microLoan) { return 6; } } return 0; } public static String getFailMessage(String response) { Field[] fields = JinXiuShuKeResponse.class.getFields(); if (StringUtils.isNotBlank(response)) { for (Field field : fields) { if (Modifier.isFinal(field.getModifiers())) { if (field.getName().contains(response)) { try { return (String) field.get(null); } catch (IllegalAccessException e) { e.printStackTrace(); } } } } } return response; } }