package com.nova.sankuai.infra.utils.zhxyp; import cn.hutool.core.util.IdUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import org.apache.commons.lang3.StringUtils; import com.nova.sankuai.security.HttpClientUtil; import lombok.RequiredArgsConstructor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.util.Objects; /** * Describe: 纵星优品接口 * Author: 纪新雷 * CreateTime: 2024-09-04 * */ @Component @RequiredArgsConstructor public class ZhxypUtil { private static final Logger log = LoggerFactory.getLogger("capitalLogger"); //撞库url @Value("${zhxyp.zkUrl}") private String zkUrl; /** * Describe: 撞库 * @param idcard : String 身份证 * @param phone : String 手机号 * @param name : String 姓名 * @return code = 0 不成功, code = 1 表示成功 * {code :0 ,data:[],msg:’’”} * {code :1,data:[url:’’,sn:’’],msg:””} * Author: 纪新雷 * CreateTime: 2024-09-04 * */ public String check(String idcard, String phone, String name) { String logNumber = IdUtil.randomUUID(); log.info("日志编号:{} idcard:{} phone:{} name:{} 撞库流程开始",logNumber, idcard, phone, name); // if(StringUtils.isBlank(idcard)) { // log.info("日志编号:" + logNumber + " 身份证入参为空"); // return null; // } // if(StringUtils.isBlank(phone)) { log.info("日志编号:" + logNumber + " 手机号入参为空"); return null; } // if(StringUtils.isBlank(name)) { log.info("日志编号:" + logNumber + " 姓名入参为空"); // throw new CommonException("姓名不能为空"); return null; } // // JSONObject body = new JSONObject(); body.put("idcard", StringUtils.defaultString(idcard)); body.put("phone", phone); body.put("name", name); String result = null; try { // 撞库 result = HttpClientUtil.getInstance().postJsonData(zkUrl, body.toJSONString()); log.info("日志编号:{} idcard:{} phone:{} name:{} , 撞库返回参数:{}",logNumber, idcard, phone, name, result); } catch (Exception ex) { log.error("日志编号:{} idcard:{} phone:{} name:{} , 撞库失败,传参:{} ex:{}",logNumber, idcard, phone, name, body, ex); return null; } try { // ChannelUnionCollisionResponse res = JSON.parseObject(result, ChannelUnionCollisionResponse.class); // JSONObject resultObj = (JSONObject)JSONObject.toJSON(res); // return resultObj.toJSONString(); String rtnValue = null; //result = "{\"code\":1,\"data\":{\"url\":\"https:\\/\\/www.zhxyp.com\\/index\\/index\\/down2\",\"sn\":\"27x20240908152837164051\"},\"msg\":\"\\u6570\\u636e\\u5141\\u8bb8\\u51c6\\u5165!\"}"; JSONObject res = JSON.parseObject(result); if (res.containsKey("code") && 1 == res.getInteger("code")) { log.info("日志编号:{} idcard:{} phone:{} name:{} , 撞库成功",logNumber, idcard, phone, name); JSONObject dataObj = res.getJSONObject("data"); if(null != dataObj && !Objects.isNull(dataObj) ) { if(dataObj.containsKey("url") && !StringUtils.isBlank(dataObj.getString("url")) ) { rtnValue = dataObj.getString("url"); } } return rtnValue; } else { log.info("日志编号:{} idcard:{} phone:{} name:{} , 撞库失败",logNumber, idcard, phone, name); return null; } } catch (Exception ex) { log.error("日志编号:{} idcard:{} phone:{} name:{} , 撞库原始返回参数转换失败,传参:{} ex:{}",logNumber, idcard, phone, name, body, ex); // throw new CommonException("撞库原始返回参数转换失败"); return null; } } }