Commit ca53be24eeaef8cb38bdd7d260478b6af52fdb05
1 parent
b00de0dd
Exists in
master
no message
Showing
12 changed files
with
286 additions
and
96 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; | 
| 7 | +import com.sincre.springboot.utils.CacheHelper; | |
| 8 | +import com.sincre.springboot.utils.ResultUtils; | |
| 6 | 9 | import io.swagger.annotations.Api; | 
| 7 | 10 | import io.swagger.annotations.ApiOperation; | 
| 11 | +import org.json.JSONObject; | |
| 8 | 12 | import org.springframework.web.bind.annotation.GetMapping; | 
| 9 | 13 | import org.springframework.web.bind.annotation.RequestMapping; | 
| 10 | 14 | import org.springframework.web.bind.annotation.RequestParam; | 
| 11 | 15 | import org.springframework.web.bind.annotation.RestController; | 
| 12 | 16 | |
| 17 | +import java.util.Date; | |
| 13 | 18 | import java.util.HashMap; | 
| 14 | 19 | import java.util.Map; | 
| 15 | 20 | |
| ... | ... | @@ -17,175 +22,181 @@ import com.sincre.springboot.ApiPlatform.YinShiServiceConfig; | 
| 17 | 22 | |
| 18 | 23 | @RestController | 
| 19 | 24 | @RequestMapping("/YinShi") | 
| 20 | -@Api(value = "YinShiController",tags = "萤石对接接口") | |
| 25 | +@Api(value = "YinShiController", tags = "萤石对接接口") | |
| 21 | 26 | public class YinShiController { | 
| 22 | 27 | |
| 23 | - private static String AccessToken = "at.2scte32926nu6q7j6adhlabg28emicz6-58f6w0596w-1ppubtz-uxh6dnv5x"; | |
| 28 | + | |
| 24 | 29 | @ApiOperation(value = "用于管理员获取accessToken") | 
| 25 | 30 | @GetMapping("/token") | 
| 26 | - public String GetYinShiToken(){ | |
| 31 | + public String GetYinShiToken() { | |
| 27 | 32 | String appKey = YinShiServiceConfig.appKey; | 
| 28 | 33 | String appSecret = YinShiServiceConfig.appSecret; | 
| 29 | 34 | |
| 30 | 35 | 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; | |
| 36 | + Map<String, Object> map = new HashMap<>(); | |
| 37 | + | |
| 38 | + map.put("appKey", appKey); | |
| 39 | + map.put("appSecret", appSecret); | |
| 40 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
| 41 | + JSONObject jsonObject = new JSONObject(result); | |
| 42 | + JSONObject data = jsonObject.optJSONObject("data"); | |
| 43 | + YinShiServiceConfig.AccessToken = data.optString("accessToken"); | |
| 44 | + Date date = new Date(); | |
| 45 | + Date dateFu = new Date(data.optLong("expireTime")); | |
| 46 | + CacheHelper.putYingshiYunToken(YinShiServiceConfig.AccessToken, (int) ((dateFu.getTime()-date.getTime())/1000)); | |
| 47 | + return ResultUtils.getInstance().resturnResultYingshi(result); | |
| 38 | 48 | } | 
| 39 | 49 | |
| 40 | 50 | @ApiOperation(value = "增加子账号") | 
| 41 | 51 | @GetMapping("/addChildAccount") | 
| 42 | - public String addChildAccount(@RequestParam String accountName, @RequestParam String password){ | |
| 52 | + public String addChildAccount(@RequestParam String accountName, @RequestParam String password) { | |
| 43 | 53 | |
| 44 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/create"; | |
| 45 | - Map<String,Object> map = new HashMap<>(); | |
| 54 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/create"; | |
| 55 | + Map<String, Object> map = new HashMap<>(); | |
| 46 | 56 | //子账户密码,LowerCase(MD5(AppKey#密码明文)) | 
| 47 | - password = YinShiServiceConfig.appKey+"#"+password; | |
| 57 | + password = YinShiServiceConfig.appKey + "#" + password; | |
| 48 | 58 | try { | 
| 49 | 59 | password = MD5.md5(password, "").toLowerCase(); | 
| 50 | - }catch (Exception ex){ | |
| 60 | + } catch (Exception ex) { | |
| 51 | 61 | ex.getStackTrace(); | 
| 52 | 62 | } | 
| 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; | |
| 63 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
| 64 | + map.put("accountName", accountName); | |
| 65 | + map.put("password", password); | |
| 66 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
| 67 | + return ResultUtils.getInstance().resturnResultYingshi(result); | |
| 59 | 68 | } | 
| 60 | 69 | |
| 61 | 70 | @ApiOperation(value = "获取单个子账户信息") | 
| 62 | 71 | @GetMapping("getChildAccount") | 
| 63 | - public String getChildAccount(@RequestParam String accountId,@RequestParam String accountName){ | |
| 72 | + public String getChildAccount(@RequestParam String accountId, @RequestParam String accountName) { | |
| 64 | 73 | |
| 65 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/get"; | |
| 66 | - Map<String,Object> map = new HashMap<>(); | |
| 74 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/get"; | |
| 75 | + Map<String, Object> map = new HashMap<>(); | |
| 67 | 76 | //子账户密码,LowerCase(MD5(AppKey#密码明文)) | 
| 77 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
| 78 | + map.put("accountId", accountId); | |
| 79 | + map.put("accountName", accountName); | |
| 80 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
| 68 | 81 | |
| 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; | |
| 82 | + return result; | |
| 75 | 83 | } | 
| 76 | 84 | |
| 77 | 85 | @ApiOperation(value = "获取子账号信息列表") | 
| 78 | 86 | @GetMapping("getChildAccountList") | 
| 79 | - public String getChildAccountList(@RequestParam("pageIndex") Integer pageIndex,@RequestParam("pageSize") Integer pageSize){ | |
| 87 | + public String getChildAccountList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSize) { | |
| 80 | 88 | |
| 81 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/list"; | |
| 82 | - Map<String,Object> map = new HashMap<>(); | |
| 89 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/list"; | |
| 90 | + Map<String, Object> map = new HashMap<>(); | |
| 83 | 91 | //子账户密码,LowerCase(MD5(AppKey#密码明文)) | 
| 84 | 92 | |
| 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); | |
| 93 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
| 94 | + map.put("pageStart", pageIndex); | |
| 95 | + map.put("pageSize", pageSize); | |
| 96 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
| 89 | 97 | |
| 90 | - return result; | |
| 98 | + return result; | |
| 91 | 99 | } | 
| 92 | 100 | |
| 93 | 101 | @ApiOperation(value = "修改当前子账户密码") | 
| 94 | 102 | @GetMapping("updateChildPassword") | 
| 95 | - public String updateChildPassword(@RequestParam("accountId") String accountId,@RequestParam("newPassword") String newPassword,@RequestParam("oldPassword") String oldPassword){ | |
| 103 | + public String updateChildPassword(@RequestParam("accountId") String accountId, @RequestParam("newPassword") String newPassword, @RequestParam("oldPassword") String oldPassword) { | |
| 96 | 104 | |
| 97 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/updatePassword"; | |
| 98 | - Map<String,Object> map = new HashMap<>(); | |
| 105 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/updatePassword"; | |
| 106 | + Map<String, Object> map = new HashMap<>(); | |
| 99 | 107 | //子账户密码,LowerCase(MD5(AppKey#密码明文)) | 
| 100 | 108 | |
| 101 | - oldPassword = YinShiServiceConfig.appKey+"#"+oldPassword; | |
| 102 | - newPassword = YinShiServiceConfig.appKey+"#"+newPassword; | |
| 109 | + oldPassword = YinShiServiceConfig.appKey + "#" + oldPassword; | |
| 110 | + newPassword = YinShiServiceConfig.appKey + "#" + newPassword; | |
| 103 | 111 | try { | 
| 104 | 112 | oldPassword = MD5.md5(oldPassword, "").toLowerCase(); | 
| 105 | 113 | newPassword = MD5.md5(newPassword, "").toLowerCase(); | 
| 106 | - }catch (Exception ex){ | |
| 114 | + } catch (Exception ex) { | |
| 107 | 115 | ex.getStackTrace(); | 
| 108 | 116 | } | 
| 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); | |
| 117 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
| 118 | + map.put("accountId", accountId); | |
| 119 | + map.put("oldPassword", oldPassword); | |
| 120 | + map.put("newPassword", newPassword); | |
| 121 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
| 114 | 122 | |
| 115 | - return result; | |
| 123 | + return result; | |
| 116 | 124 | } | 
| 117 | 125 | |
| 118 | 126 | @ApiOperation(value = "删除指定子账户") | 
| 119 | 127 | @GetMapping("deleteChildAccount") | 
| 120 | - public String deleteChildAccount(@RequestParam String accountId){ | |
| 128 | + public String deleteChildAccount(@RequestParam String accountId) { | |
| 121 | 129 | |
| 122 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/delete"; | |
| 123 | - Map<String,Object> map = new HashMap<>(); | |
| 130 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/delete"; | |
| 131 | + Map<String, Object> map = new HashMap<>(); | |
| 124 | 132 | |
| 125 | - map.put("accessToken",AccessToken); | |
| 126 | - map.put("accountId",accountId); | |
| 127 | - String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
| 133 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
| 134 | + map.put("accountId", accountId); | |
| 135 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
| 128 | 136 | |
| 129 | - return result; | |
| 137 | + return result; | |
| 130 | 138 | } | 
| 131 | 139 | |
| 132 | 140 | |
| 133 | 141 | @ApiOperation(value = "设置子账户的授权策略") | 
| 134 | 142 | @GetMapping("policySet") | 
| 135 | - public String policySet(@RequestParam String accountId,@RequestParam String policy){ | |
| 143 | + public String policySet(@RequestParam String accountId, @RequestParam String policy) { | |
| 136 | 144 | |
| 137 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/policy/set"; | |
| 138 | - Map<String,Object> map = new HashMap<>(); | |
| 145 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/policy/set"; | |
| 146 | + Map<String, Object> map = new HashMap<>(); | |
| 139 | 147 | |
| 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); | |
| 148 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
| 149 | + map.put("accountId", accountId); | |
| 150 | + map.put("policy", policy); | |
| 151 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
| 144 | 152 | |
| 145 | - return result; | |
| 153 | + return result; | |
| 146 | 154 | } | 
| 147 | 155 | |
| 148 | 156 | @ApiOperation(value = "增加子账户授权策略中的授权语句") | 
| 149 | 157 | @GetMapping("policyAdd") | 
| 150 | - public String policyAdd(@RequestParam String accountId,@RequestParam String statement){ | |
| 158 | + public String policyAdd(@RequestParam String accountId, @RequestParam String statement) { | |
| 151 | 159 | |
| 152 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/statement/add"; | |
| 153 | - Map<String,Object> map = new HashMap<>(); | |
| 160 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/add"; | |
| 161 | + Map<String, Object> map = new HashMap<>(); | |
| 154 | 162 | |
| 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); | |
| 163 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
| 164 | + map.put("accountId", accountId); | |
| 165 | + map.put("statement", statement); | |
| 166 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
| 159 | 167 | |
| 160 | - return result; | |
| 168 | + return result; | |
| 161 | 169 | } | 
| 162 | 170 | |
| 163 | 171 | @ApiOperation(value = "删除子账户授权策略中指定设备的所有授权语句") | 
| 164 | 172 | @GetMapping("policyDelete") | 
| 165 | - public String policyDelete(@RequestParam String accountId,@RequestParam String deviceSerial){ | |
| 173 | + public String policyDelete(@RequestParam String accountId, @RequestParam String deviceSerial) { | |
| 166 | 174 | |
| 167 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/statement/delete"; | |
| 168 | - Map<String,Object> map = new HashMap<>(); | |
| 175 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/delete"; | |
| 176 | + Map<String, Object> map = new HashMap<>(); | |
| 169 | 177 | |
| 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); | |
| 178 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | |
| 179 | + map.put("accountId", accountId); | |
| 180 | + map.put("deviceSerial", deviceSerial); | |
| 181 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | |
| 174 | 182 | |
| 175 | - return result; | |
| 183 | + return result; | |
| 176 | 184 | } | 
| 177 | 185 | |
| 178 | 186 | @ApiOperation(value = "获取B模式子账户accessToken") | 
| 179 | 187 | @GetMapping("getChildAccountToken") | 
| 180 | - public String getChildAccountToken(@RequestParam String accountId){ | |
| 188 | + public String getChildAccountToken(@RequestParam String accountId) { | |
| 181 | 189 | |
| 182 | - String url =YinShiServiceConfig.HostUrl + "lapp/ram/token/get"; | |
| 183 | - Map<String,Object> map = new HashMap<>(); | |
| 190 | + String url = YinShiServiceConfig.HostUrl + "lapp/ram/token/get"; | |
| 191 | + Map<String, Object> map1 = new HashMap<>(); | |
| 184 | 192 | |
| 185 | - map.put("accessToken",AccessToken); | |
| 186 | - map.put("accountId",accountId); | |
| 187 | - String result = ApiHelper.doPost(url,new HashMap<String, String>(),map); | |
| 193 | + map1.put("accessToken", YinShiServiceConfig.AccessToken); | |
| 194 | + map1.put("accountId", accountId); | |
| 195 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map1); | |
| 188 | 196 | |
| 189 | - return result; | |
| 197 | + return result; | |
| 190 | 198 | } | 
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 191 | 202 | } | ... | ... | 
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
| ... | ... | @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; | 
| 5 | 5 | import com.sincre.springboot.ApiModel.TuYaResResult; | 
| 6 | 6 | import com.sincre.springboot.ApiModel.TuYaResTokenObj; | 
| 7 | 7 | import com.sincre.springboot.ApiPlatform.TuYaCloudService; | 
| 8 | +import com.sincre.springboot.ApiPlatform.YinShiServiceConfig; | |
| 8 | 9 | import com.sincre.springboot.common.EhcacheUtil; | 
| 9 | 10 | import org.apache.commons.lang3.StringUtils; | 
| 10 | 11 | |
| ... | ... | @@ -91,4 +92,23 @@ public class CacheHelper { | 
| 91 | 92 | System.out.println(ex.getMessage()); | 
| 92 | 93 | } | 
| 93 | 94 | } | 
| 95 | + | |
| 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 | + } | |
| 113 | + | |
| 94 | 114 | } | ... | ... | 
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