myjf007
2024-11-04 627b61d17da1dbf02c0363c659b728627dd42890
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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);
    }
 
 
}