Air
2024-11-04 2016903d06e308f44b9463fcd4029850ababf152
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
package com.nova.sankuai.domain.api.sujinsuo;
 
import com.alibaba.fastjson.JSON;
import com.nova.sankuai.domain.dto.CustomerCompareDto;
import com.nova.sankuai.domain.entity.Customer;
import com.nova.sankuai.domain.enums.customerinfo.InsuranceStatusEnum;
import com.nova.sankuai.domain.enums.customerinfo.PayrollAgencyEnum;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
 
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
 
@ApiModel(value = "速金所接口对接工具类")
@Data
public class SuJinSuoUtil {
    @ApiModelProperty(value = "速金所API接口地址")
    public static final String SUJINSUO_URL = "http://139.224.251.4/api/ec/addCustomersByCBC";
    public static final String cKey = "whsjs20220214123";
 
    /**
     * 将Customer对象转换为民生接口对象
     *
     * @param customer
     * @return
     */
    public static String parseParam(Customer customer) {
        CustomerCompareDto parse = CustomerCompareDto.parse(customer);
        HashMap<String, Object> param = new HashMap<>();
//        param.put("name", customer.getName());
        param.put("name", "测试");
        param.put("quota", customer.getLoanAmount()); //额度
        param.put("city", "武汉");
        param.put("mobile", customer.getPhone());
        param.put("source", "SKFQ");
        Map tag = new HashMap();
        tag.put("bsnslcs", 2);
        tag.put("enterpriseTax", 2);
        tag.put("company", 2);
        if (customer.getHouseStatus() != null) {
            tag.put("house", parse.isHouseStatus() ? 1 : 0);
        }
        if (customer.getCarStatus() != null) {
            tag.put("car", parse.isCarStatus() ? 1 : 0);
        }
        if (customer.getSocialSecurity() != null) {
            tag.put("socialInsurance", parse.isSocialSecurity() ? 1 : 0);
        }else {
            tag.put("socialInsurance", 0);
        }
        if (customer.getProvidentFund() != null) {
            tag.put("fund", parse.isProvidentFund() ? 1 : 0);
        }else {
            tag.put("fund", 0);
        }
        if (customer.getInsurancePolicy() != null) {
            tag.put("policy", InsuranceStatusEnum.BusinessInsurance_6.getCode().equals(customer.getInsurancePolicy()) ? 1 : 0);
        }else {
            tag.put("policy", 0);
        }
        if (customer.getPayrollAgency() != null) {
            param.put("salary", PayrollAgencyEnum.PayrollAgency_2.getCode().equals(customer.getPayrollAgency()) ? 1 : 0);
        }else {
            tag.put("salary", 0);
        }
        if (customer.getMicroLoan() != null) {
            param.put("loan", PayrollAgencyEnum.PayrollAgency_2.getCode().equals(customer.getMicroLoan()) ? 1 : 0); //微粒贷额度
        }else {
            tag.put("loan", 0);
        }
        Map config = new HashMap();
        config.put("followUserId", 11253969);
        config.put("optUserId", 11253969);
        config.put("createUserId", 11253969);
        config.put("groupId", 0);
        param.put("ecConfig", JSON.toJSON(config));
        param.put("tag", JSON.toJSON(tag));
        String paramJson = JSON.toJSONString(param);
        HashMap<String, Object> paramMap = new HashMap<>();
        try {
            String encode = Encrypt(paramJson);;
            paramMap.put("data", encode);
        } catch (Exception e) {
            paramMap.put("data", "error");
        }
        return JSON.toJSONString(paramMap);
    }
    public static String Encrypt(String sSrc) throws Exception {
        byte[] raw = cKey.getBytes(StandardCharsets.UTF_8);
        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");//"算法/模式/补码方式"
        IvParameterSpec iv = new IvParameterSpec(cKey.getBytes());//使用CBC模式,需要一个向量iv,可增加加密算法的强度
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
        byte[] encrypted = cipher.doFinal(sSrc.getBytes());
        return new Base64().encode(encrypted);//此处使用BASE64做转码功能,同时能起到2次加密的作用。
    }
}