Air
2024-11-04 2016903d06e308f44b9463fcd4029850ababf152
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package com.nova.sankuai.infra.utils;
 
import cfca.sadk.extend.session.util.TextUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nova.sankuai.domain.api.zzxf.ZzxfDataImportVo;
import com.nova.sankuai.domain.api.zzxf.ZzxfResponse;
import com.nova.sankuai.domain.api.zzxf.ZzxfTokenResponse;
import com.nova.sankuai.domain.entity.Customer;
import com.nova.sankuai.domain.enums.customerinfo.SesameStatusEnum;
import com.nova.sankuai.security.HttpClientUtil;
import com.nova.sankuai.service.IChannelInfoService;
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;
 
import javax.annotation.Resource;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @Description 中赞信服工具类
 * @Author CWR
 * @Date 2022/5/20 12:06
 */
@Component
public class ZzxfUtil {
 
    /**
     * host
     */
    @Value("${zzxf.host}")
    private String host;
 
    /**
     * 渠道
     */
    @Value("${zzxf.channel}")
    private String channel;
 
    /**
     * 密钥
     */
    @Value("${zzxf.secret}")
    private String secret;
 
    /**
     * AES密钥
     */
    @Value("${zzxf.aes-secret}")
    private String aesSecret;
 
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
 
    private static final Logger logger = LoggerFactory.getLogger("capitalLogger");
 
    @Resource
    IChannelInfoService channelInfoService;
 
    /**
     * 请求token
     *
     * @return
     * @throws NoSuchAlgorithmException
     */
    @SuppressWarnings("checked")
    public ZzxfTokenResponse getToken() {
        try {
            // 生成随机字符串
            String random = AesSecretUtils.getRandomString(16);
            // 获取时间戳
            String timestamp = String.valueOf(AesSecretUtils.getTimeStamp());
            String data = this.channel + ";" + this.secret + ";" + random + ";" + timestamp;
            logger.info("中赞获取平台token接口参数->:签名前字符串{}", data);
            // 使用SHA-1对data进行签名
            String sign = AesSecretUtils.sha1(data);
            Map<String, Object> param = new HashMap<>(16);
            param.put("channel", this.channel);
            param.put("random", random);
            param.put("times", timestamp);
            param.put("sign", sign);
 
            logger.info("中赞获取平台token接口参数->:{}", param);
            String responseString = HttpClientUtil.getInstance().postJsonData(host + "big/data2022/gettoken", OBJECT_MAPPER.writeValueAsString(param));
            logger.info("中赞获取平台token返回->:{}", responseString);
            if (!TextUtils.isEmpty(responseString)) {
//                ZzxfResponse<ZzxfTokenResponse> response = OBJECT_MAPPER.readValue(responseString, ZzxfResponse.class);
                ZzxfResponse<ZzxfTokenResponse> response = JSON.parseObject(responseString, new TypeReference<ZzxfResponse<ZzxfTokenResponse>>() {
                });
                // 请求成功
                if (0 == response.getResponseCode()) {
                    return response.getData();
                }
            }
        } catch (Exception e) {
            logger.error("中赞获取平台token接口出错");
            e.printStackTrace();
            return null;
        }
        return null;
    }
 
