Commit b00de0ddcaf67aef8739de28e106bffb80d14430
1 parent
df849458
Exists in
master
'螢石用戶組和權限接口'
Showing
9 changed files
with
328 additions
and
11 deletions
Show diff stats
... | ... | @@ -0,0 +1,9 @@ |
1 | +Stack trace: | |
2 | +Frame Function Args | |
3 | +000FFFFA1A8 0018007164E (0018026F12D, 00180224DC6, 000FFFFA1A8, 000FFFF90A0) | |
4 | +000FFFFA1A8 00180046669 (00000000000, 00000000000, 00000000000, 000FFFFFFFF) | |
5 | +000FFFFA1A8 001800466A2 (0018026F1E9, 000FFFFA058, 000FFFFA1A8, 00000000000) | |
6 | +000FFFFA1A8 001800BDFEF (00000000000, 00000000000, 00000000000, 00000000000) | |
7 | +000FFFFA1A8 001800BE20F (000FFFFA1D0, 00000000000, 00000000000, 00000000000) | |
8 | +000FFFFA250 001800BF4AD (000FFFFA1D0, 00000000000, 00000000000, 00000000000) | |
9 | +End of stack trace | ... | ... |
springboot/pom.xml
... | ... | @@ -77,6 +77,12 @@ |
77 | 77 | <version>2.0.0</version> |
78 | 78 | </dependency> |
79 | 79 | |
80 | + <!--常用工具的使用--> | |
81 | + <dependency> | |
82 | + <groupId>org.apache.commons</groupId> | |
83 | + <artifactId>commons-lang3</artifactId> | |
84 | + <version>3.9</version> | |
85 | + </dependency> | |
80 | 86 | <!--模拟http请求包--> |
81 | 87 | <dependency> |
82 | 88 | <groupId>org.apache.httpcomponents</groupId> | ... | ... |
springboot/src/main/java/com/sincre/springboot/ApiModel/YinShiResResult.java
0 → 100644
... | ... | @@ -0,0 +1,61 @@ |
1 | +package com.sincre.springboot.ApiModel; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonInclude; | |
4 | + | |
5 | +@JsonInclude(JsonInclude.Include.NON_EMPTY) | |
6 | +public class YinShiResResult { | |
7 | + | |
8 | + private YinShiToken data; | |
9 | + | |
10 | + public YinShiToken getData() { | |
11 | + return data; | |
12 | + } | |
13 | + | |
14 | + public void setData(YinShiToken data) { | |
15 | + this.data = data; | |
16 | + } | |
17 | + | |
18 | + public String getCode() { | |
19 | + return code; | |
20 | + } | |
21 | + | |
22 | + public void setCode(String code) { | |
23 | + this.code = code; | |
24 | + } | |
25 | + | |
26 | + public String getMsg() { | |
27 | + return msg; | |
28 | + } | |
29 | + | |
30 | + public void setMsg(String msg) { | |
31 | + this.msg = msg; | |
32 | + } | |
33 | + | |
34 | + private String code; | |
35 | + private String msg; | |
36 | +} | |
37 | + | |
38 | +class YinShiToken{ | |
39 | + | |
40 | + private String accessToken; | |
41 | + | |
42 | + private Long expireTime; | |
43 | + | |
44 | + public String getAccessToken() { | |
45 | + return accessToken; | |
46 | + } | |
47 | + | |
48 | + public void setAccessToken(String accessToken) { | |
49 | + this.accessToken = accessToken; | |
50 | + } | |
51 | + | |
52 | + public Long getExpireTime() { | |
53 | + return expireTime; | |
54 | + } | |
55 | + | |
56 | + public void setExpireTime(Long expireTime) { | |
57 | + this.expireTime = expireTime; | |
58 | + } | |
59 | + | |
60 | + | |
61 | +} | ... | ... |
springboot/src/main/java/com/sincre/springboot/ApiPlatform/YinShiServiceConfig.java
0 → 100644
... | ... | @@ -0,0 +1,9 @@ |
1 | +package com.sincre.springboot.ApiPlatform; | |
2 | + | |
3 | +public class YinShiServiceConfig { | |
4 | + | |
5 | + public final static String HostUrl = "https://open.ys7.com/api/"; | |
6 | + | |
7 | + public static String appKey = "3780bdecb44c4b608367ba469d6d52ea"; | |
8 | + public static String appSecret = "b6399d42a10215242c3d72944abdc8a2"; | |
9 | +} | ... | ... |
springboot/src/main/java/com/sincre/springboot/common/MD5.java
0 → 100644
... | ... | @@ -0,0 +1,42 @@ |
1 | +package com.sincre.springboot.common; | |
2 | + | |
3 | +import org.apache.commons.codec.digest.DigestUtils; | |
4 | + | |
5 | +public class MD5 { | |
6 | + | |
7 | + /** | |
8 | + * MD5方法 | |
9 | + * | |
10 | + * @param text 明文 | |
11 | + * @param key 密钥 | |
12 | + * @return 密文 | |
13 | + * @throws Exception | |
14 | + */ | |
15 | + public static String md5(String text, String key) throws Exception { | |
16 | + //加密后的字符串 | |
17 | + String encodeStr= DigestUtils.md5Hex(text + key); | |
18 | + System.out.println("MD5加密后的字符串为:encodeStr="+encodeStr); | |
19 | + return encodeStr; | |
20 | + } | |
21 | + | |
22 | + /** | |
23 | + * MD5验证方法 | |
24 | + * | |
25 | + * @param text 明文 | |
26 | + * @param key 密钥 | |
27 | + * @param md5 密文 | |
28 | + * @return true/false | |
29 | + * @throws Exception | |
30 | + */ | |
31 | + public static boolean verify(String text, String key, String md5) throws Exception { | |
32 | + //根据传入的密钥进行验证 | |
33 | + String md5Text = md5(text, key); | |
34 | + if(md5Text.equalsIgnoreCase(md5)) | |
35 | + { | |
36 | + System.out.println("MD5验证通过"); | |
37 | + return true; | |
38 | + } | |
39 | + | |
40 | + return false; | |
41 | + } | |
42 | +} | ... | ... |
springboot/src/main/java/com/sincre/springboot/controller/TuYaYunController.java
springboot/src/main/java/com/sincre/springboot/controller/YinShiController.java
0 → 100644
... | ... | @@ -0,0 +1,191 @@ |
1 | +package com.sincre.springboot.controller; | |
2 | + | |
3 | + | |
4 | +import com.sincre.springboot.common.MD5; | |
5 | +import com.sincre.springboot.utils.ApiHelper; | |
6 | +import io.swagger.annotations.Api; | |
7 | +import io.swagger.annotations.ApiOperation; | |
8 | +import org.springframework.web.bind.annotation.GetMapping; | |
9 | +import org.springframework.web.bind.annotation.RequestMapping; | |
10 | +import org.springframework.web.bind.annotation.RequestParam; | |
11 | +import org.springframework.web.bind.annotation.RestController; | |
12 | + | |
13 | +import java.util.HashMap; | |
14 | +import java.util.Map; | |
15 | + | |
16 | +import com.sincre.springboot.ApiPlatform.YinShiServiceConfig; | |
17 | + | |
18 | +@RestController | |
19 | +@RequestMapping("/YinShi") | |
20 | +@Api(value = "YinShiController",tags = "萤石对接接口") | |
21 | +public class YinShiController { | |
22 | + | |
23 | + private static String AccessToken = "at.2scte32926nu6q7j6adhlabg28emicz6-58f6w0596w-1ppubtz-uxh6dnv5x"; | |
24 | + @ApiOperation(value = "用于管理员获取accessToken") | |
25 | + @GetMapping("/token") | |
26 | + public String GetYinShiToken(){ | |
27 | + String appKey = YinShiServiceConfig.appKey; | |
28 | + String appSecret = YinShiServiceConfig.appSecret; | |
29 | + | |
30 | + String url = YinShiServiceConfig.HostUrl + "lapp/token/get"; | |
31 | + Map<String,Object> map = new HashMap<>(); | |
32 | + | |
33 | + map.put("appKey",appKey); | |
34 | + map.put("appSecret",appSecret); | |
35 | + String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
36 | + | |
37 | + return result; | |
38 | + } | |
39 | + | |
40 | + @ApiOperation(value = "增加子账号") | |
41 | + @GetMapping("/addChildAccount") | |
42 | + public String addChildAccount(@RequestParam String accountName, @RequestParam String password){ | |
43 | + | |
44 | + String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/create"; | |
45 | + Map<String,Object> map = new HashMap<>(); | |
46 | + //子账户密码,LowerCase(MD5(AppKey#密码明文)) | |
47 | + password = YinShiServiceConfig.appKey+"#"+password; | |
48 | + try { | |
49 | + password = MD5.md5(password, "").toLowerCase(); | |
50 | + }catch (Exception ex){ | |
51 | + ex.getStackTrace(); | |
52 | + } | |
53 | + map.put("accessToken",AccessToken); | |
54 | + map.put("accountName",accountName); | |
55 | + map.put("password",password); | |
56 | + String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
57 | + | |
58 | + return result; | |
59 | + } | |
60 | + | |
61 | + @ApiOperation(value = "获取单个子账户信息") | |
62 | + @GetMapping("getChildAccount") | |
63 | + public String getChildAccount(@RequestParam String accountId,@RequestParam String accountName){ | |
64 | + | |
65 | + String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/get"; | |
66 | + Map<String,Object> map = new HashMap<>(); | |
67 | + //子账户密码,LowerCase(MD5(AppKey#密码明文)) | |
68 | + | |
69 | + map.put("accessToken",AccessToken); | |
70 | + map.put("accountId",accountId); | |
71 | + map.put("accountName",accountName); | |
72 | + String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
73 | + | |
74 | + return result; | |
75 | + } | |
76 | + | |
77 | + @ApiOperation(value = "获取子账号信息列表") | |
78 | + @GetMapping("getChildAccountList") | |
79 | + public String getChildAccountList(@RequestParam("pageIndex") Integer pageIndex,@RequestParam("pageSize") Integer pageSize){ | |
80 | + | |
81 | + String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/list"; | |
82 | + Map<String,Object> map = new HashMap<>(); | |
83 | + //子账户密码,LowerCase(MD5(AppKey#密码明文)) | |
84 | + | |
85 | + map.put("accessToken",AccessToken); | |
86 | + map.put("pageStart",pageIndex); | |
87 | + map.put("pageSize",pageSize); | |
88 | + String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
89 | + | |
90 | + return result; | |
91 | + } | |
92 | + | |
93 | + @ApiOperation(value = "修改当前子账户密码") | |
94 | + @GetMapping("updateChildPassword") | |
95 | + public String updateChildPassword(@RequestParam("accountId") String accountId,@RequestParam("newPassword") String newPassword,@RequestParam("oldPassword") String oldPassword){ | |
96 | + | |
97 | + String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/updatePassword"; | |
98 | + Map<String,Object> map = new HashMap<>(); | |
99 | + //子账户密码,LowerCase(MD5(AppKey#密码明文)) | |
100 | + | |
101 | + oldPassword = YinShiServiceConfig.appKey+"#"+oldPassword; | |
102 | + newPassword = YinShiServiceConfig.appKey+"#"+newPassword; | |
103 | + try { | |
104 | + oldPassword = MD5.md5(oldPassword, "").toLowerCase(); | |
105 | + newPassword = MD5.md5(newPassword, "").toLowerCase(); | |
106 | + }catch (Exception ex){ | |
107 | + ex.getStackTrace(); | |
108 | + } | |
109 | + map.put("accessToken",AccessToken); | |
110 | + map.put("accountId",accountId); | |
111 | + map.put("oldPassword",oldPassword); | |
112 | + map.put("newPassword",newPassword); | |
113 | + String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
114 | + | |
115 | + return result; | |
116 | + } | |
117 | + | |
118 | + @ApiOperation(value = "删除指定子账户") | |
119 | + @GetMapping("deleteChildAccount") | |
120 | + public String deleteChildAccount(@RequestParam String accountId){ | |
121 | + | |
122 | + String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/delete"; | |
123 | + Map<String,Object> map = new HashMap<>(); | |
124 | + | |
125 | + map.put("accessToken",AccessToken); | |
126 | + map.put("accountId",accountId); | |
127 | + String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
128 | + | |
129 | + return result; | |
130 | + } | |
131 | + | |
132 | + | |
133 | + @ApiOperation(value = "设置子账户的授权策略") | |
134 | + @GetMapping("policySet") | |
135 | + public String policySet(@RequestParam String accountId,@RequestParam String policy){ | |
136 | + | |
137 | + String url =YinShiServiceConfig.HostUrl + "lapp/ram/policy/set"; | |
138 | + Map<String,Object> map = new HashMap<>(); | |
139 | + | |
140 | + map.put("accessToken",AccessToken); | |
141 | + map.put("accountId",accountId); | |
142 | + map.put("policy",policy); | |
143 | + String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
144 | + | |
145 | + return result; | |
146 | + } | |
147 | + | |
148 | + @ApiOperation(value = "增加子账户授权策略中的授权语句") | |
149 | + @GetMapping("policyAdd") | |
150 | + public String policyAdd(@RequestParam String accountId,@RequestParam String statement){ | |
151 | + | |
152 | + String url =YinShiServiceConfig.HostUrl + "lapp/ram/statement/add"; | |
153 | + Map<String,Object> map = new HashMap<>(); | |
154 | + | |
155 | + map.put("accessToken",AccessToken); | |
156 | + map.put("accountId",accountId); | |
157 | + map.put("statement",statement); | |
158 | + String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
159 | + | |
160 | + return result; | |
161 | + } | |
162 | + | |
163 | + @ApiOperation(value = "删除子账户授权策略中指定设备的所有授权语句") | |
164 | + @GetMapping("policyDelete") | |
165 | + public String policyDelete(@RequestParam String accountId,@RequestParam String deviceSerial){ | |
166 | + | |
167 | + String url =YinShiServiceConfig.HostUrl + "lapp/ram/statement/delete"; | |
168 | + Map<String,Object> map = new HashMap<>(); | |
169 | + | |
170 | + map.put("accessToken",AccessToken); | |
171 | + map.put("accountId",accountId); | |
172 | + map.put("deviceSerial",deviceSerial); | |
173 | + String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
174 | + | |
175 | + return result; | |
176 | + } | |
177 | + | |
178 | + @ApiOperation(value = "获取B模式子账户accessToken") | |
179 | + @GetMapping("getChildAccountToken") | |
180 | + public String getChildAccountToken(@RequestParam String accountId){ | |
181 | + | |
182 | + String url =YinShiServiceConfig.HostUrl + "lapp/ram/token/get"; | |
183 | + Map<String,Object> map = new HashMap<>(); | |
184 | + | |
185 | + map.put("accessToken",AccessToken); | |
186 | + map.put("accountId",accountId); | |
187 | + String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
188 | + | |
189 | + return result; | |
190 | + } | |
191 | +} | ... | ... |
springboot/src/main/java/com/sincre/springboot/utils/ApiHelper.java
... | ... | @@ -74,22 +74,23 @@ public class ApiHelper { |
74 | 74 | |
75 | 75 | /** |
76 | 76 | * 表单格式的post请求 |
77 | - * @param url 接口地址 | |
77 | + * | |
78 | + * @param url 接口地址 | |
78 | 79 | * @param headerParamMap 设置请求头 |
79 | - * @param paramMap 设置请求值 | |
80 | + * @param paramMap 设置请求值,表单格式的请求值 | |
80 | 81 | * @return |
81 | 82 | */ |
82 | - public static String doPost(String url,Map<String, String> headerParamMap, Map<String, Object> paramMap) { | |
83 | - CloseableHttpClient httpClient ; | |
83 | + public static String doPost(String url, Map<String, String> headerParamMap, Map<String, Object> paramMap) { | |
84 | + CloseableHttpClient httpClient; | |
84 | 85 | String result; |
85 | 86 | // 创建httpClient实例 |
86 | 87 | httpClient = HttpClients.createDefault(); |
87 | 88 | // 创建httpPost远程连接实例 |
88 | 89 | HttpPost httpPost = new HttpPost(url); |
89 | 90 | // 设置请求头 |
90 | - httpPost.addHeader("Content-Type", "application/json"); | |
91 | + httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded"); | |
91 | 92 | for (Map.Entry<String, String> entry : headerParamMap.entrySet()) { |
92 | - httpPost.setHeader(entry.getKey(),entry.getValue()); | |
93 | + httpPost.setHeader(entry.getKey(), entry.getValue()); | |
93 | 94 | } |
94 | 95 | // 配置请求参数实例 |
95 | 96 | RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 设置连接主机服务超时时间 |
... | ... | @@ -114,16 +115,14 @@ public class ApiHelper { |
114 | 115 | // 为httpPost设置封装好的请求参数 |
115 | 116 | try { |
116 | 117 | UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nvps, "UTF-8"); |
117 | - entity.setContentType("application/json"); | |
118 | 118 | httpPost.setEntity(entity); |
119 | 119 | } catch (UnsupportedEncodingException e) { |
120 | 120 | e.printStackTrace(); |
121 | 121 | } |
122 | 122 | } |
123 | - result = closeHttpAndResult(httpClient,httpPost); | |
123 | + result = closeHttpAndResult(httpClient, httpPost); | |
124 | 124 | return result; |
125 | 125 | } |
126 | - | |
127 | 126 | /** |
128 | 127 | * post请求,内容体比较灵活,任意字符串格式的内容 |
129 | 128 | * @param url | ... | ... |
springboot/src/main/java/com/sincre/springboot/utils/CacheHelper.java
... | ... | @@ -28,7 +28,7 @@ public class CacheHelper { |
28 | 28 | map.put("sign_method",TuYaCloudService.Sign_method); |
29 | 29 | map.put("t",t.toString()); |
30 | 30 | String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); |
31 | - | |
31 | + System.out.println(result); | |
32 | 32 | TuYaResResult<TuYaResTokenObj> resResult ; |
33 | 33 | try{ |
34 | 34 | ObjectMapper objectMapper = new ObjectMapper(); | ... | ... |