ab
2024-11-04 09d882262f530ded672f1c01fb65a1fefa00d52d
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
package com.nova.sankuai.infra.utils.mxc;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.nova.sankuai.domain.dto.mxc.MxcDTO;
import com.nova.sankuai.domain.dto.mxc.MxcData;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
 
import java.nio.charset.StandardCharsets;
import java.util.Objects;
 
/**
 * 芒小橙对接
 */
@Component
public class MxcUtil {
 
    //撞库url
    @Value("${mxc.url}")
    private String url;
 
    @Value("${mxc.aesKey}")
    private String aesKey;
 
    private static final Logger log = LoggerFactory.getLogger("capitalLogger");
 
    public String push(String idcard, String phone, String name) {
        String respMsg = "";
        log.info("芒小橙联登撞库开始: phone:{}  name:{}  idcard:{}", phone, name, idcard);
        try {
            JSONObject jsonObject = new JSONObject();
            JSONObject jsonObject1 = new JSONObject();
            jsonObject.put("partner_id","mxchycyp");
            jsonObject1.put("idCard",idcard);
            jsonObject1.put("name",name);
            jsonObject1.put("phoneNum", phone);
//            cn.hutool.crypto.symmetric.AES aes = new cn.hutool.crypto.symmetric.AES("ECB",
//                    "PKCS5Padding", "OZqKairb9ciGd9xWn4q8re1g".getBytes());
            cn.hutool.crypto.symmetric.AES aes = new cn.hutool.crypto.symmetric.AES("ECB",
                    "PKCS5Padding", aesKey.getBytes());
            String biz_data = aes.encryptBase64(jsonObject1.toJSONString());
            jsonObject.put("biz_data",biz_data);
            //发送请求
            CloseableHttpClient httpClient = HttpClients.createDefault();
//            HttpPost httpPost = new HttpPost("http://101.37.166.164:8885/ycNotify-server/rongbei/121/check");
            HttpPost httpPost = new HttpPost(url);
            httpPost.addHeader("Content-type", "application/json; charset=UTF-8");
            httpPost.setEntity(new StringEntity(jsonObject.toJSONString(), StandardCharsets.UTF_8));
 
 
            CloseableHttpResponse response = httpClient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            respMsg = EntityUtils.toString(entity, StandardCharsets.UTF_8);
            if (StringUtils.isBlank(respMsg)) {
                log.error("芒小橙联登撞库失败: phone:{}  name:{}  idcard:{} 返回参数:{}", phone, name, idcard, respMsg);
            }
            else {
                MxcDTO res = JSON.parseObject(respMsg, MxcDTO.class);
                if (Objects.isNull(res)) {
                    log.error("芒小橙联登撞库失败: phone:{}  name:{}  idcard:{} 返回参数:{}", phone, name, idcard, respMsg);
                } else {
                    if (1 == res.getStatus()) {
                        log.error("芒小橙联登撞库失败: phone:{}  name:{}  idcard:{} 返回参数:{}", phone, name, idcard, respMsg);
                    }
                    else {
                        String data = res.getData();
                        data = aes.decryptStr(data);
                        MxcData mxcData = JSON.parseObject(data, MxcData.class);
                        String appUrl = mxcData.getAppUrl();
                        if(StringUtils.isNotBlank(appUrl)) {
                            log.info("芒小橙联登撞库成功: phone:{}  name:{}  idcard:{} 返回参数:{}", phone, name, idcard, respMsg);
                            url = appUrl;
                        }
                        else {
                            log.error("芒小橙联登撞库失败: phone:{}  name:{}  idcard:{} 返回参数:{}", phone, name, idcard, respMsg);
                        }
                    }
                }
            }
 
        } catch (Exception e) {
            log.error("芒小橙联登撞库失败: phone:{}  name:{}  idcard:{}  返回参数:{} 错误:{}", phone, name, idcard, respMsg,e);
        }
        return url;
    }
 
}