liujie
7 小时以前 281c6016ab0ea5b2eeecb9167d9ee690b6fdac1f
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
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;
    }
 
 
}