| | |
| | | package com.xcong.excoin.modules.blackchain.service; |
| | | |
| | | import cn.hutool.core.math.MathUtil; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.http.*; |
| | | import org.springframework.http.client.SimpleClientHttpRequestFactory; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.tron.common.utils.ByteArray; |
| | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("num", num); |
| | | String param = JSON.toJSONString(map); |
| | | return postForEntity(url, param).getBody(); |
| | | // return postForEntity(url, param).getBody(); |
| | | return postForEntityHuTool(url, param).body(); |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | private static ResponseEntity<String> postForEntity(String url, String param) { |
| | | RestTemplate restTemplate = new RestTemplate(); |
| | | SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); |
| | | factory.setConnectTimeout(20000); |
| | | factory.setReadTimeout(20000); |
| | | RestTemplate restTemplate = new RestTemplate(factory); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | headers.set("TRON-PRO-API-KEY", Trc20Service.API_KEY); |
| | |
| | | ResponseEntity<String> result = restTemplate.postForEntity(url, request, String.class); |
| | | // System.out.println("url:" + url + ",param:" + param + ",result:" + result.getBody()); |
| | | return result; |
| | | } |
| | | |
| | | private static HttpResponse postForEntityHuTool(String url, String param) { |
| | | System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2"); |
| | | return HttpUtil.createPost(url).body(param) |
| | | .timeout(20000).contentType("application/json") |
| | | .header("TRON-PRO-API-KEY", Trc20Service.API_KEY) |
| | | .execute(); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | for (String address : addressList) { |
| | | if (address.equals(to_address)) { |
| | | System.out.println("存在本地的地址:" + address); |
| | | log.info("存在本地的地址:" + address); |
| | | // 金额 |
| | | // 发送消息队列 |
| | | EthUsdtChargeDto dto = new EthUsdtChargeDto(address, txId, amount); |
| | | dto.setSymbol(EthUsdtChargeDto.Symbol.USDT_TRC20); |
| | | usdtUpdateProducer.sendMsg(JSONObject.toJSONString(dto)); |
| | | System.out.println("===to_address:" + to_address + "===amount:" + amount); |
| | | log.info("===to_address:" + to_address + "===amount:" + amount); |
| | | } |
| | | } |
| | | |
| | |
| | | public Long getnowblockFromTronScan() { |
| | | String roundNum = Math.random() + ""; |
| | | String url = "https://apiasia.tronscan.io:5566/api/block/statistic?randomNum=" + roundNum; |
| | | RestTemplate restTemplate = new RestTemplate(); |
| | | SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); |
| | | factory.setConnectTimeout(20000); |
| | | factory.setReadTimeout(20000); |
| | | RestTemplate restTemplate = new RestTemplate(factory); |
| | | String forObject = restTemplate.getForObject(url, String.class); |
| | | String wholeBlockCount = JSON.parseObject(forObject).getString("whole_block_count"); |
| | | return Long.valueOf(wholeBlockCount); |