zbb378@sohu.com
2024-11-04 b2bad51be3c8d3e78d7f81a19415faeac2d0297c
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
package com.nova.sankuai.domain.api.xinyongfei;
 
import com.alibaba.fastjson.JSON;
import com.nova.sankuai.security.HttpClientUtil;
import com.nova.sankuai.security.MD5Encryption;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
 
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
 
@ApiModel(value = "信用飞对接")
@Data
@Slf4j
@Component
public class XinYongFeiUtil {
 
    @Value("${xinyongfei.conf.collision_url}")
    @ApiModelProperty(value = "撞库接口URL地址")
    private String collisionUrl;
 
    @Value("${xinyongfei.conf.auto_url}")
    @ApiModelProperty(value = "联登接口URL地址")
    private String autoUrl;
 
    @Value("${xinyongfei.conf.secretKey}")
    @ApiModelProperty(value = "接口密钥")
    private String secretKey;
 
    @ApiModelProperty(value = "信用飞下载地址")
    private static final String DOWNLOAD_ADDRESS = "https://m-v3.xinyongfei.cn/activity/landingpage?type=XYF12&app_name=xyf01&utm_source=QD-CPS-XYF01-DDH01";
 
    //获取撞库sign
    public String getCollisionLibrarySign(String phone) {
        String md5 = MD5Encryption.getMD5(phone);
        String phoneString = "mobile" + "=" + md5;
        String signString = phoneString + secretKey;
        String sign = "";
        try {
            sign = DigestUtils.md5DigestAsHex(signString.getBytes());
        } catch (Exception e) {
            log.error("信用飞错误,撞库对接数据md5加秘签名失败:{}", e);
            return null;
        }
        return sign;
    }
 
    //获取联登sign
    public String getAutoSign(String phone, HttpServletRequest request) {
        String agent = request.getHeader("User-Agent");
        log.info("获取os:{}", agent);
        String phoneString = "mobile" + "=" + phone;
        String signString = phoneString + "&os=" + agent + secretKey;
        String sign = "";
        try {
            sign = DigestUtils.md5DigestAsHex(signString.getBytes());
        } catch (Exception e) {
            log.error("信用飞错误,联登对接数据md5加秘签名失败:{}", e);
            return null;
        }
        return sign;
    }
 
    //获取撞库对接数据
    public String getCollisionLibraryJson(String phoneString, String sign) {
        HashMap<String, String> map = new HashMap<>();
        map.put("mobile", phoneString);
        map.put("sign", sign);
        String result = "";
        try {
            result = JSON.toJSONString(map);
        } catch (Exception e) {
            log.error("信用飞错误,撞库对接数据转换json失败:{}", e);
            return null;
        }
        return result;
    }
 
    //获取联登对接数据
    public static String getAutoJson(String phone, String agent, String sign) {
        HashMap<String, String> map = new HashMap<>();
        map.put("mobile", phone);
        map.put("os", agent);
        map.put("sign", sign);
        String result = "";
        try {
            result = JSON.toJSONString(map);
        } catch (Exception e) {
            log.error("信用飞错误,联登对接数据转换json失败:{}", e);
            return null;
        }
        return result;
    }
 
    /**
     * 撞库
     *
     * @param phone
     * @return
     */
    public XinYongFeiResponse collisionLibraryRequest(String phone) {
        String collisionLibrarySign = getCollisionLibrarySign(phone);
        String collisionLibraryJson = getCollisionLibraryJson(MD5Encryption.getMD5(phone), collisionLibrarySign);
        String result = "";
        try {
            result = HttpClientUtil.getInstance().postJsonData(collisionUrl , collisionLibraryJson);
            log.info("信用飞原始数据:{}",result);
        } catch (IOException e) {
            log.error("信用飞错误,原始返回为:{}",result+"撞库连接获取信息失败:{}", e);
            e.printStackTrace();
            return null;
        }
        XinYongFeiResponse xinYongFeiResponse = null;
        try {
            xinYongFeiResponse = JSON.parseObject(result, XinYongFeiResponse.class);
        } catch (Exception e) {
            log.error("信用飞错误,撞库对接数据转换json失败:{}", e);
            return null;
        }
        return xinYongFeiResponse;
    }
 
    /**
     * 联登
     *
     * @param phone
     * @param request
     * @return
     */
    public XinYongFeiResponse autoRequest(String phone, HttpServletRequest request) {
        String autoSign = getAutoSign(phone, request);
        String agent = request.getHeader("User-Agent");
        String autoJson = getAutoJson(phone, agent, autoSign);
        String result = "";
        try {
            result = HttpClientUtil.getInstance().postJsonData(autoUrl , autoJson);
        } catch (IOException e) {
            log.error("信用飞错误,联登连接获取信息失败:{}", e);
            e.printStackTrace();
            return null;
        }
        XinYongFeiResponse xinYongFeiResponse = null;
        try {
            xinYongFeiResponse = JSON.parseObject(result, XinYongFeiResponse.class);
        } catch (Exception e) {
            log.error("信用飞错误,联登对接数据转换json失败:{}", e);
            return null;
        }
        return xinYongFeiResponse;
    }
 
    public String getDownloadAddress() {
        return DOWNLOAD_ADDRESS;
    }
 
}