From 3cfb3d987566f4baf5563a52dced85c9bd8a5391 Mon Sep 17 00:00:00 2001
From: dd <gitluke@outlook.com>
Date: Fri, 26 Dec 2025 01:47:15 +0800
Subject: [PATCH] 1

---
 src/main/java/com/nq/service/impl/PriceServicesImpl.java |   54 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/src/main/java/com/nq/service/impl/PriceServicesImpl.java b/src/main/java/com/nq/service/impl/PriceServicesImpl.java
index 77755e0..c0a3e1d 100644
--- a/src/main/java/com/nq/service/impl/PriceServicesImpl.java
+++ b/src/main/java/com/nq/service/impl/PriceServicesImpl.java
@@ -2,6 +2,7 @@
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.http.HttpUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.google.gson.Gson;
@@ -10,9 +11,11 @@
 import com.nq.dao.StockMapper;
 import com.nq.dao.StockSettingMapper;
 import com.nq.enums.EConfigKey;
+import com.nq.enums.EStockType;
 import com.nq.pojo.*;
 import com.nq.service.IPriceServices;
 import com.nq.service.IStockConfigServices;
+import com.nq.utils.PropertiesUtil;
 import com.nq.utils.http.HttpClientRequest;
 import com.nq.utils.redis.RedisKeyUtil;
 import com.nq.utils.timeutil.TimeUtil;
@@ -20,8 +23,7 @@
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
+import java.io.*;
 import java.lang.reflect.Type;
 import java.math.BigDecimal;
 import  java.io.BufferedReader;
@@ -67,7 +69,7 @@
                     String s = doGet(stock.getStockCode());
                     if(null != s){
                         Map<String, Object> stringObjectMap = jsonToMap(s);
-                        return   new BigDecimal(stringObjectMap.get("last").toString()).multiply(new BigDecimal(stockSetting.getPrice()));
+                        return   new BigDecimal(stringObjectMap.get("Last").toString()).multiply(new BigDecimal(stockSetting.getPrice()));
                     }
                 }
             }
@@ -76,7 +78,7 @@
         String s = doGet(stock.getStockCode());
         if(null != s) {
             Map<String, Object> stringObjectMap = jsonToMap(s);
-            return  new BigDecimal(stringObjectMap.get("last").toString());
+            return  new BigDecimal(stringObjectMap.get("Last").toString());
         }
         return BigDecimal.ZERO;
     }
@@ -107,26 +109,44 @@
         }
     }
 
-    public String doGet(String pid){
-        String  apiUrl  =  "http://api-in-2.js-stock.top/stock?pid="+pid+"&key=eVKtHt7aG4m6ozwWL9qG";
-        try  {
-            URL  url  =  new  URL(apiUrl);
-            HttpURLConnection  connection  =  (HttpURLConnection)  url.openConnection();
-            connection.setRequestMethod("GET");
+    public String doGet(String pid) {
+        // 从配置中获取 API URL,并拼接 key
+        String apiUrl = PropertiesUtil.getProperty("JS_IN_HTTP_URL") + "stock?key=" + PropertiesUtil.getProperty("JS_IN_KEY");
+        String result = null;
+        try {
+            Thread.sleep(3000);
+            URL url = new URL(apiUrl);
+            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
 
-            BufferedReader in  =  new  BufferedReader(new InputStreamReader(connection.getInputStream()));
-            String  inputLine;
-            StringBuffer  response  =  new  StringBuffer();
+            // 设置请求方法为 POST
+            connection.setRequestMethod("POST");
+            // 设置请求头
+            connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
+            connection.setDoOutput(true); // 允许向连接输出
 
-            while  ((inputLine  =  in.readLine())  !=  null)  {
+            // 构建 POST 数据
+            String postData = "pid=" + pid;
+
+            // 发送 POST 请求
+            try (OutputStream os = connection.getOutputStream()) {
+                byte[] input = postData.getBytes("utf-8");
+                os.write(input, 0, input.length);
+            }
+
+            // 读取响应
+            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+            String inputLine;
+            StringBuffer response = new StringBuffer();
+
+            while ((inputLine = in.readLine()) != null) {
                 response.append(inputLine);
             }
             in.close();
-            return response.toString();
-        }  catch  (Exception  e)  {
+            result = response.toString();
+        } catch (Exception e) {
             e.printStackTrace();
         }
-        return null;
+        return result;
     }
 
     @Override

--
Gitblit v1.9.3