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
package com.nova.sankuai.domain.api.huizhongzhidai;
 
import com.alibaba.fastjson.JSONObject;
import com.nova.sankuai.domain.dto.CustomerCompareDto;
import com.nova.sankuai.domain.entity.Customer;
import com.nova.sankuai.security.MD5Encryption;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
 
import javax.crypto.*;
import javax.crypto.spec.DESedeKeySpec;
import javax.crypto.spec.IvParameterSpec;
import java.nio.charset.StandardCharsets;
import java.security.Key;
 
/**
 * <p>
 * 惠众直贷接口公司对接
 * </p>
 *
 * @author: zcj  2022/2/17
 */
@Data
@Slf4j
@Component
@ApiModel(value = "惠众直贷接口公司对接")
public class HuiZhongZhiDaiUtil {
    @Value("${huizhongzhidai.hitUrl}")
    public String hitUrl;
 
    @Value("${huizhongzhidai.commitUrl}")
    public String commitUrl;
 
    @Value("${huizhongzhidai.source}")
    public String source;
 
    @Value("${huizhongzhidai.key}")
    public String key;
 
    public JSONObject parseHitParam(Customer customer) {
        JSONObject object = new JSONObject();
        object.put("registerFrom", this.source);
        // TODO 分支合并后改加密
        String phone = MD5Encryption.getMD5(customer.getPhone()) ;
        object.put("phoneNo", phone);
        return object;
    }
 
    public JSONObject parseCommitParam(Customer customer) {
        CustomerCompareDto parse = CustomerCompareDto.parse(customer);
        JSONObject json = new JSONObject();
        json.put("channel_source", this.source);
        json.put("cust_name", customer.getName());
        json.put("mobile", customer.getPhone());
        json.put("age", customer.getAge()==null?0:customer.getAge());
        json.put("sex", "0");
        json.put("city", customer.getCityName().substring(0, customer.getCityName().indexOf('市')));
        json.put("apply_limit", parse.getQuota());
        return json;
    }
 
    public String encrypt(String json){
        byte[] bytes = tripleDES(Cipher.ENCRYPT_MODE, json.getBytes(StandardCharsets.UTF_8), key.getBytes());
        byte[] base64 = Base64.encodeBase64(bytes);
        return new String(base64);
    }
 
    private static byte[] tripleDES(int opmode, byte[] data, byte[] secretKey) {
        return cipher("DESede", "DESede/CBC/PKCS5Padding", opmode, data, "01234567".getBytes(), secretKey);
    }
 
    private static byte[] cipher(String algorithm, String transformation, int opmode, byte[] data, byte[] iv, byte[] secretKey) {
        try {
            Key key = SecretKeyFactory.getInstance(algorithm).generateSecret(new DESedeKeySpec(secretKey));
            IvParameterSpec spec = new IvParameterSpec(iv);
            Cipher cipher = Cipher.getInstance(transformation);
            cipher.init(opmode, key, spec);
            return cipher.doFinal(data);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
 
}