zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package http;
import java.net.InetAddress;
import java.util.LinkedHashMap;
import java.util.Vector;
 
import Method.BaoWenShow;
import PbuliClass.ShowMessage;
import VectroData.ForwardDatas;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import tbDataModel.Tb_forward_data;
public class HTTP_Post implements Runnable{    
    static Vector<LinkedHashMap<String, Object>> displayvc=new Vector<LinkedHashMap<String,Object>>();
    static int sleeptime=1;
    static Object lock=new Object();
    /**Æô¶¯Ï̵߳ķ½·¨*/
    public void startThread() {        
        Thread t=new Thread(this);
        t.start();
    }
 
 
    public void run() {
        while(true) {            
            try {
                synchronized (lock) {
                    lock.wait(sleeptime);
                    zhuanfa_display();
                }
            } catch (InterruptedException e) {
                e.printStackTrace(); 
            }        
            
        }
    }
    
    /**ת·¢Î»ÖÃÊý¾Ý*/
    public static void zhuanfa_display() {        
        if(displayvc.size()>10000) {
            displayvc.removeAllElements();
        }else {
            if(displayvc.size()==0) {
                sleeptime=100;
            }else {
                sleeptime=1;
                LinkedHashMap<String, Object> displayh= displayvc.get(0);
                HTTP_Post.display("", "", displayh);
                displayvc.removeElement(displayh);
            }
        }    
        
    }
    
    /**µÇÂ¼Ò³Ãæ*/
    public static String login(String url,String admin,String password) {
 
        String paramJson = "{\r\n" + 
                "\"password\": \""+password+"\",\r\n" + 
                "\"account\": \""+admin+"\"\r\n" + 
                "}";
 
        //µ÷ÓõǼ»ñÈ¡µÄtoken
        String token ="";
        //ÇëÇó½Ó¿Ú»ñÈ¡½á¹û
        String result = HttpRequest.post(url)
                .header("token",token)
                .body(paramJson)
                .execute().body();
 
        JSONObject jo = JSONUtil.parseObj(result);
        JSONObject jo1 = JSONUtil.parseObj(jo.get("data"));
        String tokens=(String) jo1.get("token");
        return tokens;
 
    }
 
 
    /**
     * ´«ÈëÐèÒªÁ¬½ÓµÄIP£¬·µ»ØÊÇ·ñÁ¬½Ó³É¹¦
     * @param remoteInetAddr
     * @return
     */
    public static boolean isReachable(String remoteInetAddr) {
        boolean reachable = false;
        try {
            InetAddress address = InetAddress.getByName(remoteInetAddr);
            reachable = address.isReachable(5000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return reachable;
    }
 
 
    /**HTTPת·¢Î»ÖÃÊý¾Ý
     * /**ת·¢ÊµÊ±Î»ÖÃÊý¾Ý
     * { 
     * {"type": "display", "tagid": "8252", "x":"200", "y": "585", "z": "150", "floor": "0" ,"biaozhi": "23", "timestamp": "2021-05-31 23:14:14.063"},     
     * {"type": "display", "tagid": "8354", "x":"175", "y": "369", "z": "175", "floor": "1", "biaozhi": "23", "timestamp": "2021-05-31 23:14:14.063"},  
     * {"type": "display", "tagid": "8680", "x":"857", "y": "814", "z": "163", "floor": "0", "biaozhi": "23", "timestamp": "2021-05-31 23:14:14.063"}
     * }**/
    public static void display(
            String admin,
            String password,
            LinkedHashMap<String, Object> display) {
        int size=ForwardDatas.get_mou_tb_forword("HTTP-Client", "λÖÃÊý¾Ý").size();
        for(int i=0;i<size;i++) {
            String url=ForwardDatas.get_mou_tb_forword("HTTP-Client", "λÖÃÊý¾Ý").get(i).getIp();
            JSONObject json = new JSONObject(display);
            try {
                String data=json.toString();
                HttpRequest.post(url).timeout(1000).header(Header.CONTENT_TYPE,"application/json").body(data).execute().body();
                BaoWenShow.show2(data, "HTTPת·¢",url,1000);
            } catch (Exception e) {
                displayvc.removeAllElements();
                sleeptime=1000;
                ShowMessage.zidingyi("HTTPת·¢Òì³£"+url);                
            }        
        }
    }
 
 
 
    /**²î·Ö¶¨Î»Êý¾Ý
     * ¸ñʽÈçÏÂ
     * {¡°positionmsg¡±:¡±$GNGGA,043310.44,3951.73773,N,11615.40420,E,4,12,0.71,53.0,M,-8.9,M,1.4,1935*41,1234,2d¡±}
     * Êý¾Ý¶¨Òå²Î¿¼£º¡¶±êǩʵʱλÖÃ$GNGGA¡·*/
    public static void gngga(
            String admin,
            String password,
            LinkedHashMap<String, Object> display) {
        int size=ForwardDatas.get_mou_tb_forword("HTTP-Client", "λÖÃÊý¾Ý").size();
        for(int i=0;i<size;i++) {
            //String url = "http://123.60.216.101:8081/stage-api/api/chinasoft/upload/uploadPositionForBeidou";
            String url=ForwardDatas.get_mou_tb_forword("HTTP-Client", "λÖÃÊý¾Ý").get(i).getIp();
            JSONObject json = new JSONObject(display);
            try {
                String data=json.toString();
                HttpRequest.post(url).header(Header.CONTENT_TYPE,"application/json").body(data).execute().body();
                BaoWenShow.show2(data, "HTTPת·¢",url,1000);
            } catch (Exception e) {
                ShowMessage.zidingyi("HTTPת·¢Òì³£"+url);
            }        
        }
    }
 
 
    /**HTTPת·¢¸æ¾¯Êý¾Ý*/
    public static void warnig(String admin,String password,LinkedHashMap<String, Object> message) {
        Vector<Tb_forward_data> vc=ForwardDatas.get_mou_tb_forword("HTTP-Client", "¸æ¾¯Êý¾Ý");
        int size=vc.size();
        for(int i=0;i<size;i++) {
            String url=vc.get(i).getIp();
            JSONObject json = new JSONObject(message);
            try {
                String data=json.toString();
                HttpRequest.post(url).header(Header.CONTENT_TYPE,"application/json").body(data).execute().body();
                BaoWenShow.show2(data, "HTTPת·¢",url,1000);
            } catch (Exception e) {
                ShowMessage.zidingyi("HTTPת·¢Òì³£"+url);
            }
        }
    }
 
 
    public static Vector<LinkedHashMap<String, Object>> getDisplayvc() {
        return displayvc;
    }
 
 
    public static void setDisplayvc(Vector<LinkedHashMap<String, Object>> display) {
        HTTP_Post.displayvc = display;
    }
 
 
}