HttpUtils.java
5.38 KB
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
package com.example.dahua.utils;
import com.example.dahua.bean.PermissionBean;
import com.example.dahua.bean.PermissionFaceBean;
import com.example.dahua.bean.PermissionHKBean;
import com.example.dahua.lib.CompressPic;
import com.example.dahua.lib.FilePath;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestTemplate;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
public class HttpUtils {
public static boolean uploadImgs(File file, String schoolId, String studentCode, String clint_type, int userType) {
if (!file.exists()) {
System.out.println("图片不存在");
return false;
}
String targPath = FilePath.picPathComp + studentCode + ".jpg";
// String targPath = "C:\\Users\\taohandong\\Desktop\\comp\\"+userInfoBean.getStudentcode()+".jpg";
try {
CompressPic.CompressPic(file.getAbsolutePath(), targPath, studentCode);//压缩后的图片
} catch (Exception e) {
e.printStackTrace();
}
String url = "http://121.40.109.21:8991/file/uploadImg";
// String url = "http://localhost:8991/file/uploadImg";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE);
headers.setContentType(mediaType);
MultiValueMap<String, Object> multivaluedMap = new LinkedMultiValueMap<>();
FileSystemResource fileSystemResource = new FileSystemResource(targPath);
multivaluedMap.add("file", fileSystemResource);
multivaluedMap.add("schoolId", schoolId);
multivaluedMap.add("studentCode", studentCode);
multivaluedMap.add("clint_type", clint_type);
multivaluedMap.add("userType", userType);
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(multivaluedMap, headers);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, httpEntity, String.class);
System.out.println("responseEntity:" + responseEntity.getBody());
return responseEntity.getBody().equals("1");
}
public static String uploadImg2HK(String filePath,String card,String name,String deviceId,String userType){
String url = String.format("http://114.55.30.100:8089/facereco/sendCardAndImg1?filePath=%s&card=%s&name=%s&userType=%s&deviceId=%s",
filePath,card,name,userType,deviceId);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
System.out.println("responseEntity:" + responseEntity.getBody());
return responseEntity.getBody();
}
public static boolean imgsSend(String schoolId, int type) {
String url = "http://121.40.109.21:8991/file/imgsSend?schoolId=" + schoolId + "&type=" + type;
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Boolean> result = restTemplate.getForEntity(url, Boolean.class);
System.out.println("result:" + result.getBody());
return result.getBody();
}
public static boolean sendPermission(PermissionBean permissionBean) {
String url = "http://121.40.109.21:8991/file/sendPermission";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
MediaType mediaType = MediaType.parseMediaType(MediaType.APPLICATION_JSON_UTF8_VALUE);
headers.setContentType(mediaType);
HttpEntity<PermissionBean> httpEntity = new HttpEntity<>(permissionBean, headers);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, httpEntity, String.class);
System.out.println("大华设备下发权限:" + responseEntity.getBody());
return responseEntity.getBody().equals("1");
}
public static void sendPermission2HK(PermissionFaceBean permissionFaceBean) {
String url = "http://114.55.30.100:8089/facereco/sendPermiss";
PermissionBean permissionBean = permissionFaceBean.getPermissionBean();
if (null!=permissionBean){
PermissionHKBean permissionHKBean = new PermissionHKBean();
permissionHKBean.setDeviceIds(permissionBean.getDeviceIds());
permissionHKBean.setSchoolId(permissionFaceBean.getSchoolId()+"");
permissionHKBean.setUserType("2");
permissionHKBean.setWeekDays(permissionBean.getWeekDays());
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
MediaType mediaType = MediaType.parseMediaType(MediaType.APPLICATION_JSON_UTF8_VALUE);
headers.setContentType(mediaType);
HttpEntity<PermissionHKBean> httpEntity = new HttpEntity<>(permissionHKBean, headers);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, httpEntity, String.class);
System.out.println("海康设备下发权限:" + responseEntity.getBody());
}
}
}