    /**
     * 导入数据接口
     *
     * @param vo 导入数据vo
     * @return
     */
    public ZzxfResponse dataImport(Customer vo) {
        ZzxfDataImportVo zzxfDataImportVo = new ZzxfDataImportVo();
        zzxfDataImportVo.setAge(vo.getAge());
        if (vo.getAge() == null && !StringUtils.isEmpty(vo.getBirthday())) {
            calcuAge(zzxfDataImportVo, vo.getBirthday());
        }
        zzxfDataImportVo.setBaitiao(0);
        zzxfDataImportVo.setChildSource(null);
        if (vo.getCityName() != null) {
            String cityName = vo.getCityName();
            if (cityName.endsWith("市")) {
                cityName = cityName.substring(0, cityName.length() - 1);
            }
            zzxfDataImportVo.setCity(cityName);
        }
        zzxfDataImportVo.setExt1(null);
        zzxfDataImportVo.setHuabei(0);
        zzxfDataImportVo.setIdcard(vo.getIdCard());
        zzxfDataImportVo.setName(vo.getName());
        zzxfDataImportVo.setMobile(vo.getPhone());
        Integer integer = vo.parseLoadAmount();
        zzxfDataImportVo.setMoneyDemand(integer);
        if (vo.getCarStatus() != null) {
            zzxfDataImportVo.setIsCar(vo.getCarStatus() == 3 ? "Y" : "N");
        } else {
            zzxfDataImportVo.setIsCar("N");
        }
        if (vo.getHouseStatus() != null) {
            zzxfDataImportVo.setIsHouse(vo.getHouseStatus() == 3 ? "Y" : "N");
        } else {
            zzxfDataImportVo.setIsHouse("N");
        }
        if (vo.getInsurancePolicy() != null) {
            zzxfDataImportVo.setIsInsurance(vo.getInsurancePolicy() == 0 ? "N" : "Y");
        } else {
            zzxfDataImportVo.setIsInsurance("N");
        }
        if (vo.getProvidentFund() != null) {
            zzxfDataImportVo.setIsFund(vo.getProvidentFund() == 0 ? "N" : "Y");
        } else {
            zzxfDataImportVo.setIsFund("N");
        }
        if (vo.getSocialSecurity() != null) {
            zzxfDataImportVo.setIsSocial(vo.getSocialSecurity() == 0 ? "N" : "Y");
        } else {
            zzxfDataImportVo.setIsSocial("N");
        }
        if (vo.getSesame() != null) {
            if (SesameStatusEnum.Sesame_1.getCode().equals(vo.getSesame())) {
                zzxfDataImportVo.setZhimascore(vo.getSesame());
            } else if (SesameStatusEnum.Sesame_2.getCode().equals(vo.getSesame())) {
                zzxfDataImportVo.setZhimascore(600);
            } else if (SesameStatusEnum.Sesame_3.getCode().equals(vo.getSesame())) {
                zzxfDataImportVo.setZhimascore(650);
            } else if (SesameStatusEnum.Sesame_4.getCode().equals(vo.getSesame())) {
                zzxfDataImportVo.setZhimascore(700);
            } else {
                zzxfDataImportVo.setZhimascore(701);
            }
        } else {
            zzxfDataImportVo.setZhimascore(0);
        }
        try {
            // 首先获取token
            ZzxfTokenResponse token = getToken();
            if (token == null || token.getToken() == null) {
                throw new Exception("token为空");
            }
            Map<String, Object> param = new HashMap<>(16);
            logger.info("中赞导入数据接口原始参数->:{}", zzxfDataImportVo.toString());
            param.put("channel", this.channel);
            param.put("token", token.getToken());
            // 请求数据加密
            String data = AesSecretUtils.encrypt(OBJECT_MAPPER.writeValueAsString(zzxfDataImportVo), this.aesSecret);
            param.put("data", data);
            logger.info("中赞导入数据接口参数->:{}", param);
            String responseJson = HttpClientUtil.getInstance().postJsonData(host + "big/data2022/putdata", OBJECT_MAPPER.writeValueAsString(param));
            logger.info("中赞导入数据接口返回->:{}", responseJson);
            if (!TextUtils.isEmpty(responseJson)) {
                return OBJECT_MAPPER.readValue(responseJson, ZzxfResponse.class);
            }
        } catch (Exception e) {
            logger.error("中赞导入数据接口出错");
            e.printStackTrace();
            return null;
        }
        return null;
    }
 
    public void calcuAge(ZzxfDataImportVo zzxfDataImportVo, String birthday) {
        Long yearmoi = (long) 365 * 24 * 60 * 60 * 1000;
        Date today = new Date();
        SimpleDateFormat bDate = new SimpleDateFormat("yyyyMMdd");
        try {
            long birthdayMi = bDate.parse(birthday).getTime();
            long todayMi = today.getTime();
            long liveMi = todayMi - birthdayMi;
            int age = (int) (liveMi / yearmoi);
            zzxfDataImportVo.setAge(age);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
 
}