package com.zx.dataservice.controller; import com.alibaba.fastjson.JSON; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Record; import com.zx.dataservice.utils.ZXOptions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.List; @Controller @RequestMapping({"/admin/"}) public class CallBackController { private static Logger LOG = LoggerFactory.getLogger(CallBackController.class); @GetMapping("/t1") @ResponseBody public String quantCallBack(String code){ String url1 = "https://api.huobi.pro/market/history/kline?period=1day&size=200&symbol=btcusdt"; String ur2 = "https://status.huobigroup.com/api/v2/summary.json"; String url = "https://api.huobi.pro/market/history/kline?period=1day&size=200&symbol=btcusdt"; String s1 = ""; try { // String wssurl1 = "ws://192.168.1.101:8088/websocket/zxdata9876541+"; // String wssurl1 = "ws://101.32.215.72:8080/data_server_java/websocket/zxdata9876541+"; // http://qwer16888.vip/stock2coin/ws/test/start.do // String s = HttpRequest.doGet(url, ""); // WsClient myClient = new WsClient(new URI(wssurl1)); // myClient.connect(); // 判断是否连接成功,未成功后面发送消息时会报错 // while (!myClient.getReadyState().equals(WebSocket.READYSTATE.OPEN)) { // System.out.println("连接中···请稍后"); // Thread.sleep(1000); // } // myClient.send("123"); // System.out.println("发送成功"); // new WebSocketController().sendSysMsg("zxdata987654+","sss"); } catch (Exception e) { return e.toString(); // e.printStackTrace(); // if(e.toString().length()>500){ LOG.error(e.toString().substring(0,450)); }else { LOG.error(e.toString()); } } // Request executeRequest = new Request.Builder() // .url(url) // .addHeader("Content-Type", "application/x-www-form-urlencoded") // .build(); // String str = ConnectionFactory.execute(executeRequest); return "true"; } @GetMapping("/test") @ResponseBody public boolean test(String code){ try { // QuantUtil quantUtil = new QuantUtil(); //// System.out.println("初始化东方财富"); // quantUtil.init(); //// //调用登录函数 // quantUtil.start(); } catch (Exception e) { if(e.toString().length()>500){ LOG.error(e.toString().substring(0,450)); }else { LOG.error(e.toString()); } } return true; } @GetMapping("/updateZX") @ResponseBody public boolean updateZX(String code){ try { List records = Db.use("gp").find("select config_key,config_value from sys_config "); for (Record record:records) { ZXOptions.set(record.getStr("config_key"),record.getStr("config_value")); } System.out.println(ZXOptions.get("ws.key")); } catch (Exception e) { if(e.toString().length()>500){ LOG.error(e.toString().substring(0,450)); }else { LOG.error(e.toString()); } } return true; } @GetMapping("/start") @ResponseBody public boolean start(String code){ try { } catch (Exception e) { if(e.toString().length()>500){ LOG.error(e.toString().substring(0,450)); }else { LOG.error(e.toString()); } } return true; } @GetMapping("/remMap") @ResponseBody public boolean remMap2(String key){ try { } catch (Exception e) { if(e.toString().length()>500){ LOG.error(e.toString().substring(0,450)); }else { LOG.error(e.toString()); } } return true; } @GetMapping("/remWSKey") @ResponseBody public boolean remWSKey(String key){ try { new WebSocketController().remWSKey(key); } catch (Exception e) { if(e.toString().length()>500){ LOG.error(e.toString().substring(0,450)); }else { LOG.error(e.toString()); } } return true; } @GetMapping("/testis") @ResponseBody public boolean testis(String key){ try { final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key for (int j = 0; j < webArr.length; j++) { new WebSocketController().sendSysMsg(webArr[j],key); } } catch (Exception e) { if(e.toString().length()>500){ LOG.error(e.toString().substring(0,450)); }else { LOG.error(e.toString()); } } return true; } }