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; } }