package com.happy.action; import com.alibaba.fastjson.JSONObject; import com.happy.Model.Fmap; import com.happy.Model.Hmap; import com.happy.Model.Smap; import com.happy.Until.ResUtil; import com.happy.Until.TimeExchange; import com.happy.common.http.HttpRequestUtils; import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.ServletActionContext; import org.apache.struts2.interceptor.ServletRequestAware; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class loginAction extends ActionSupport implements ServletRequestAware { private HttpServletRequest request; public HttpServletResponse response; public HttpServletRequest getRequest() { return request; } public void setRequest(HttpServletRequest request) { this.request = request; } public void setServletRequest(HttpServletRequest request) { this.request = request; } public HttpServletResponse getResponse() { return response; } public void setResponse(HttpServletResponse response) { this.response = response; } public String login() throws Exception { HttpRequestUtils.sendPost("https://172.22.42.1:443/API/Web/Login","123","admin","Chuanghai-2021","json"); String token = Hmap.map.get("token"); String cookie = Hmap.map.get("cookie"); while (true){ String msg = HttpRequestUtils.sendPost2("https://172.22.42.1:443/API/Login/Heartbeat", token, cookie); Thread.sleep(6000); JSONObject json = JSONObject.parseObject(msg); if (json.get("result")==null){ HttpRequestUtils.sendPost("https://172.22.42.1:443/API/Web/Login","123","admin","Chuanghai-2021","json"); token = Hmap.map.get("token"); cookie = Hmap.map.get("cookie"); } } } public String firsts() throws Exception { String token = Hmap.map.get("token"); String cookie = Hmap.map.get("cookie"); JSONObject json = new JSONObject(); String msg = HttpRequestUtils.sendPost2("https://172.22.42.1:443/API/Event/Check", token, cookie); JSONObject jsonObject = JSONObject.parseObject(msg); String datas = jsonObject.getString("data"); JSONObject jsonObject2 = JSONObject.parseObject(datas); String reader_id = jsonObject2.getString("reader_id"); String sequence = jsonObject2.getString("sequence"); String lap_number = jsonObject2.getString("lap_number"); Fmap.map.put("reader_id",reader_id); Fmap.map.put("sequence", sequence); Fmap.map.put("lap_number", lap_number); json.put("code", 200); json.put("message", Fmap.map); ResUtil.writeJson(ServletActionContext.getResponse(), json.toString()); return null; } public String seconds() throws InterruptedException { while (true){ Thread.sleep(3000); String token = Hmap.map.get("token"); String cookie = Hmap.map.get("cookie"); JSONObject data = new JSONObject(); data.put("reader_id",Fmap.map.get("reader_id")); data.put("sequence",Fmap.map.get("sequence")); data.put("lap_number",Fmap.map.get("lap_number")); data.put("subscribe_ai_metadata",true); data.put("subscribe_intelligence",true); String msg = HttpRequestUtils.sendPost4("https://172.22.42.1:443/API/Event/Check",token,cookie,data); JSONObject json2 = JSONObject.parseObject(msg); String datas = json2.getString("data"); JSONObject json3 = JSONObject.parseObject(datas); if (json3.get("reader_id")==null){ token = Hmap.map.get("token"); cookie = Hmap.map.get("cookie"); String msg_first = HttpRequestUtils.sendPost2("https://172.22.42.1:443/API/Event/Check", token, cookie); JSONObject jsonObject = JSONObject.parseObject(msg_first); String datas_first = jsonObject.getString("data"); JSONObject jsonObject2 = JSONObject.parseObject(datas_first); String reader_id = jsonObject2.getString("reader_id"); String sequence = jsonObject2.getString("sequence"); String lap_number = jsonObject2.getString("lap_number"); Fmap.map.put("reader_id",reader_id); Fmap.map.put("sequence", sequence); Fmap.map.put("lap_number", lap_number); } if (json3.get("alarm_list")!=null){ json2.put("time", TimeExchange.getTime()); Smap.map.put("msg", JSONObject.toJSONString(json2)); } } } public String query(){ JSONObject json = new JSONObject(); String msg = Smap.map.get("msg"); json.put("code", 200); json.put("message", msg); ResUtil.writeJson(ServletActionContext.getResponse(), json.toString()); return null; } }