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;
|
}
|
|
|
}
|