package com.nova.sankuai.domain.api.taojinhui; import com.alibaba.fastjson.JSON; import com.fasterxml.jackson.databind.ObjectMapper; import com.nova.sankuai.security.HttpClientUtil; import com.nova.sankuai.security.MD5Encryption; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.io.IOException; import java.util.HashMap; import java.util.Map; /** * @Author Lilinhong * @Date 2022/5/30 16:30 */ @Component @Slf4j public class TjhUtil { private static final Logger logger = LoggerFactory.getLogger("capitalLogger"); /** * 撞库地址 */ @Value("${taojinhui.collision_url}") private String collisionUrl; /** * 联合注册地址 */ @Value("${taojinhui.auto_url}") private String autoUrl; /** * 产品编码 */ @Value("${taojinhui.app_code}") private String appCode; /** * 渠道名称, 公钥 */ @Value("${taojinhui.channel}") private String channel; /** * 私钥 */ @Value("${taojinhui.channel_key}") private String channelKey; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); public TjhCollisionResponse checkUser(String mobile, String mobileType, String deviceBrand, String systemVersion, String systemModel) { String phoneMd5 = MD5Encryption.getMD5(mobile); String mobileTypeLower = null; if (StringUtils.isNotEmpty(mobileType)) { mobileTypeLower = mobileType.toLowerCase(); } String timeStamp = String.valueOf(System.currentTimeMillis()); String sign = MD5Encryption.getMD5(appCode + phoneMd5 + timeStamp + channelKey).toUpperCase(); // 请求体 Map body = new HashMap<>(16); body.put("appCode", appCode); body.put("mobile", phoneMd5); body.put("channel", channel); body.put("timeStamp", timeStamp); body.put("mobileType", mobileTypeLower); body.put("deviceBrand", deviceBrand); body.put("systemVersion", systemVersion); body.put("systemModel", systemModel); body.put("sign", sign); String response = ""; logger.info("淘金荟撞库原始数据->:{}", body); try { response = HttpClientUtil.getInstance().postJsonData(collisionUrl, OBJECT_MAPPER.writeValueAsString(body)); logger.info("淘金荟撞库原始返回数据->:{}", response); } catch (IOException e) { logger.error("淘金荟撞库原始返回数据失败->:{}", response); e.printStackTrace(); return null; } if (StringUtils.isEmpty(response)) { logger.error("淘金荟撞库返回数据失败为空"); return null; } TjhCollisionResponse tjhCollisionResponse = null; try { tjhCollisionResponse = JSON.parseObject(response, TjhCollisionResponse.class); } catch (Exception e) { logger.error("淘金荟撞库原始返回数据转换失败->:{}", tjhCollisionResponse); e.printStackTrace(); return null; } return tjhCollisionResponse; } public TjhAutoResponse register(String mobile, String mobileType, String deviceBrand, String systemVersion, String systemModel) { String mobileTypeLower = mobileType.toLowerCase(); String timeStamp = String.valueOf(System.currentTimeMillis()); String sign = MD5Encryption.getMD5(appCode + mobile + timeStamp + channelKey).toUpperCase(); // 请求体 Map body = new HashMap<>(16); body.put("appCode", appCode); body.put("mobile", mobile); body.put("channel", channel); body.put("timeStamp", timeStamp); body.put("mobileType", mobileTypeLower); body.put("deviceBrand", deviceBrand); body.put("systemVersion", systemVersion); body.put("systemModel", systemModel); body.put("sign", sign); logger.info("淘金荟联合注册原始数据->:{}", body); String response = ""; try { response = HttpClientUtil.getInstance().postJsonData(autoUrl, OBJECT_MAPPER.writeValueAsString(body)); logger.info("淘金荟联合注册原始返回数据->:{}", response); } catch (IOException e) { logger.error("淘金荟联合注册原始返回数据失败->:{}", response); e.printStackTrace(); return null; } if (StringUtils.isEmpty(response)) { logger.error("淘金荟联合注册返回数据失败为空"); return null; } TjhAutoResponse tjhAutoResponse = null; try { tjhAutoResponse = JSON.parseObject(response, TjhAutoResponse.class); } catch (Exception e) { logger.error("淘金荟联合注册原始返回数据转换失败->:{}", tjhAutoResponse); e.printStackTrace(); return null; } return tjhAutoResponse; } }