新版仿ok交易所-后端
1
zyy
2026-03-05 9fa09b7700040b6cf416081ba0edfcfb72219b16
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
package com.yami.trading.admin.task;
 
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yami.trading.bean.cms.News;
import com.yami.trading.bean.data.domain.Depth;
import com.yami.trading.bean.data.domain.DepthEntry;
import com.yami.trading.bean.data.domain.Kline;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.common.constants.ContractRedisKeys;
import com.yami.trading.common.constants.RedisKeys;
import com.yami.trading.common.util.RedisUtil;
import com.yami.trading.huobi.hobi.Config;
import com.yami.trading.huobi.hobi.http.HttpHelper;
import com.yami.trading.huobi.hobi.http.HttpMethodType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
 
@Component
@Slf4j
public class NewsTask {
 
 
 
    @Scheduled(cron = "0 */30 * * * ?")
    public void test() throws Exception {
        try {
            String result = HttpHelper.getJSONFromHttp("https://newsapi.org/v2/top-headlines?country=us&category=business&apiKey=f39cfa8922534af295491f38f664ea3d", null, HttpMethodType.GET);
            JSONObject resultJson = JSON.parseObject(result);
            String status = resultJson.getString("status");
            if ("ok".equals(status)) {
                RedisUtil.set(RedisKeys.NEWS_TOP_HEADLINES, resultJson);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    void getNews() {
        try {
            String result = HttpHelper.getJSONFromHttp("https://newsapi.org/v2/top-headlines?country=us&category=business&apiKey=f39cfa8922534af295491f38f664ea3d", null, HttpMethodType.GET);
            JSONObject resultJson = JSON.parseObject(result);
            String status = resultJson.getString("status");
            if ("ok".equals(status)) {
                RedisUtil.set(RedisKeys.NEWS_TOP_HEADLINES, resultJson);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public static void main(String[] args) {
        NewsTask task = new NewsTask();
        task.getNews();
    }
}