Air
2024-11-04 a1f06d31b7b4cac569c34bdfbb68de77f2858ffe
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
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;
        }
 
    }
 
}