package com.nova.sankuai.domain.api.rongduoduo;
|
|
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpResponse;
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.nova.sankuai.domain.entity.Customer;
|
import com.nova.sankuai.domain.enums.customerinfo.*;
|
import com.nova.sankuai.infra.constants.Constants;
|
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModelProperty;
|
import org.apache.commons.lang.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Component;
|
|
|
/**
|
* @author ephemeral
|
* @date 2021/12/30 9:48
|
*/
|
@Component
|
@ApiModel(value = "融多多接口对接工具类")
|
public class RongDuoDuoUtil {
|
|
@ApiModelProperty("撞库url")
|
@Value("${rongduoduo.conf.api-url1}")
|
public String url1;
|
|
@ApiModelProperty("用户信息添加url")
|
@Value("${rongduoduo.conf.api-url2}")
|
public String url2;
|
|
@ApiModelProperty("渠道号")
|
@Value("${rongduoduo.conf.channel-number}")
|
public String channelNumber;
|
|
private static final Logger log = LoggerFactory.getLogger("capitalLogger");
|
|
|
/**
|
* 撞库-API预检MD5
|
*
|
* @param customer 用户信息
|
* @return
|
*/
|
public String apiMd5Check(Customer customer) {
|
JSONObject params = new JSONObject();
|
params.put("qdName", channelNumber);
|
params.put("phone", customer.getPhone());
|
params.put("city", customer.getCityName());
|
HttpResponse httpResponse = null;
|
try {
|
log.info("融多多对接:API预检MD5参数->:{}", params.toJSONString());
|
httpResponse = HttpRequest.post(url1)
|
.contentType("multipart/form-data")
|
.timeout(Constants.TIME_OUT)
|
.form(params).execute();
|
log.info("融多多对接:API预检MD5返回参数->:{}", httpResponse.body());
|
} catch (Exception e) {
|
log.error("融多多对接:API预检MD5接口请求错误", e);
|
e.printStackTrace();
|
}
|
return httpResponse.body();
|
}
|
|
public static RongDuoDuoResponse getResponse(String result) {
|
if (StringUtils.isNotEmpty(result)) {
|
try {
|
RongDuoDuoResponse response = JSON.parseObject(result, RongDuoDuoResponse.class);
|
if (response != null) {
|
return response;
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
log.error("融多多对接:转换响应返回数据失败", e);
|
}
|
}
|
return null;
|
}
|
|
/**
|
* 将Customer对象转换为融多多接口对象
|
*
|
* @param customer
|
* @return
|
*/
|
public SanKuaiCustomer parseParam(Customer customer) {
|
if (customer == null) {
|
return null;
|
}
|
SanKuaiCustomer sanKuaiCustomer = new SanKuaiCustomer();
|
sanKuaiCustomer.setQdName(channelNumber);
|
sanKuaiCustomer.setName(customer.getName());
|
sanKuaiCustomer.setPhone(customer.getPhone());
|
if (customer.getLoanAmount() == null) {
|
Integer price = LargeLoanAmountEnum.parseAmountToYuan(customer.getLargeLoanAmount());
|
sanKuaiCustomer.setPrice(price);
|
} else {
|
sanKuaiCustomer.setPrice(customer.getLoanAmount().intValue());
|
}
|
if (sanKuaiCustomer.getPrice() == null) {
|
sanKuaiCustomer.setPrice(30000);
|
}
|
if (customer.getHouseStatus() != null
|
&& HouseStatusEnum.House_1.getCode().equals(customer.getHouseStatus())) {
|
sanKuaiCustomer.setHouse(SanKuaiCustomer.NOT_OWNED);
|
} else {
|
sanKuaiCustomer.setHouse(SanKuaiCustomer.OWNED);
|
}
|
if (customer.getCarStatus() != null
|
&& CarStatusEnum.Car_1.getCode().equals(customer.getCarStatus())) {
|
sanKuaiCustomer.setCar(SanKuaiCustomer.NOT_OWNED);
|
} else {
|
sanKuaiCustomer.setCar(SanKuaiCustomer.OWNED);
|
}
|
if (customer.getInsurancePolicy() != null
|
&& InsuranceStatusEnum.BusinessInsurance_1.getCode().equals(customer.getInsurancePolicy())) {
|
sanKuaiCustomer.setInsurance(SanKuaiCustomer.NOT_OWNED);
|
} else {
|
sanKuaiCustomer.setInsurance(SanKuaiCustomer.OWNED);
|
}
|
if (customer.getProvidentFund() != null
|
&& ProvidentFundStatusEnum.ProvidentFund_1.getCode().equals(customer.getProvidentFund())) {
|
sanKuaiCustomer.setFund(SanKuaiCustomer.NOT_OWNED);
|
} else {
|
sanKuaiCustomer.setFund(SanKuaiCustomer.OWNED);
|
}
|
if (customer.getSocialSecurity() != null
|
&& SocialSecurityStatusEnum.SocialSecurity_1.getCode().equals(customer.getSocialSecurity())) {
|
sanKuaiCustomer.setSocital(SanKuaiCustomer.NOT_OWNED);
|
} else {
|
sanKuaiCustomer.setSocital(SanKuaiCustomer.OWNED);
|
}
|
if (customer.getCreditCard() != null) {
|
sanKuaiCustomer.setXyk(customer.getCreditCard());
|
} else {
|
sanKuaiCustomer.setXyk(SanKuaiCustomer.NOT_OWNED);
|
}
|
if (customer.getMicroLoan() != null
|
&& MicroLoanEnum.MicroLoanEnum_1.getCode().equals(customer.getMicroLoan())) {
|
sanKuaiCustomer.setWld(SanKuaiCustomer.NOT_OWNED);
|
} else {
|
sanKuaiCustomer.setWld(SanKuaiCustomer.OWNED);
|
}
|
sanKuaiCustomer.setQyns(SanKuaiCustomer.NOT_OWNED);
|
if (customer.getPayrollAgency() != null) {
|
sanKuaiCustomer.setDf(customer.getPayrollAgency());
|
} else {
|
sanKuaiCustomer.setDf(SanKuaiCustomer.NOT_OWNED);
|
}
|
//营业执照目前没有,直接写死为无
|
sanKuaiCustomer.setBusiness_license(SanKuaiCustomer.NOT_OWNED);
|
sanKuaiCustomer.setCity(customer.getCityName());
|
sanKuaiCustomer.setSource(channelNumber);
|
if (customer.getAge() != null) {
|
sanKuaiCustomer.setAge(customer.getAge());
|
} else {
|
//没有年龄的话默认30
|
sanKuaiCustomer.setAge(30);
|
}
|
sanKuaiCustomer.setLoan_periods(customer.getLoanTerm());
|
return sanKuaiCustomer;
|
}
|
|
public static String encrypt(String json) throws Exception {
|
return SecurityCore.getInstance().encrypt(json);
|
}
|
|
|
}
|