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