From 829f629756e5402bcd3e9f6ef1f9c6dbffbabb11 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Wed, 17 Apr 2024 14:46:29 +0800
Subject: [PATCH] 55测试环境
---
src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java | 113 ++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 80 insertions(+), 33 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 a8c87dc..a9ae7b9 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;
@@ -11,10 +13,9 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
+import org.springframework.util.ClassUtils;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -35,39 +36,32 @@
@Autowired
private XchProfitService xchProfitService;
- @Scheduled(cron = "* */1 * * * ? ")
- public void baseDataUpdate() {
- // 请求价格等数据
- String result = getUrlResponse("https://api2.chiaexplorer.com/blockchainSummary");
- // 每t预计收益
- String profitPerT = getUrlResponse("https://api2.chiaexplorer.com/chart/xchTibDay?period=2w");
- JSONObject jsonObject = (JSONObject) JSONObject.parse(result);
- JSONObject perTObject = (JSONObject) JSONObject.parse(profitPerT);
- List<YdBasicSettingEntity> list = ydBasicSettingDao.selectList(null);
- if (CollUtil.isNotEmpty(list)) {
- YdBasicSettingEntity settingEntity = list.get(0);
- String netspaceStr = jsonObject.getString("netspace");
- BigDecimal baseUnit = BigDecimal.valueOf(1024);
- BigDecimal netspace = new BigDecimal(netspaceStr).divide(baseUnit.multiply(baseUnit.multiply(baseUnit.multiply(baseUnit.multiply(baseUnit)))), 2, BigDecimal.ROUND_DOWN);
- settingEntity.setAllPower(netspace);
-
- BigDecimal newPrice = new BigDecimal(jsonObject.getString("price"));
- redisUtils.set("XCH_NEW_PRICE", newPrice);
- settingEntity.setCurrentPrice(newPrice);
- List<String> data = JSONObject.parseArray(perTObject.getString("data"), String.class);
- settingEntity.setPrifitT(new BigDecimal(data.get(0)));
- settingEntity.setProfitDay(new BigDecimal(data.get(0)).multiply(BigDecimal.valueOf(1024)));
-
- ydBasicSettingDao.updateById(settingEntity);
- }
- }
+// @Scheduled(cron = "0/1 * * * * ? ")
+// @Scheduled(cron = "0 0/10 * * * ? ")
+// public void baseDataUpdate() {
+// log.info("基础数据更新任务");
+// // 请求价格等数据 "https://api2.chiaexplorer.com/blockchainSummary"
+// String result = pyExec();
+// JSONObject xchPrice24HObj = (JSONObject) JSONObject.parse(result);
+// List<YdBasicSettingEntity> list = ydBasicSettingDao.selectList(null);
+// if (CollUtil.isNotEmpty(list)) {
+// YdBasicSettingEntity settingEntity = list.get(0);
+// List<String> xchPrice24H = JSONObject.parseArray(xchPrice24HObj.getString("data"), String.class);
+//
+// BigDecimal newestPrice = new BigDecimal(xchPrice24H.get(xchPrice24H.size() - 1));
+//
+// redisUtils.set("XCH_NEW_PRICE", newestPrice);
+// settingEntity.setCurrentPrice(newestPrice);
+// ydBasicSettingDao.updateById(settingEntity);
+// }
+// }
private String getUrlResponse(String url) {
BufferedReader reader = null;
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);
@@ -94,15 +88,68 @@
return result;
}
-// @Scheduled(cron = "0 0 23 * * ?")
+ // @Scheduled(cron = "0 0 23 * * ?")
public void xchProfitJob() {
log.info("XCH收益返利任务");
// xchProfitService.xchProfitDistributor();
}
-// @Scheduled(cron = "0 0 22 * * ?")
+ // @Scheduled(cron = "0 0 22 * * ?")
public void usdtProfitJob() {
log.info("USDT返利任务");
- xchProfitService.agentUsdtProfitDistributor();
+// 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;
+ }
+
+ public String pyExec() {
+ String result = "";
+ String cmd = "python2.7 /home/javaweb/yunding/xch.py";
+// String cmd = "python /Users/helius/Desktop/xch.py";
+ try {
+ Process process = Runtime.getRuntime().exec(cmd);
+ process.waitFor();
+ InputStreamReader ir = new InputStreamReader(process.getInputStream());
+ LineNumberReader input = new LineNumberReader(ir);
+ result = input.readLine();
+ input.close();
+ ir.close();
+ } catch (IOException | InterruptedException e) {
+ log.error("python执行异常", e);
+ }
+ return result;
+ }
+
}
--
Gitblit v1.9.1