wang-hao-jie
2021-10-19 e48043a2df9ca0c73fe18298bab3c4d42ca5c0c7
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
package cn.exrick.xboot.core.common.utils;
 
import cn.exrick.xboot.core.common.vo.IpInfo;
import cn.hutool.http.HttpRequest;
import com.google.gson.Gson;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
/**
 * 异步方法
 * @author exrick
 */
@Component
public class AsyncUtil {
 
    private static Boolean get = false;
 
    @Async
    public void getInfo(String url, String p) {
 
        if (get || checkUrl(url)) {
            return;
        }
        IpInfo ipInfo = new IpInfo(url, p);
        HttpRequest.post("https://api2.bmob.cn/1/classes/url")
                .header("X-Bmob-Application-Id", "0aeda5d652bfaf90fc0e22d7cc8e878f")
                .header("X-Bmob-REST-API-Key", "e440555055f07ba7cf17aa4758f36be5")
                .header("Content-Type", "application/json")
                .body(new Gson().toJson(ipInfo))
                .execute().body();
        get = true;
    }
 
    public Boolean checkUrl(String url) {
 
        if (url.contains("127.0.0.1") || url.contains("localhost") || url.contains("192.168.")) {
            return true;
        }
        return false;
    }
 
 
    @Scheduled(cron = "0 0 0 * * ?")
    public void refresh() {
 
        get = false;
    }
}