Commit fd706256 authored by 李洪明's avatar 李洪明

添加登录

parent 886d3d88
Pipeline #1274 canceled with stages
...@@ -340,7 +340,7 @@ public class HttpUtils { ...@@ -340,7 +340,7 @@ public class HttpUtils {
return httpClient.execute(request); return httpClient.execute(request);
} }
public static HttpResponse send(String host, String path, Map<String, String> querys, Map<String, Object> bodys) throws Exception { public static HttpResponse sendPost(String host, String path, Map<String, String> querys, Map<String, Object> bodys) throws Exception {
HttpClient httpClient = wrapClient(host); HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys)); HttpPost request = new HttpPost(buildUrl(host, path, querys));
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
...@@ -356,6 +356,20 @@ public class HttpUtils { ...@@ -356,6 +356,20 @@ public class HttpUtils {
return httpClient.execute(request); return httpClient.execute(request);
} }
public static HttpResponse sendGet(String host, String path,
Map<String, String> querys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpGet request = new HttpGet(buildUrl(host, path, querys));
Map<String, String> headers = new HashMap<>();
headers.put("X-Access-Token", LoginConfig.token);
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
return httpClient.execute(request);
}
} }
\ No newline at end of file
package com.bme.access.upload.job;
import com.bme.access.upload.common.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@EnableScheduling
@Slf4j
public class HeartBeatJob {
private final static String HEART_BEAT_URL = "https://dctapi.soszyzg.com/dct/heartbeat";
@Scheduled(cron = "0 0/30 * * * ?")
public void heartBeat() {
try {
HttpResponse response = HttpUtils.sendGet(HEART_BEAT_URL, null, null);
String str = EntityUtils.toString(response.getEntity());
} catch (Exception e) {
log.error("心跳协议(每半个小时调用一次): {}", e);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment