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
package com.nova.sankuai.domain.api.taojinhui;
 
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nova.sankuai.security.HttpClientUtil;
import com.nova.sankuai.security.MD5Encryption;
import lombok.extern.slf4j.Slf4j;
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 java.io.IOException;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @Author Lilinhong
 * @Date 2022/5/30 16:30
 */
@Component
@Slf4j
public class TjhUtil {
 
    private static final Logger logger = LoggerFactory.getLogger("capitalLogger");
 
    /**
     * 撞库地址
     */
    @Value("${taojinhui.collision_url}")
    private String collisionUrl;
 
    /**
     * 联合注册地址
     */
    @Value("${taojinhui.auto_url}")
    private String autoUrl;
 
    /**
     * 产品编码
     */
    @Value("${taojinhui.app_code}")
    private String appCode;
 
    /**
     * 渠道名称, 公钥
     */
    @Value("${taojinhui.channel}")
    private String channel;
 
    /**
     * 私钥
     */
    @Value("${taojinhui.channel_key}")
    private String channelKey;
 
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
 
 
    public TjhCollisionResponse checkUser(String mobile, String mobileType, String deviceBrand, String systemVersion, String systemModel) {
        String phoneMd5 = MD5Encryption.getMD5(mobile);
        String mobileTypeLower = null;
        if (StringUtils.isNotEmpty(mobileType)) {
            mobileTypeLower = mobileType.toLowerCase();
        }
        String timeStamp = String.valueOf(System.currentTimeMillis());
        String sign = MD5Encryption.getMD5(appCode + phoneMd5 + timeStamp + channelKey).toUpperCase();
        // 请求体
        Map<String, Object> body = new HashMap<>(16);
        body.put("appCode", appCode);
        body.put("mobile", phoneMd5);
        body.put("channel", channel);
        body.put("timeStamp", timeStamp);
        body.put("mobileType", mobileTypeLower);
        body.put("deviceBrand", deviceBrand);
        body.put("systemVersion", systemVersion);
        body.put("systemModel", systemModel);
        body.put("sign", sign);
        String response = "";
        logger.info("淘金荟撞库原始数据->:{}", body);
        try {
            response = HttpClientUtil.getInstance().postJsonData(collisionUrl, OBJECT_MAPPER.writeValueAsString(body));
            logger.info("淘金荟撞库原始返回数据->:{}", response);
        } catch (IOException e) {
            logger.error("淘金荟撞库原始返回数据失败->:{}", response);
            e.printStackTrace();
            return null;
        }
        if (StringUtils.isEmpty(response)) {
            logger.error("淘金荟撞库返回数据失败为空");
            return null;
        }
        TjhCollisionResponse tjhCollisionResponse = null;
        try {
            tjhCollisionResponse = JSON.parseObject(response, TjhCollisionResponse.class);
        } catch (Exception e) {
            logger.error("淘金荟撞库原始返回数据转换失败->:{}", tjhCollisionResponse);
            e.printStackTrace();
            return null;
        }
        return tjhCollisionResponse;
    }
 
    public TjhAutoResponse register(String mobile, String mobileType, String deviceBrand, String systemVersion, String systemModel) {
        String mobileTypeLower = mobileType.toLowerCase();
        String timeStamp = String.valueOf(System.currentTimeMillis());
        String sign = MD5Encryption.getMD5(appCode + mobile + timeStamp + channelKey).toUpperCase();
        // 请求体
        Map<String, Object> body = new HashMap<>(16);
        body.put("appCode", appCode);
        body.put("mobile", mobile);
        body.put("channel", channel);
        body.put("timeStamp", timeStamp);
        body.put("mobileType", mobileTypeLower);
        body.put("deviceBrand", deviceBrand);
        body.put("systemVersion", systemVersion);
        body.put("systemModel", systemModel);
        body.put("sign", sign);
        logger.info("淘金荟联合注册原始数据->:{}", body);
        String response = "";
        try {
            response = HttpClientUtil.getInstance().postJsonData(autoUrl, OBJECT_MAPPER.writeValueAsString(body));
            logger.info("淘金荟联合注册原始返回数据->:{}", response);
        } catch (IOException e) {
            logger.error("淘金荟联合注册原始返回数据失败->:{}", response);
            e.printStackTrace();
            return null;
        }
        if (StringUtils.isEmpty(response)) {
            logger.error("淘金荟联合注册返回数据失败为空");
            return null;
        }
        TjhAutoResponse tjhAutoResponse = null;
        try {
            tjhAutoResponse = JSON.parseObject(response, TjhAutoResponse.class);
        } catch (Exception e) {
            logger.error("淘金荟联合注册原始返回数据转换失败->:{}", tjhAutoResponse);
            e.printStackTrace();
            return null;
        }
        return tjhAutoResponse;
    }
 
}