zbb378@sohu.com
2024-11-04 b2bad51be3c8d3e78d7f81a19415faeac2d0297c
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
173
174
175
176
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;
 
/**
 * <p>
 * 锦绣数科公司接口对接
 * </p>
 *
 * @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;
    }
}