YinShiController.java
8.2 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
package com.sincre.springboot.controller;
import com.alibaba.fastjson.JSON;
import com.sincre.springboot.common.MD5;
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.ApiOperation;
import org.json.JSONObject;
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.Date;
import java.util.HashMap;
import java.util.Map;
import com.sincre.springboot.ApiPlatform.YinShiServiceConfig;
@RestController
@RequestMapping("/YinShi")
@Api(value = "YinShiController", tags = "萤石对接接口")
public class YinShiController {
private static String AccessToken = "at.2scte32926nu6q7j6adhlabg28emicz6-58f6w0596w-1ppubtz-uxh6dnv5x";
@ApiOperation(value = "用于管理员获取accessToken")
@GetMapping("/token")
public String GetYinShiToken() {
String appKey = YinShiServiceConfig.appKey;
String appSecret = YinShiServiceConfig.appSecret;
String url = YinShiServiceConfig.HostUrl + "lapp/token/get";
Map<String, Object> map = new HashMap<>();
map.put("appKey", appKey);
map.put("appSecret", appSecret);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
JSONObject jsonObject = new JSONObject(result);
JSONObject data = jsonObject.optJSONObject("data");
YinShiServiceConfig.AccessToken = data.optString("accessToken");
Date date = new Date();
Date dateFu = new Date(data.optLong("expireTime"));
CacheHelper.putYingshiYunToken(YinShiServiceConfig.AccessToken, (int) ((dateFu.getTime()-date.getTime())/1000));
return ResultUtils.getInstance().resturnResultYingshi(result);
}
@ApiOperation(value = "增加子账号")
@GetMapping("/addChildAccount")
public String 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);
return ResultUtils.getInstance().resturnResultYingshi(result);
}
@ApiOperation(value = "获取单个子账户信息")
@GetMapping("getChildAccount")
public String getChildAccount(@RequestParam String accountId, @RequestParam String accountName) {
String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/get";
Map<String, Object> map = new HashMap<>();
//子账户密码,LowerCase(MD5(AppKey#密码明文))
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("accountId", accountId);
map.put("accountName", accountName);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
return result;
}
@ApiOperation(value = "获取子账号信息列表")
@GetMapping("getChildAccountList")
public String getChildAccountList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSize) {
String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/list";
Map<String, Object> map = new HashMap<>();
//子账户密码,LowerCase(MD5(AppKey#密码明文))
map.put("accessToken", YinShiServiceConfig.AccessToken);
map.put("pageStart", pageIndex);
map.put("pageSize", pageSize);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
return result;
}
@ApiOperation(value = "修改当前子账户密码")
@GetMapping("updateChildPassword")
public String 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<>();
//子账户密码,LowerCase(MD5(AppKey#密码明文))
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);
return result;
}
@ApiOperation(value = "删除指定子账户")
@GetMapping("deleteChildAccount")
public String 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);
return result;
}
@ApiOperation(value = "设置子账户的授权策略")
@GetMapping("policySet")
public String 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);
return result;
}
@ApiOperation(value = "增加子账户授权策略中的授权语句")
@GetMapping("policyAdd")
public String 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);
return result;
}
@ApiOperation(value = "删除子账户授权策略中指定设备的所有授权语句")
@GetMapping("policyDelete")
public String 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);
return result;
}
@ApiOperation(value = "获取B模式子账户accessToken")
@GetMapping("getChildAccountToken")
public String getChildAccountToken(@RequestParam String accountId) {
String url = YinShiServiceConfig.HostUrl + "lapp/ram/token/get";
Map<String, Object> map1 = new HashMap<>();
map1.put("accessToken", YinShiServiceConfig.AccessToken);
map1.put("accountId", accountId);
String result = ApiHelper.doPost(url, new HashMap<String, String>(), map1);
return result;
}
}