ab
2024-11-05 0c6faf64f2a02ae94b0d719729754f7ca29da416
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
package com.nova.sankuai.domain.api.yibeifenqi;
 
import cn.hutool.crypto.digest.MD5;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.nova.sankuai.infra.mapper.CustomerMapper;
import com.nova.sankuai.service.ICustomerUserService;
import lombok.Getter;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.Objects;
 
/**
 * @author Gmw
 * @date 2022年5月19日
 */
@Getter
@Setter
@Component
public class YiBeiUtil {
 
    /**
     * 撞库接口
     */
    @Value("${yibei.config.check-user-url}")
    private String checkUserUrl;
 
    /**
     * 正式传参接口
     */
    @Value("${yibei.config.register-url}")
    private String registerUrl;
 
    /**
     * 渠道编码
     */
    @Value("${yibei.config.channel-code}")
    private String channelCode;
 
    /**
     * 回调接口使用到的
     */
    @Value("${yibei.config.sign-key}")
    private String signKey;
 
    /**
     * 用户渠道来源(固定参数)
     */
    public static final String channelSource = "BSB00001";
 
 
    @Resource
    ICustomerUserService customerUserService;
 
    @Resource
    CustomerMapper customerMapper;
 
    private static final Logger log = LoggerFactory.getLogger("capitalLogger");
 
    /**
     * 撞库接口
     *
     * @param phone 手机号
     * @return
     */
    public YiBeiCheckUserResponseVO checkUser(String phone) {
        MD5 md5 = MD5.create();
        String phoneMd5 = md5.digestHex(phone);
        String sign = md5.digestHex(String.format("phoneMd5=%s&channelCode=%s", phoneMd5, channelCode));
        String body = JSON.toJSONString(new YiBeiCheckUserDTO(phoneMd5, channelCode, sign));
        log.info("易贝分期撞库请求, phone={}, body={}", phone, body);
        HttpResponse response = HttpUtil.createPost(checkUserUrl)
                .header("Content-Type", "application/json")
                .body(body)
                .execute();
        if (response == null) {
            log.error("易贝分期撞库请求失败");
            return null;
        }
        YiBeiCheckUserResponseVO vo = null;
        try {
            vo = JSON.parseObject(response.body(), YiBeiCheckUserResponseVO.class);
            boolean flag = Objects.equals(vo.getStatus(), 1) // 接口返回成功
                    && Objects.equals(vo.getData().getFilterResult(), 1); // 新用户
            if (flag) {
                log.info("易贝分期撞库请求成功, phone={}", phone);
            } else {
                log.info("易贝分期撞库请求失败, phone={}, resp={}", phone, response.body());
                return null;
            }
            return vo;
        } catch (Exception e) {
            log.info("易贝分期撞库返回转换失败, phone={}, resp={}", phone, response);
            return null;
        }
    }
 
    public YiBeiRegisterResponseVO register(YiBeiRegisterDTO registerDTO) {
        MD5 md5 = MD5.create();
        String sign = md5.digestHex(String.format("phone=%s&channelCode=%s", registerDTO.getPhone(), channelCode));
        registerDTO.setSign(sign);
        registerDTO.setChannelCode(channelCode);
        registerDTO.setChannelSource(channelSource);
        String body = JSON.toJSONString(registerDTO);
        log.info("易贝分期注册请求, param={}", body);
        HttpResponse response = HttpUtil.createPost(registerUrl)
                .header("Content-Type", "application/json")
                .body(body)
                .execute();
        if (response == null) {
            log.error("易贝分期联登请求失败");
            return null;
        }
        YiBeiRegisterResponseVO yiBeiRegisterResponseVO = null;
        try {
            yiBeiRegisterResponseVO = JSON.parseObject(response.body(), YiBeiRegisterResponseVO.class);
            if (yiBeiRegisterResponseVO != null && yiBeiRegisterResponseVO.getStatus() != null && yiBeiRegisterResponseVO.getData() != null) {
                log.info("易贝分期联登返回转换数据为,{}", yiBeiRegisterResponseVO.toString());
                return yiBeiRegisterResponseVO;
            }
        } catch (Exception e) {
            log.info("易贝分期联登返回转换失败,{}", response.body());
            return null;
        }
        log.info("易贝分期联登返回失败,{}", yiBeiRegisterResponseVO);
        return null;
    }
 
}