KKSU
2024-04-17 d23645e976981bc9b670eea1d469fe8a36be309c
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
package com.xcong.excoin;
 
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.xcong.excoin.modules.blackchain.service.Trc20Service;
import com.xcong.excoin.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @author wzy
 * @date 2021-05-04
 **/
@Slf4j
@SpringBootTest
public class TrcTest {
 
    @Autowired
    private RedisUtils redisUtils;
 
    @Test
    public void trc20Test() {
        String url = "https://api.trongrid.io/wallet/getblockbynum";
 
        while(true) {
            Object current = redisUtils.get("USDT_TRC20_CURRENT_BLOCK_NUM");
            Map<String, Object> map = new HashMap<>();
            map.put("num", current);
            String param = JSON.toJSONString(map);
            System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
            HttpResponse response = HttpUtil.createPost(url).body(param).contentType("application/json").header("TRON-PRO-API-KEY", Trc20Service.API_KEY).execute();
//            log.info(response.body());
 
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}