Commit efe2cf9e22cd42946781bf4e90583adc0d8adb3c
Exists in
master
Merge branch 'master' of http://git.shunzhi.net/taohd/javassm
# Conflicts: # springboot/src/main/java/com/sincre/springboot/controller/YinShiController.java # springboot/src/main/java/com/sincre/springboot/utils/CacheHelper.java
Showing
12 changed files
with
288 additions
and
88 deletions
Show diff stats
springboot/pom.xml
... | ... | @@ -77,11 +77,17 @@ |
77 | 77 | <version>2.0.0</version> |
78 | 78 | </dependency> |
79 | 79 | |
80 | + <dependency> | |
81 | + <groupId>org.json</groupId> | |
82 | + <artifactId>json</artifactId> | |
83 | + <version>20180813</version> | |
84 | + </dependency> | |
85 | + | |
80 | 86 | <!--常用工具的使用--> |
81 | 87 | <dependency> |
82 | 88 | <groupId>org.apache.commons</groupId> |
83 | 89 | <artifactId>commons-lang3</artifactId> |
84 | - <version>3.9</version> | |
90 | + <scope>runtime</scope> | |
85 | 91 | </dependency> |
86 | 92 | <!--模拟http请求包--> |
87 | 93 | <dependency> | ... | ... |
springboot/src/main/java/com/sincre/springboot/ApiPlatform/YinShiServiceConfig.java
... | ... | @@ -4,6 +4,15 @@ public class YinShiServiceConfig { |
4 | 4 | |
5 | 5 | public final static String HostUrl = "https://open.ys7.com/api/"; |
6 | 6 | |
7 | + public final static String accessToken = "accessToken"; | |
8 | + | |
9 | + /** | |
10 | + * 萤石云appKey和appSecret | |
11 | + */ | |
7 | 12 | public static String appKey = "3780bdecb44c4b608367ba469d6d52ea"; |
8 | - public static String appSecret = "b6399d42a10215242c3d72944abdc8a2"; | |
13 | + public static String appSecret = "35c83d24b5a39b171572f6eae4ded9a7"; | |
14 | + public static String AccessToken = ""; | |
15 | + | |
16 | + | |
17 | + | |
9 | 18 | } | ... | ... |
springboot/src/main/java/com/sincre/springboot/SpringbootApplication.java
1 | 1 | package com.sincre.springboot; |
2 | 2 | |
3 | +import com.sincre.springboot.controller.YinShiController; | |
3 | 4 | import org.apache.ibatis.annotations.Mapper; |
4 | 5 | import org.mybatis.spring.annotation.MapperScan; |
5 | 6 | import org.springframework.boot.SpringApplication; |
... | ... | @@ -9,6 +10,8 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer |
9 | 10 | |
10 | 11 | import javax.swing.*; |
11 | 12 | import java.awt.*; |
13 | +import java.text.SimpleDateFormat; | |
14 | +import java.util.Date; | |
12 | 15 | |
13 | 16 | @MapperScan("com.sincre.springboot.mapper") |
14 | 17 | @SpringBootApplication |
... | ... | @@ -17,6 +20,7 @@ public class SpringbootApplication extends SpringBootServletInitializer { |
17 | 20 | public static void main(String[] args) { |
18 | 21 | |
19 | 22 | SpringApplication.run(SpringbootApplication.class, args); |
23 | + new YinShiController().GetYinShiToken();//获取萤石云token | |
20 | 24 | } |
21 | 25 | |
22 | 26 | } | ... | ... |
springboot/src/main/java/com/sincre/springboot/controller/TuYaYunController.java
... | ... | @@ -9,6 +9,7 @@ import com.sincre.springboot.ApiModel.UserInfo; |
9 | 9 | import com.sincre.springboot.ApiPlatform.TuYaCloudService; |
10 | 10 | import com.sincre.springboot.utils.ApiHelper; |
11 | 11 | import com.sincre.springboot.utils.CacheHelper; |
12 | +import com.sincre.springboot.utils.ResultUtils; | |
12 | 13 | import io.swagger.annotations.Api; |
13 | 14 | import org.springframework.web.bind.annotation.*; |
14 | 15 | |
... | ... | @@ -43,7 +44,6 @@ public class TuYaYunController { |
43 | 44 | } catch(Exception ex){ |
44 | 45 | System.out.println(ex.getMessage()); |
45 | 46 | } |
46 | - | |
47 | 47 | System.out.println(result); |
48 | 48 | return resResult; |
49 | 49 | } | ... | ... |
springboot/src/main/java/com/sincre/springboot/controller/YinShiController.java
1 | 1 | package com.sincre.springboot.controller; |
2 | 2 | |
3 | 3 | |
4 | +import com.alibaba.fastjson.JSON; | |
4 | 5 | import com.sincre.springboot.common.MD5; |
5 | 6 | import com.sincre.springboot.utils.ApiHelper; |
6 | 7 | import com.sincre.springboot.utils.CacheHelper; |
8 | +import com.sincre.springboot.utils.ResultUtils; | |
7 | 9 | import io.swagger.annotations.Api; |
8 | 10 | import io.swagger.annotations.ApiOperation; |
11 | +import org.json.JSONObject; | |
9 | 12 | import org.springframework.web.bind.annotation.GetMapping; |
10 | 13 | import org.springframework.web.bind.annotation.RequestMapping; |
11 | 14 | import org.springframework.web.bind.annotation.RequestParam; |
12 | 15 | import org.springframework.web.bind.annotation.RestController; |
13 | 16 | |
17 | +import java.util.Date; | |
14 | 18 | import java.util.HashMap; |
15 | 19 | import java.util.Map; |
16 | 20 | |
... | ... | @@ -18,160 +22,182 @@ import com.sincre.springboot.ApiPlatform.YinShiServiceConfig; |
18 | 22 | |
19 | 23 | @RestController |
20 | 24 | @RequestMapping("/YinShi") |
21 | -@Api(value = "YinShiController",tags = "萤石对接接口") | |
25 | +@Api(value = "YinShiController", tags = "萤石对接接口") | |
22 | 26 | public class YinShiController { |
23 | 27 | |
24 | 28 | private static String AccessToken = "at.2scte32926nu6q7j6adhlabg28emicz6-58f6w0596w-1ppubtz-uxh6dnv5x"; |
25 | 29 | |
30 | + @ApiOperation(value = "用于管理员获取accessToken") | |
31 | + @GetMapping("/token") | |
32 | + public String GetYinShiToken() { | |
33 | + String appKey = YinShiServiceConfig.appKey; | |
34 | + String appSecret = YinShiServiceConfig.appSecret; | |
35 | + | |
36 | + String url = YinShiServiceConfig.HostUrl + "lapp/token/get"; | |
37 | + Map<String, Object> map = new HashMap<>(); | |
38 | + | |
39 | + map.put("appKey", appKey); | |
40 | + map.put("appSecret", appSecret); | |
41 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
42 | + JSONObject jsonObject = new JSONObject(result); | |
43 | + JSONObject data = jsonObject.optJSONObject("data"); | |
44 | + YinShiServiceConfig.AccessToken = data.optString("accessToken"); | |
45 | + Date date = new Date(); | |
46 | + Date dateFu = new Date(data.optLong("expireTime")); | |
47 | + CacheHelper.putYingshiYunToken(YinShiServiceConfig.AccessToken, (int) ((dateFu.getTime()-date.getTime())/1000)); | |
48 | + return ResultUtils.getInstance().resturnResultYingshi(result); | |
49 | + } | |
50 | + | |
26 | 51 | @ApiOperation(value = "增加子账号") |
27 | 52 | @GetMapping("/addChildAccount") |
28 | - public String addChildAccount(@RequestParam String accountName, @RequestParam String password){ | |
53 | + public String addChildAccount(@RequestParam String accountName, @RequestParam String password) { | |
29 | 54 | |
30 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/create"; | |
31 | - Map<String,Object> map = new HashMap<>(); | |
55 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/create"; | |
56 | + Map<String, Object> map = new HashMap<>(); | |
32 | 57 | //子账户密码,LowerCase(MD5(AppKey#密码明文)) |
33 | - password = YinShiServiceConfig.appKey+"#"+password; | |
58 | + password = YinShiServiceConfig.appKey + "#" + password; | |
34 | 59 | try { |
35 | 60 | password = MD5.md5(password, "").toLowerCase(); |
36 | - }catch (Exception ex){ | |
61 | + } catch (Exception ex) { | |
37 | 62 | ex.getStackTrace(); |
38 | 63 | } |
39 | - map.put("accessToken",AccessToken); | |
40 | - map.put("accountName",accountName); | |
41 | - map.put("password",password); | |
42 | - String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
43 | - | |
44 | - return result; | |
64 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
65 | + map.put("accountName", accountName); | |
66 | + map.put("password", password); | |
67 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
68 | + return ResultUtils.getInstance().resturnResultYingshi(result); | |
45 | 69 | } |
46 | 70 | |
47 | 71 | @ApiOperation(value = "获取单个子账户信息") |
48 | 72 | @GetMapping("getChildAccount") |
49 | - public String getChildAccount(@RequestParam String accountId,@RequestParam String accountName){ | |
73 | + public String getChildAccount(@RequestParam String accountId, @RequestParam String accountName) { | |
50 | 74 | |
51 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/get"; | |
52 | - Map<String,Object> map = new HashMap<>(); | |
75 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/get"; | |
76 | + Map<String, Object> map = new HashMap<>(); | |
53 | 77 | //子账户密码,LowerCase(MD5(AppKey#密码明文)) |
78 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
79 | + map.put("accountId", accountId); | |
80 | + map.put("accountName", accountName); | |
81 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
54 | 82 | |
55 | - map.put("accessToken",AccessToken); | |
56 | - map.put("accountId",accountId); | |
57 | - map.put("accountName",accountName); | |
58 | - String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
59 | - | |
60 | - return result; | |
83 | + return result; | |
61 | 84 | } |
62 | 85 | |
63 | 86 | @ApiOperation(value = "获取子账号信息列表") |
64 | 87 | @GetMapping("getChildAccountList") |
65 | - public String getChildAccountList(@RequestParam("pageIndex") Integer pageIndex,@RequestParam("pageSize") Integer pageSize){ | |
88 | + public String getChildAccountList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSize) { | |
66 | 89 | |
67 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/list"; | |
68 | - Map<String,Object> map = new HashMap<>(); | |
90 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/list"; | |
91 | + Map<String, Object> map = new HashMap<>(); | |
69 | 92 | //子账户密码,LowerCase(MD5(AppKey#密码明文)) |
70 | 93 | |
71 | - map.put("accessToken",AccessToken); | |
72 | - map.put("pageStart",pageIndex); | |
73 | - map.put("pageSize",pageSize); | |
74 | - String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
94 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
95 | + map.put("pageStart", pageIndex); | |
96 | + map.put("pageSize", pageSize); | |
97 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
75 | 98 | |
76 | - return result; | |
99 | + return result; | |
77 | 100 | } |
78 | 101 | |
79 | 102 | @ApiOperation(value = "修改当前子账户密码") |
80 | 103 | @GetMapping("updateChildPassword") |
81 | - public String updateChildPassword(@RequestParam("accountId") String accountId,@RequestParam("newPassword") String newPassword,@RequestParam("oldPassword") String oldPassword){ | |
104 | + public String updateChildPassword(@RequestParam("accountId") String accountId, @RequestParam("newPassword") String newPassword, @RequestParam("oldPassword") String oldPassword) { | |
82 | 105 | |
83 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/updatePassword"; | |
84 | - Map<String,Object> map = new HashMap<>(); | |
106 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/updatePassword"; | |
107 | + Map<String, Object> map = new HashMap<>(); | |
85 | 108 | //子账户密码,LowerCase(MD5(AppKey#密码明文)) |
86 | 109 | |
87 | - oldPassword = YinShiServiceConfig.appKey+"#"+oldPassword; | |
88 | - newPassword = YinShiServiceConfig.appKey+"#"+newPassword; | |
110 | + oldPassword = YinShiServiceConfig.appKey + "#" + oldPassword; | |
111 | + newPassword = YinShiServiceConfig.appKey + "#" + newPassword; | |
89 | 112 | try { |
90 | 113 | oldPassword = MD5.md5(oldPassword, "").toLowerCase(); |
91 | 114 | newPassword = MD5.md5(newPassword, "").toLowerCase(); |
92 | - }catch (Exception ex){ | |
115 | + } catch (Exception ex) { | |
93 | 116 | ex.getStackTrace(); |
94 | 117 | } |
95 | - map.put("accessToken",AccessToken); | |
96 | - map.put("accountId",accountId); | |
97 | - map.put("oldPassword",oldPassword); | |
98 | - map.put("newPassword",newPassword); | |
99 | - String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
118 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
119 | + map.put("accountId", accountId); | |
120 | + map.put("oldPassword", oldPassword); | |
121 | + map.put("newPassword", newPassword); | |
122 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
100 | 123 | |
101 | - return result; | |
124 | + return result; | |
102 | 125 | } |
103 | 126 | |
104 | 127 | @ApiOperation(value = "删除指定子账户") |
105 | 128 | @GetMapping("deleteChildAccount") |
106 | - public String deleteChildAccount(@RequestParam String accountId){ | |
129 | + public String deleteChildAccount(@RequestParam String accountId) { | |
107 | 130 | |
108 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/delete"; | |
109 | - Map<String,Object> map = new HashMap<>(); | |
131 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/delete"; | |
132 | + Map<String, Object> map = new HashMap<>(); | |
110 | 133 | |
111 | - map.put("accessToken",AccessToken); | |
112 | - map.put("accountId",accountId); | |
113 | - String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
134 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
135 | + map.put("accountId", accountId); | |
136 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
114 | 137 | |
115 | - return result; | |
138 | + return result; | |
116 | 139 | } |
117 | 140 | |
118 | 141 | |
119 | 142 | @ApiOperation(value = "设置子账户的授权策略") |
120 | 143 | @GetMapping("policySet") |
121 | - public String policySet(@RequestParam String accountId,@RequestParam String policy){ | |
144 | + public String policySet(@RequestParam String accountId, @RequestParam String policy) { | |
122 | 145 | |
123 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/policy/set"; | |
124 | - Map<String,Object> map = new HashMap<>(); | |
146 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/policy/set"; | |
147 | + Map<String, Object> map = new HashMap<>(); | |
125 | 148 | |
126 | - map.put("accessToken",AccessToken); | |
127 | - map.put("accountId",accountId); | |
128 | - map.put("policy",policy); | |
129 | - String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
149 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
150 | + map.put("accountId", accountId); | |
151 | + map.put("policy", policy); | |
152 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
130 | 153 | |
131 | - return result; | |
154 | + return result; | |
132 | 155 | } |
133 | 156 | |
134 | 157 | @ApiOperation(value = "增加子账户授权策略中的授权语句") |
135 | 158 | @GetMapping("policyAdd") |
136 | - public String policyAdd(@RequestParam String accountId,@RequestParam String statement){ | |
159 | + public String policyAdd(@RequestParam String accountId, @RequestParam String statement) { | |
137 | 160 | |
138 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/statement/add"; | |
139 | - Map<String,Object> map = new HashMap<>(); | |
161 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/add"; | |
162 | + Map<String, Object> map = new HashMap<>(); | |
140 | 163 | |
141 | - map.put("accessToken",AccessToken); | |
142 | - map.put("accountId",accountId); | |
143 | - map.put("statement",statement); | |
144 | - String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
164 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
165 | + map.put("accountId", accountId); | |
166 | + map.put("statement", statement); | |
167 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
145 | 168 | |
146 | - return result; | |
169 | + return result; | |
147 | 170 | } |
148 | 171 | |
149 | 172 | @ApiOperation(value = "删除子账户授权策略中指定设备的所有授权语句") |
150 | 173 | @GetMapping("policyDelete") |
151 | - public String policyDelete(@RequestParam String accountId,@RequestParam String deviceSerial){ | |
174 | + public String policyDelete(@RequestParam String accountId, @RequestParam String deviceSerial) { | |
152 | 175 | |
153 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/statement/delete"; | |
154 | - Map<String,Object> map = new HashMap<>(); | |
176 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/delete"; | |
177 | + Map<String, Object> map = new HashMap<>(); | |
155 | 178 | |
156 | - map.put("accessToken",AccessToken); | |
157 | - map.put("accountId",accountId); | |
158 | - map.put("deviceSerial",deviceSerial); | |
159 | - String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
179 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
180 | + map.put("accountId", accountId); | |
181 | + map.put("deviceSerial", deviceSerial); | |
182 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
160 | 183 | |
161 | - return result; | |
184 | + return result; | |
162 | 185 | } |
163 | 186 | |
164 | 187 | @ApiOperation(value = "获取B模式子账户accessToken") |
165 | 188 | @GetMapping("getChildAccountToken") |
166 | - public String getChildAccountToken(@RequestParam String accountId){ | |
189 | + public String getChildAccountToken(@RequestParam String accountId) { | |
167 | 190 | |
168 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/token/get"; | |
169 | - Map<String,Object> map = new HashMap<>(); | |
191 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/token/get"; | |
192 | + Map<String, Object> map1 = new HashMap<>(); | |
170 | 193 | |
171 | - map.put("accessToken",AccessToken); | |
172 | - map.put("accountId",accountId); | |
173 | - String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
194 | + map1.put("accessToken", YinShiServiceConfig.AccessToken); | |
195 | + map1.put("accountId", accountId); | |
196 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map1); | |
174 | 197 | |
175 | - return result; | |
198 | + return result; | |
176 | 199 | } |
200 | + | |
201 | + | |
202 | + | |
177 | 203 | } | ... | ... |
springboot/src/main/java/com/sincre/springboot/model/ResultModelObj.java
0 → 100644
... | ... | @@ -0,0 +1,64 @@ |
1 | +package com.sincre.springboot.model; | |
2 | + | |
3 | +/** | |
4 | + * 返回结果对象 | |
5 | + */ | |
6 | +public class ResultModelObj { | |
7 | + | |
8 | + private int total; | |
9 | + | |
10 | + /** | |
11 | + * 错误信息 | |
12 | + */ | |
13 | + private String msg; | |
14 | + | |
15 | + /** | |
16 | + * 错误码 | |
17 | + */ | |
18 | + private long code; | |
19 | + | |
20 | + /** | |
21 | + * 返回结果 | |
22 | + */ | |
23 | + private String data; | |
24 | + | |
25 | + public int getTotal() { | |
26 | + return total; | |
27 | + } | |
28 | + | |
29 | + public void setTotal(int total) { | |
30 | + this.total = total; | |
31 | + } | |
32 | + | |
33 | + public String getMsg() { | |
34 | + return msg; | |
35 | + } | |
36 | + | |
37 | + public void setMsg(String msg) { | |
38 | + this.msg = msg; | |
39 | + } | |
40 | + | |
41 | + public long getCode() { | |
42 | + return code; | |
43 | + } | |
44 | + | |
45 | + public void setCode(long code) { | |
46 | + this.code = code; | |
47 | + } | |
48 | + | |
49 | + public String getData() { | |
50 | + return data; | |
51 | + } | |
52 | + | |
53 | + public void setData(String data) { | |
54 | + this.data = data; | |
55 | + } | |
56 | + | |
57 | + @Override | |
58 | + public String toString() { | |
59 | + return "{\"msg\":" + msg + | |
60 | + ", \"code\":" + code + | |
61 | + ", \"data\":" + data + | |
62 | + ",\"total\":"+total+"}"; | |
63 | + } | |
64 | +} | ... | ... |
springboot/src/main/java/com/sincre/springboot/utils/CacheHelper.java
... | ... | @@ -4,7 +4,6 @@ import com.fasterxml.jackson.core.type.TypeReference; |
4 | 4 | import com.fasterxml.jackson.databind.ObjectMapper; |
5 | 5 | import com.sincre.springboot.ApiModel.TuYaResResult; |
6 | 6 | import com.sincre.springboot.ApiModel.TuYaResTokenObj; |
7 | -import com.sincre.springboot.ApiModel.YinShiResResult; | |
8 | 7 | import com.sincre.springboot.ApiPlatform.TuYaCloudService; |
9 | 8 | import com.sincre.springboot.ApiPlatform.YinShiServiceConfig; |
10 | 9 | import com.sincre.springboot.common.EhcacheUtil; |
... | ... | @@ -95,4 +94,20 @@ public class CacheHelper { |
95 | 94 | } |
96 | 95 | } |
97 | 96 | |
97 | + /** | |
98 | + * 获取萤石云token | |
99 | + * @return | |
100 | + */ | |
101 | + public static String getYingshiYunToken(){ | |
102 | + return ehcacheUtil.get(YinShiServiceConfig.accessToken); | |
103 | + } | |
104 | + | |
105 | + /** | |
106 | + * 设置萤石云token | |
107 | + * @param token | |
108 | + * @param time | |
109 | + */ | |
110 | + public static void putYingshiYunToken(String token,int time){ | |
111 | + ehcacheUtil.setex(YinShiServiceConfig.accessToken,token,time); | |
112 | + } | |
98 | 113 | } | ... | ... |
springboot/src/main/java/com/sincre/springboot/utils/ResultUtils.java
0 → 100644
... | ... | @@ -0,0 +1,80 @@ |
1 | +package com.sincre.springboot.utils; | |
2 | + | |
3 | + | |
4 | +import com.sincre.springboot.controller.YinShiController; | |
5 | +import com.sincre.springboot.model.ResultModelObj; | |
6 | +import org.json.JSONObject; | |
7 | +import org.springframework.http.codec.json.Jackson2JsonDecoder; | |
8 | + | |
9 | +/** | |
10 | + * 结果返回工具类 | |
11 | + * 成功的code统一为 200,其他的根据接口返回的code返回给客户端 | |
12 | + */ | |
13 | +public class ResultUtils { | |
14 | + | |
15 | + private static ResultUtils resultUtils; | |
16 | + | |
17 | + public ResultUtils() { | |
18 | + | |
19 | + } | |
20 | + | |
21 | + public static ResultUtils getInstance() { | |
22 | + if (null == resultUtils) { | |
23 | + synchronized (ResultUtils.class) { | |
24 | + if (null == resultUtils) resultUtils = new ResultUtils(); | |
25 | + } | |
26 | + } | |
27 | + return resultUtils; | |
28 | + } | |
29 | + | |
30 | + | |
31 | + /** | |
32 | + * 萤石统一结果回调 | |
33 | + * @param result data为对象的字符串 | |
34 | + * @return 返回的data可以是对象或者集合,都以字符串形式返回 | |
35 | + */ | |
36 | + public String resturnResultYingshi(String result) { | |
37 | + JSONObject jsonObject = new JSONObject(result); | |
38 | + ResultModelObj resultModelObj = new ResultModelObj(); | |
39 | + long code = jsonObject.optLong("code"); | |
40 | + if (code==10002){//accesstoken过期 | |
41 | + new YinShiController().GetYinShiToken(); | |
42 | + try { | |
43 | + Thread.sleep(1000); | |
44 | + } catch (InterruptedException e) { | |
45 | + e.printStackTrace(); | |
46 | + } | |
47 | + } | |
48 | + resultModelObj.setCode(code); | |
49 | + resultModelObj.setData(jsonObject.optString("data")); | |
50 | + resultModelObj.setMsg(jsonObject.optString("msg")); | |
51 | + resultModelObj.setTotal(jsonObject.optInt("page")); | |
52 | + return resultModelObj.toString(); | |
53 | + } | |
54 | + | |
55 | + private void getYinShiToken(){ | |
56 | + | |
57 | + } | |
58 | + | |
59 | + /** | |
60 | + * 涂鸦云返回结果 | |
61 | + * @param result | |
62 | + * @return | |
63 | + */ | |
64 | + public String resturnResultTuya(String result) { | |
65 | + JSONObject jsonObject = new JSONObject(result); | |
66 | + boolean success = jsonObject.optBoolean("success"); | |
67 | + ResultModelObj resultModelObj = new ResultModelObj(); | |
68 | + if (success){//成功 | |
69 | + resultModelObj.setCode(200); | |
70 | + resultModelObj.setData(jsonObject.optString("result")); | |
71 | + resultModelObj.setMsg(jsonObject.optString("msg")); | |
72 | + }else {//失败 | |
73 | + resultModelObj.setCode(jsonObject.optLong("code")); | |
74 | + resultModelObj.setData("{}"); | |
75 | + resultModelObj.setMsg(jsonObject.optString("msg")); | |
76 | + } | |
77 | + return resultModelObj.toString(); | |
78 | + } | |
79 | + | |
80 | +} | ... | ... |
springboot/src/main/resources/mybatis-config.xml
springboot/src/main/webapp/WEB-INF/jsp/index.jsp
springboot/src/main/webapp/WEB-INF/lib/sqljdbc42.jar
No preview for this file type
springboot/src/main/webapp/WEB-INF/web.xml