| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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())); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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; |
| | | } |
| | |
| | | } |
| | | |
| | | public String doGet(String pid){ |
| | | EStockType eStockType = EStockType.getEStockTypeByCode("IN"); |
| | | String apiUrl = eStockType.stockUrl+"?pid="+pid+"&key="+eStockType.stockKey; |
| | | // 从配置中获取 API URL,并拼接 key |
| | | String apiUrl = PropertiesUtil.getProperty("JS_IN_HTTP_URL") + "stock?key=" + PropertiesUtil.getProperty("JS_IN_KEY"); |
| | | String result = null; |
| | | try { |
| | | URL url = new URL(apiUrl); |
| | | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| | | connection.setRequestMethod("GET"); |
| | | |
| | | // 设置请求方法为 POST |
| | | connection.setRequestMethod("POST"); |
| | | // 设置请求头 |
| | | connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); |
| | | connection.setDoOutput(true); // 允许向连接输出 |
| | | |
| | | // 构建 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(); |
| | |
| | | response.append(inputLine); |
| | | } |
| | | in.close(); |
| | | return response.toString(); |
| | | result = response.toString(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | return result; |
| | | } |
| | | |
| | | @Override |