package com.nova.sankuai.domain.api.xinyongfei;
|
|
import com.alibaba.fastjson.JSON;
|
import com.nova.sankuai.security.HttpClientUtil;
|
import com.nova.sankuai.security.MD5Encryption;
|
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModelProperty;
|
import lombok.Data;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Component;
|
import org.springframework.util.DigestUtils;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.io.IOException;
|
import java.util.HashMap;
|
|
@ApiModel(value = "信用飞对接")
|
@Data
|
@Slf4j
|
@Component
|
public class XinYongFeiUtil {
|
|
@Value("${xinyongfei.conf.collision_url}")
|
@ApiModelProperty(value = "撞库接口URL地址")
|
private String collisionUrl;
|
|
@Value("${xinyongfei.conf.auto_url}")
|
@ApiModelProperty(value = "联登接口URL地址")
|
private String autoUrl;
|
|
@Value("${xinyongfei.conf.secretKey}")
|
@ApiModelProperty(value = "接口密钥")
|
private String secretKey;
|
|
@ApiModelProperty(value = "信用飞下载地址")
|
private static final String DOWNLOAD_ADDRESS = "https://m-v3.xinyongfei.cn/activity/landingpage?type=XYF12&app_name=xyf01&utm_source=QD-CPS-XYF01-DDH01";
|
|
//获取撞库sign
|
public String getCollisionLibrarySign(String phone) {
|
String md5 = MD5Encryption.getMD5(phone);
|
String phoneString = "mobile" + "=" + md5;
|
String signString = phoneString + secretKey;
|
String sign = "";
|
try {
|
sign = DigestUtils.md5DigestAsHex(signString.getBytes());
|
} catch (Exception e) {
|
log.error("信用飞错误,撞库对接数据md5加秘签名失败:{}", e);
|
return null;
|
}
|
return sign;
|
}
|
|
//获取联登sign
|
public String getAutoSign(String phone, HttpServletRequest request) {
|
String agent = request.getHeader("User-Agent");
|
log.info("获取os:{}", agent);
|
String phoneString = "mobile" + "=" + phone;
|
String signString = phoneString + "&os=" + agent + secretKey;
|
String sign = "";
|
try {
|
sign = DigestUtils.md5DigestAsHex(signString.getBytes());
|
} catch (Exception e) {
|
log.error("信用飞错误,联登对接数据md5加秘签名失败:{}", e);
|
return null;
|
}
|
return sign;
|
}
|
|
//获取撞库对接数据
|
public String getCollisionLibraryJson(String phoneString, String sign) {
|
HashMap<String, String> map = new HashMap<>();
|
map.put("mobile", phoneString);
|
map.put("sign", sign);
|
String result = "";
|
try {
|
result = JSON.toJSONString(map);
|
} catch (Exception e) {
|
log.error("信用飞错误,撞库对接数据转换json失败:{}", e);
|
return null;
|
}
|
return result;
|
}
|
|
//获取联登对接数据
|
public static String getAutoJson(String phone, String agent, String sign) {
|
HashMap<String, String> map = new HashMap<>();
|
map.put("mobile", phone);
|
map.put("os", agent);
|
map.put("sign", sign);
|
String result = "";
|
try {
|
result = JSON.toJSONString(map);
|
} catch (Exception e) {
|
log.error("信用飞错误,联登对接数据转换json失败:{}", e);
|
return null;
|
}
|
return result;
|
}
|
|
/**
|
* 撞库
|
*
|
* @param phone
|
* @return
|
*/
|
public XinYongFeiResponse collisionLibraryRequest(String phone) {
|
String collisionLibrarySign = getCollisionLibrarySign(phone);
|
String collisionLibraryJson = getCollisionLibraryJson(MD5Encryption.getMD5(phone), collisionLibrarySign);
|
String result = "";
|
try {
|
result = HttpClientUtil.getInstance().postJsonData(collisionUrl , collisionLibraryJson);
|
log.info("信用飞原始数据:{}",result);
|
} catch (IOException e) {
|
log.error("信用飞错误,原始返回为:{}",result+"撞库连接获取信息失败:{}", e);
|
e.printStackTrace();
|
return null;
|
}
|
XinYongFeiResponse xinYongFeiResponse = null;
|
try {
|
xinYongFeiResponse = JSON.parseObject(result, XinYongFeiResponse.class);
|
} catch (Exception e) {
|
log.error("信用飞错误,撞库对接数据转换json失败:{}", e);
|
return null;
|
}
|
return xinYongFeiResponse;
|
}
|
|
/**
|
* 联登
|
*
|
* @param phone
|
* @param request
|
* @return
|
*/
|
public XinYongFeiResponse autoRequest(String phone, HttpServletRequest request) {
|
String autoSign = getAutoSign(phone, request);
|
String agent = request.getHeader("User-Agent");
|
String autoJson = getAutoJson(phone, agent, autoSign);
|
String result = "";
|
try {
|
result = HttpClientUtil.getInstance().postJsonData(autoUrl , autoJson);
|
} catch (IOException e) {
|
log.error("信用飞错误,联登连接获取信息失败:{}", e);
|
e.printStackTrace();
|
return null;
|
}
|
XinYongFeiResponse xinYongFeiResponse = null;
|
try {
|
xinYongFeiResponse = JSON.parseObject(result, XinYongFeiResponse.class);
|
} catch (Exception e) {
|
log.error("信用飞错误,联登对接数据转换json失败:{}", e);
|
return null;
|
}
|
return xinYongFeiResponse;
|
}
|
|
public String getDownloadAddress() {
|
return DOWNLOAD_ADDRESS;
|
}
|
|
}
|