1
zj
2024-07-25 bcd96e924ea184da9a4dacfd16a5c3bfba14ac53
websocketSerivce/src/main/java/org/example/controller/ApiController.java
@@ -14,6 +14,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
/**
@@ -71,4 +75,28 @@
       return HttpClientRequest.doGet(EStockType.IN.getStockUrl()) + "/new-stock?key=" + (EStockType.IN.getStockKey() + "&country_id=14");
    }
    @RequestMapping("/stock")
    @ResponseBody
    public String doGet(@RequestParam("pid") 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");
            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)  {
            e.printStackTrace();
        }
        return null;
    }
}