1
sunshine
2024-11-05 92a9e53e82c74d36a72eb92f93777bbb16e2db73
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
package com.nova.sankuai.domain.api.taohuihua;
 
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nova.sankuai.security.HttpClientUtil;
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 org.springframework.util.DigestUtils;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @Author Lilinhong
 * @Date 2022/7/27 14:54
 */
@Component
public class TaoHuiHuaUtil {
 
    private static final Logger logger = LoggerFactory.getLogger("capitalLogger");
 
    @Value("${taohuihua.check-url}")
    private String checkUrl;
 
    @Value("${taohuihua.register-url}")
    private String registerUrl;
 
    @Value("${taohuihua.appCode}")
    private String appCode;
 
    @Value("${taohuihua.channel}")
    private String channel;
 
    @Value("${taohuihua.channel-key}")
    private String channelKey;
 
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
 
    public TaoHuiHuaCheckResponse checkUser(String mobile, String mobileType, String deviceBrand, String systemVersion, String systemModel) {
        String phoneMd5 = DigestUtils.md5DigestAsHex(mobile.getBytes());
        String mobileTypeLower = null;
        if (StringUtils.isNotEmpty(mobileType)) {
            mobileTypeLower = mobileType.toLowerCase();
        }
        String timeStamp = String.valueOf(System.currentTimeMillis());
        String sign = DigestUtils.md5DigestAsHex((appCode + phoneMd5.toUpperCase() + timeStamp + channelKey).getBytes()).toUpperCase();
        // 请求体
        Map<String, Object> body = new HashMap<>(16);
        body.put("appCode", appCode);
        body.put("mobile", phoneMd5.toUpperCase());
        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.error("淘惠花撞库原始数据->:{}", body);
        try {
            response = HttpClientUtil.getInstance().postJsonData(checkUrl, OBJECT_MAPPER.writeValueAsString(body));
            logger.error("淘惠花撞库原始返回数据->:{}", response);
        } catch (IOException e) {
            logger.error("淘惠花撞库原始返回数据失败->:{}", response);
            e.printStackTrace();
            return null;
        }
        if (StringUtils.isEmpty(response)) {
            logger.error("淘惠花撞库返回数据失败为空");
            return null;
        }
        TaoHuiHuaCheckResponse taoHuiHuaCheckResponse = null;
        try {
            taoHuiHuaCheckResponse = JSON.parseObject(response, TaoHuiHuaCheckResponse.class);
        } catch (Exception e) {
            logger.error("淘惠花撞库原始返回数据转换失败->:{}", taoHuiHuaCheckResponse);
            e.printStackTrace();
            return null;
        }
        return taoHuiHuaCheckResponse;
    }
 
    public TaoHuiHuaRegisterResponse register(String mobile, String mobileType, String deviceBrand, String systemVersion, String systemModel) {
        String mobileTypeLower = null;
        if (StringUtils.isNotEmpty(mobileType)) {
            mobileTypeLower = mobileType.toLowerCase();
        }
        String timeStamp = String.valueOf(System.currentTimeMillis());
        String sign = DigestUtils.md5DigestAsHex((appCode + mobile + timeStamp + channelKey).getBytes()).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.error("淘惠花联合注册原始数据->:{}", body);
        String response = "";
        try {
            response = HttpClientUtil.getInstance().postJsonData(registerUrl, OBJECT_MAPPER.writeValueAsString(body));
            logger.error("淘惠花联合注册原始返回数据->:{}", response);
        } catch (IOException e) {
            logger.error("淘惠花联合注册原始返回数据失败->:{}", response);
            e.printStackTrace();
            return null;
        }
        if (StringUtils.isEmpty(response)) {
            logger.error("淘惠花联合注册返回数据失败为空");
            return null;
        }
        TaoHuiHuaRegisterResponse taoHuiHuaRegisterResponse = null;
        try {
            taoHuiHuaRegisterResponse = JSON.parseObject(response, TaoHuiHuaRegisterResponse.class);
        } catch (Exception e) {
            logger.error("淘惠花联合注册原始返回数据转换失败->:{}", taoHuiHuaRegisterResponse);
            e.printStackTrace();
            return null;
        }
        return taoHuiHuaRegisterResponse;
    }
 
}