From 2b8b6b15c284bb5f75309ff695666f1da35a130a Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Tue, 18 May 2021 18:43:26 +0800
Subject: [PATCH] Merge branch 'yunding' of http://120.27.238.55:7000/r/exchange into yunding

---
 src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java |   52 +++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java b/src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java
index b33063c..4df1ca4 100644
--- a/src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java
+++ b/src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java
@@ -1,6 +1,8 @@
 package com.xcong.excoin.quartz.job;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.xcong.excoin.modules.yunding.dao.YdBasicSettingDao;
 import com.xcong.excoin.modules.yunding.entity.YdBasicSettingEntity;
@@ -13,6 +15,7 @@
 import org.springframework.stereotype.Component;
 
 import java.io.BufferedReader;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.math.BigDecimal;
@@ -35,15 +38,16 @@
     @Autowired
     private XchProfitService xchProfitService;
 
-    @Scheduled(cron = "0 0/1 * * * ? ")
+    @Scheduled(cron = "0 0 0/10 * * ? ")
+//    @Scheduled(cron = "0 0/1 * * * ? ")
     public void baseDataUpdate() {
         log.info("基础数据更新任务");
         // 请求价格等数据
-        String result = getUrlResponse("https://api2.chiaexplorer.com/blockchainSummary");
+        String result = execCurl("https://api2.chiaexplorer.com/blockchainSummary");
         // 每t预计收益
-        String profitPerT = getUrlResponse("https://api2.chiaexplorer.com/chart/xchTibDay?period=2w");
+        String profitPerT = execCurl("https://api2.chiaexplorer.com/chart/xchTibDay?period=2w");
 
-        String xchPrice24HStr = getUrlResponse("https://api2.chiaexplorer.com/chart/xchPriceChart?period=24h");
+        String xchPrice24HStr = execCurl("https://api2.chiaexplorer.com/chart/xchPriceChart?period=24h");
         JSONObject jsonObject = (JSONObject) JSONObject.parse(result);
         JSONObject perTObject = (JSONObject) JSONObject.parse(profitPerT);
         JSONObject xchPrice24HObj = (JSONObject) JSONObject.parse(xchPrice24HStr);
@@ -77,7 +81,7 @@
         String result = null;
         StringBuffer sbf = new StringBuffer();
         // 模拟浏览器
-        String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
+        String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36";
         try {
             System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
             URL request = new URL(url);
@@ -115,4 +119,42 @@
         log.info("USDT返利任务");
 //        xchProfitService.agentUsdtProfitDistributor();
     }
+
+    public static void main(String[] args) {
+
+
+
+//        System.out.println(HttpRequest.get("https://www.chiaexplorer.com").execute().body());
+//        System.out.println(execCurl(cmds));
+    }
+
+    private String execCurl(String url) {
+        String[] cmds = {"curl", url
+                , "-H", "sec-ch-ua: \" Not A;Brand\";v=\"99\", \"Chromium\";v=\"90\", \"Google Chrome\";v=\"90\""
+                ,"-H", "Accept: application/json, text/plain, */*"
+                ,"-H", "Referer: https://www.chiaexplorer.com/"
+                ,"-H", "sec-ch-ua-mobile: ?0"
+                ,"-H", "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"
+                ," --compressed"};
+
+        ProcessBuilder process = new ProcessBuilder(cmds);
+        Process p;
+        try {
+            p = process.start();
+            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+            StringBuilder builder = new StringBuilder();
+            String line;
+            while ((line = reader.readLine()) != null) {
+                builder.append(line);
+                builder.append(System.getProperty("line.separator"));
+            }
+            return builder.toString();
+
+        } catch (IOException e) {
+            System.out.print("error");
+            e.printStackTrace();
+        }
+        return null;
+    }
+
 }

--
Gitblit v1.9.1