ab
2024-11-04 09d882262f530ded672f1c01fb65a1fefa00d52d
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
package com.nova.sankuai.domain.api.xiamenzhongheyinhua;
 
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import com.nova.sankuai.domain.entity.Customer;
import com.nova.sankuai.domain.enums.customerinfo.HousePaymentEnum;
import com.nova.sankuai.domain.enums.customerinfo.InsuranceStatusEnum;
import com.nova.sankuai.domain.enums.customerinfo.LargeLoanAmountEnum;
import com.nova.sankuai.domain.enums.customerinfo.MicroLoanEnum;
import com.nova.sankuai.infra.config.CommonException;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.http.MediaType;
 
import java.util.Random;
 
/**
 * 厦门众合银华对接工具类
 *
 * @author weikangdi
 * @create 2021/12/20
 */
@Slf4j
public class XiaMenZhongHeYinHuaUtil {
 
    @ApiModelProperty(value = "厦门众合银华API接口测试地址")
    public static final String SANDBOX_URL = "https://101.43.4.103/api/channel/clue/_unsafe";
 
    @ApiModelProperty(value = "厦门众合银华API接口正式地址")
    public static final String PROD_URL = "https://www.zhongheyinhua.com.cn/api/channel/clue/_unsafe";
 
    @ApiModelProperty(value = "厦门众合银华API加密传输接口正式地址")
    public static final String PROD_URL_ENC = "https://www.zhongheyinhua.com.cn/api/channel/clue";
 
    @ApiModelProperty(value = "厦门众合银华API接口撞库地址")
    public static final String PROD_URL_CHECK = "https://www.zhongheyinhua.com.cn/api/channel/clue/phone/_check";
 
    @ApiModelProperty(value = "厦门众合银华API接口渠道")
    public static final String CHANNEL = "SANKUAI";
 
 
    /**
     * 将Customer对象转换为民生接口对象
     *
     * @param customer
     * @return
     */
    public static JSONArray parseParam(Customer customer) {
        JSONObject param = new JSONObject();
        param.putOnce("city", formatCity(customer.getCity()));
        param.putOnce("poolNo", "SANKUAI");
        param.putOnce("name", customer.getName());
        param.putOnce("phone", customer.getPhone());
        // level-线索等级-没有
        // sex-性别-没有标准定义,先搁置
        if (customer.getHousePayment() != null) {
            if (HousePaymentEnum.HousePayment_2.getCode().equals(customer.getHousePayment())) {
                param.putOnce("house", 1);
            } else if (HousePaymentEnum.HousePayment_3.getCode().equals(customer.getHousePayment())) {
                param.putOnce("house", 2);
            } else {
                param.putOnce("house", 3);
            }
        }
        // car-车-无法区分按揭和全款,搁置
        // socialSecurity-发薪方式-没有
        param.putOnce("socialSecurity", 1);
        param.putOnce("accumulationFund", 1);
        if (InsuranceStatusEnum.BusinessInsurance_5.getCode().equals(customer.getInsurancePolicy())) {
            param.putOnce("lifeInsurance", "1"); // 有
        } else {
            param.putOnce("lifeInsurance", "2"); // 无
        }
        param.putOnce("age", customer.getAge());
        param.putOnce("company", customer.getCompanyName());
 
        if (customer.getLoanAmount() == null) {
            Integer quota = LargeLoanAmountEnum.parseAmountToYuan(customer.getLargeLoanAmount());
            param.putOnce("quota", quota);
        } else {
            param.putOnce("quota", customer.getLoanAmount());
        }
        if (customer.getMicroLoan() != null) {
            if (MicroLoanEnum.MicroLoanEnum_1.getCode().equals(customer.getMicroLoan())) {
                param.putOnce("weBank", "无");
            } else {
                param.putOnce("weBank", "有");
            }
        }
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(param);
        return jsonArray;
    }
 
    private static String formatCity(String city) {
        if (StringUtils.isNotBlank(city)) {
            return city.substring(0, 6);
        }
        return "";
    }
 
    /**
     * 随机生成16位字符串.
     */
    public static String getRandomStr() {
        return getRandomStr(16);
    }
 
    /**
     * 随机生成字符串.
     *
     * @param length 字符串长度
     */
    public static String getRandomStr(int length) {
        String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }
 
 
    public static XiaMenZhongHeYinHuaResponse phoneCheckExists(String phone) {
        HttpResponse resp = HttpRequest.post(PROD_URL_CHECK)
                .body(
                        new JSONObject() {{
                            putOnce("channelCode", CHANNEL);
                            putOnce("data", new JSONObject() {{
                                putOnce("phone", SignatureUtil.encrypt(phone, SignatureUtil.SECRET_KEY));
                            }});
                        }}.toString()
                )
                .contentType(MediaType.APPLICATION_JSON_VALUE)
                .execute();
        if (resp.isOk()) {
            log.info("厦门众合银华撞库接口: resp -> {}", resp.body());
            return JSON.parseObject(resp.body(), XiaMenZhongHeYinHuaResponse.class);
        }
        throw new CommonException("访问厦门众合银华撞库接口失败! " + resp);
    }
}