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();
|
}
|
}
|
|
}
|