YinShiController.java
14.5 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
package com.sincre.springboot.controller;
import com.alibaba.fastjson.JSON;
import com.sincre.springboot.ApiModel.YinShiResResult;
import com.sincre.springboot.ApiPlatform.YinShiServiceConfig;
import com.sincre.springboot.common.MD5;
import com.sincre.springboot.common.ResponseCode;
import com.sincre.springboot.common.ServerResponse;
import com.sincre.springboot.utils.ApiHelper;
import com.sincre.springboot.utils.CacheHelper;
import com.sincre.springboot.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/YinShi")
@Api(value = "YinShiController", tags = "萤石对接接口")
public class YinShiController {
@ApiOperation(value = "用于管理员获取accessToken")
@GetMapping("/token")
public ServerResponse GetYinShiToken() {
CacheHelper.GetYinShiToken();
return ServerResponse.createBySuccessMessage(ResponseCode.SUCCESS.getDesc());
}
@ApiOperation(value = "增加子账号")
@GetMapping("/addChildAccount")
public ServerResponse addChildAccount(@RequestParam String accountName, @RequestParam String password) {
String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/create";
Map<String, Object> map = new HashMap<>();
//子账户密码,LowerCase(MD5(AppKey#密码明文))
password = YinShiServiceConfig.appKey + "#" + password;
try {
password = MD5.md5(password, "").toLowerCase();
} catch (Exception ex) {
ex.getStackTrace();
}
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("accountName", accountName);
map.put("password", password);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
System.out.println(result);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "获取单个子账户信息")
@ApiImplicitParam(name="accountId",value = "子账号标识",required = true,dataType = "String")
@GetMapping("getChildAccount")
public ServerResponse getChildAccount(@RequestParam String accountId) {
String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/get";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("accountId", accountId);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "获取子账号信息列表")
@ApiImplicitParams({
@ApiImplicitParam(name="pageIndex", value = "分页起始页,从1开始",required = true),
@ApiImplicitParam(name="pageSize", value = "分页大小,默认为10,最大为50")
})
@GetMapping("getChildAccountList")
public ServerResponse getChildAccountList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize) {
pageIndex = pageIndex - 1;
String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/list";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("pageStart", pageIndex);
map.put("pageSize", pageSize);
String result = ApiHelper.doPost(url, new HashMap<String,String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "修改当前子账户密码")
@GetMapping("updateChildPassword")
public ServerResponse updateChildPassword(@RequestParam("accountId") String accountId, @RequestParam("newPassword") String newPassword, @RequestParam("oldPassword") String oldPassword) {
String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/updatePassword";
Map<String, Object> map = new HashMap<>();
oldPassword = YinShiServiceConfig.appKey + "#" + oldPassword;
newPassword = YinShiServiceConfig.appKey + "#" + newPassword;
try {
oldPassword = MD5.md5(oldPassword, "").toLowerCase();
newPassword = MD5.md5(newPassword, "").toLowerCase();
} catch (Exception ex) {
ex.getStackTrace();
}
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("accountId", accountId);
map.put("oldPassword", oldPassword);
map.put("newPassword", newPassword);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "删除指定子账户")
@GetMapping("deleteChildAccount")
public ServerResponse deleteChildAccount(@RequestParam String accountId) {
String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/delete";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("accountId", accountId);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "设置子账户的授权策略")
@GetMapping("policySet")
public ServerResponse policySet(@RequestParam String accountId, @RequestParam String policy) {
String url = YinShiServiceConfig.HostUrl + "lapp/ram/policy/set";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("accountId", accountId);
map.put("policy", policy);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "增加子账户授权策略中的授权语句")
@GetMapping("policyAdd")
public ServerResponse policyAdd(@RequestParam String accountId, @RequestParam String statement) {
String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/add";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("accountId", accountId);
map.put("statement", statement);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "删除子账户授权策略中指定设备的所有授权语句")
@GetMapping("policyDelete")
public ServerResponse policyDelete(@RequestParam String accountId, @RequestParam String deviceSerial) {
String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/delete";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("accountId", accountId);
map.put("deviceSerial", deviceSerial);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "获取B模式子账户accessToken")
@GetMapping("getChildAccountToken")
public ServerResponse getChildAccountToken(@RequestParam String accountId) {
String url = YinShiServiceConfig.HostUrl + "lapp/ram/token/get";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("accountId", accountId);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "添加设备到账号下")
@ApiImplicitParams({
@ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true),
@ApiImplicitParam(name="validateCode",value = "备验证码,设备机身上的六位大写字母,如OLZKQU",required = true)
})
@GetMapping("addAccountDevice")
public ServerResponse addAccountDevice(@RequestParam String deviceSerial,@RequestParam String validateCode) {
String url = YinShiServiceConfig.HostUrl + "lapp/device/add";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("deviceSerial", deviceSerial);
map.put("validateCode", validateCode);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "修改设备的名称")
@ApiImplicitParams({
@ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true),
@ApiImplicitParam(name="deviceName",value = "设备名称,长度不大于50字节,不能包含特殊字符",required = true)
})
@GetMapping("updateDeviceName")
public ServerResponse updateDeviceName(@RequestParam String deviceName,@RequestParam String deviceSerial) {
String url = YinShiServiceConfig.HostUrl + "lapp/device/name/update";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("deviceSerial", deviceSerial);
map.put("deviceName", deviceName);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "删除设备")
@ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true)
@GetMapping("deleteDevice")
public ServerResponse deleteDevice(@RequestParam String deviceSerial) {
String url = YinShiServiceConfig.HostUrl + "lapp/device/delete";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("deviceSerial", deviceSerial);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "设备抓拍图片")
@ApiImplicitParams({
@ApiImplicitParam(name="channelNo",value = "通道号,IPC设备填写1",required = true),
@ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true)
})
@GetMapping("deviceCapture")
public ServerResponse deviceCapture(@RequestParam Integer channelNo,@RequestParam String deviceSerial) {
String url = YinShiServiceConfig.HostUrl + "lapp/device/capture";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("deviceSerial", deviceSerial);
map.put("channelNo",channelNo);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "获取设备列表")
@ApiImplicitParams({
@ApiImplicitParam(name="pageIndex", value = "分页起始页,从1开始",required = true),
@ApiImplicitParam(name="pageSize", value = "分页大小,默认为10,最大为50")
})
@GetMapping("getDeviceList")
public ServerResponse getDeviceList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize) {
pageIndex = pageIndex - 1;
String url = YinShiServiceConfig.HostUrl + "lapp/device/list";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("pageStart", pageIndex);
map.put("pageSize", pageSize);
String result = ApiHelper.doPost(url, new HashMap<String,String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
@ApiOperation(value = "获取单个设备信息")
@ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true)
@GetMapping("getDeviceInfo")
public ServerResponse getDeviceInfo(@RequestParam String deviceSerial) {
String url = YinShiServiceConfig.HostUrl + "lapp/device/info";
Map<String, Object> map = new HashMap<>();
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("deviceSerial", deviceSerial);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
}
}