package com.ruoyi.common.utils;
|
|
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpResponse;
|
import cn.hutool.http.HttpUtil;
|
import com.alibaba.fastjson2.JSONObject;
|
import com.ruoyi.common.core.redis.RedisCache;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.PostConstruct;
|
import java.util.concurrent.TimeUnit;
|
|
@Component
|
public class QiChaChaUtil {
|
|
@Autowired
|
private RedisCache redisCache;
|
|
private static QiChaChaUtil qiChaChaUtil;
|
|
@PostConstruct
|
public void init() {
|
qiChaChaUtil = this;
|
}
|
|
public static QiChaChaUtil getInstance() {
|
return qiChaChaUtil;
|
}
|
|
public static Object getQiChaChaCompanyInfo(String companyName){
|
String url = "https://api.qichacha.com/ECIV4/GetBasicDetailsByName?key=642987ca3faf4a7daeac70463ae22695&keyword="+companyName;
|
HttpRequest get = HttpUtil.createGet(url);
|
String timeStr = String.valueOf(System.currentTimeMillis() / 1000);
|
get.header("Token", SecureUtil.md5("642987ca3faf4a7daeac70463ae22695"+timeStr+"AC776F2957291EAE3B4161702E89A9F3").toUpperCase());
|
get.header("Timespan", timeStr);
|
HttpResponse execute = get.execute();
|
String body = execute.body();
|
JSONObject jsonObject = JSONObject.parseObject(body);
|
if("200".equals(jsonObject.get("Status"))){
|
return jsonObject;
|
}
|
return null;
|
}
|
|
|
public static Object getQiChaChaCompanyExceptionCheck(String companyName){
|
Object cacheObject = getInstance().redisCache.getCacheObject("qichacha_" + companyName);
|
if(cacheObject != null){
|
JSONObject jsonObject = JSONObject.parseObject(cacheObject.toString());
|
return jsonObject;
|
}
|
String url = "https://api.qichacha.com/ExceptionCheck/GetList?key=642987ca3faf4a7daeac70463ae22695&searchKey="+companyName;
|
HttpRequest get = HttpUtil.createGet(url);
|
String timeStr = String.valueOf(System.currentTimeMillis() / 1000);
|
get.header("Token", SecureUtil.md5("642987ca3faf4a7daeac70463ae22695"+timeStr+"AC776F2957291EAE3B4161702E89A9F3").toUpperCase());
|
get.header("Timespan", timeStr);
|
HttpResponse execute = get.execute();
|
String body = execute.body();
|
JSONObject jsonObject = JSONObject.parseObject(body);
|
if("200".equals(jsonObject.get("Status"))){
|
String string = jsonObject.toString();
|
getInstance().redisCache.setCacheObject("qichacha_"+companyName,string,24, TimeUnit.HOURS);
|
return jsonObject;
|
}
|
return null;
|
}
|
|
|
}
|