Commit 41b4900a6a8340c70876fecbdb684474b18a69c4

Authored by baishou
1 parent 7dc3d7c7
Exists in master

涂鸦云服务对接接口封装以及代码优化

springboot/src/main/java/com/sincre/springboot/ApiModel/TuYaResResult.java
... ... @@ -5,11 +5,11 @@ import com.fasterxml.jackson.annotation.JsonInclude;
5 5 @JsonInclude(JsonInclude.Include.NON_EMPTY)
6 6 public class TuYaResResult<T> {
7 7  
8   - public String getSuccess() {
  8 + public Boolean getSuccess() {
9 9 return success;
10 10 }
11 11  
12   - public void setSuccess(String success) {
  12 + public void setSuccess(Boolean success) {
13 13 this.success = success;
14 14 }
15 15  
... ... @@ -45,7 +45,7 @@ public class TuYaResResult&lt;T&gt; {
45 45 this.t = t;
46 46 }
47 47  
48   - private String success;
  48 + private Boolean success;
49 49 private String code;
50 50 private String msg;
51 51 private Long t;
... ...
springboot/src/main/java/com/sincre/springboot/controller/TuYaYunController.java
1 1 package com.sincre.springboot.controller;
2 2  
  3 +import com.alibaba.fastjson.JSON;
3 4 import com.fasterxml.jackson.core.type.TypeReference;
4 5 import com.fasterxml.jackson.databind.ObjectMapper;
5   -import com.sincre.springboot.ApiModel.DeviceToken;
6   -import com.sincre.springboot.ApiModel.TuYaDevicesList;
7   -import com.sincre.springboot.ApiModel.TuYaResResult;
8   -import com.sincre.springboot.ApiModel.UserInfo;
  6 +import com.sincre.springboot.ApiModel.*;
9 7 import com.sincre.springboot.ApiPlatform.TuYaCloudService;
  8 +import com.sincre.springboot.common.ServerResponse;
10 9 import com.sincre.springboot.utils.ApiHelper;
11 10 import com.sincre.springboot.utils.CacheHelper;
12 11 import com.sincre.springboot.utils.ResultUtils;
13 12 import io.swagger.annotations.Api;
  13 +import io.swagger.annotations.ApiImplicitParam;
  14 +import io.swagger.annotations.ApiImplicitParams;
  15 +import io.swagger.annotations.ApiOperation;
14 16 import org.springframework.web.bind.annotation.*;
15 17  
16 18 import java.util.HashMap;
... ... @@ -22,7 +24,7 @@ import java.util.Map;
22 24 public class TuYaYunController {
23 25  
24 26 @GetMapping("GetDevicesInfo")
25   - public TuYaResResult getTuYaDevicesInfo(){
  27 + public ServerResponse getTuYaDevicesInfo(){
26 28  
27 29 String apiUrl = "/v1.0/devices?device_ids=";
28 30 Long t = System.currentTimeMillis();
... ... @@ -36,16 +38,18 @@ public class TuYaYunController {
36 38 map.put("t",t.toString());
37 39 String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map);
38 40  
39   - TuYaResResult<TuYaDevicesList> resResult = null;
40   - try{
41   - ObjectMapper objectMapper = new ObjectMapper();
42   - TypeReference<TuYaResResult<TuYaDevicesList>> reference = new TypeReference<TuYaResResult<TuYaDevicesList>>(){};
43   - resResult = objectMapper.readValue(result,reference);
44   - } catch(Exception ex){
45   - System.out.println(ex.getMessage());
46   - }
  41 +// TuYaResResult<TuYaDevicesList> resResult = null;
  42 +// try{
  43 +// ObjectMapper objectMapper = new ObjectMapper();
  44 +// TypeReference<TuYaResResult<TuYaDevicesList>> reference = new TypeReference<TuYaResResult<TuYaDevicesList>>(){};
  45 +// resResult = objectMapper.readValue(result,reference);
  46 +// } catch(Exception ex){
  47 +// System.out.println(ex.getMessage());
  48 +// }
47 49 System.out.println(result);
48   - return resResult;
  50 +
  51 + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class);
  52 + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult);
49 53 }
50 54  
51 55  
... ... @@ -56,8 +60,13 @@ public class TuYaYunController {
56 60 * @param pageSize 大小
57 61 * @return
58 62 */
  63 + @ApiOperation(value = "获取用户信息列表")
  64 + @ApiImplicitParams({
  65 + @ApiImplicitParam(name="pageIndex", value = "分页起始页,从1开始",required = true),
  66 + @ApiImplicitParam(name="pageSize", value = "分页大小,默认为10,最大为50")
  67 + })
59 68 @GetMapping("{AppId}/GetTuYaAPPUser")
60   - public String getTuYaAPPUser(@PathVariable("AppId") String AppId, @RequestParam int pageIndex, @RequestParam int pageSize){
  69 + public ServerResponse getTuYaAPPUser(@PathVariable("AppId") String AppId, @RequestParam int pageIndex, @RequestParam(defaultValue = "10") int pageSize){
61 70  
62 71 String apiUrl = String.format("/v1.0/apps/%s/users?page_no=%d&page_size=%d",AppId,pageIndex,pageSize);//iotshunzhi
63 72 Long t = System.currentTimeMillis();
... ... @@ -73,12 +82,13 @@ public class TuYaYunController {
73 82  
74 83 String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,headMap);
75 84  
76   - return result;
  85 + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class);
  86 + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult);
77 87 }
78 88  
79 89  
80 90 @PostMapping("{AppId}/AddTuYaAPPUser")
81   - public String addTuYaAPPUser(@PathVariable("AppId") String AppId,@RequestBody UserInfo userInfo){
  91 + public ServerResponse addTuYaAPPUser(@PathVariable("AppId") String AppId, @RequestBody UserInfo userInfo){
82 92  
83 93 String apiUrl = String.format("/v1.0/apps/%s/user",AppId);//应用标识iotshunzhi
84 94 Long t = System.currentTimeMillis();
... ... @@ -93,7 +103,6 @@ public class TuYaYunController {
93 103 headMap.put("t",t.toString());
94 104  
95 105 ObjectMapper objectMapper = new ObjectMapper();
96   -
97 106 String jsonResult = "";
98 107 try {
99 108 jsonResult = objectMapper.writeValueAsString(userInfo);
... ... @@ -103,9 +112,8 @@ public class TuYaYunController {
103 112  
104 113 String result = ApiHelper.doPost(TuYaCloudService.TuYaOpenUrl + apiUrl,headMap,jsonResult);
105 114  
106   - TuYaResResult<UserInfo> resResult = null;
107   -
108   - return result;
  115 + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class);
  116 + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult);
109 117 }
110 118  
111 119 /**
... ... @@ -114,7 +122,7 @@ public class TuYaYunController {
114 122 * @return
115 123 */
116 124 @GetMapping("{uid}/GetDevicesByUid")
117   - public String getDevicesByUid(@PathVariable("uid") String uid){
  125 + public ServerResponse getDevicesByUid(@PathVariable("uid") String uid){
118 126  
119 127 String apiUrl = String.format("/v1.0/users/%s/devices",uid);
120 128 Long t = System.currentTimeMillis();
... ... @@ -130,14 +138,16 @@ public class TuYaYunController {
130 138  
131 139 String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map);
132 140  
133   - return result;
  141 + System.out.println(result);
  142 + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class);
  143 + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult);
134 144 }
135 145 /**
136 146 * 生成配网的Token
137 147 * @return
138 148 */
139 149 @GetMapping("AddDevicesToken")
140   - public String addDevicesToken(@RequestParam String UId){
  150 + public ServerResponse addDevicesToken(@RequestParam String UId){
141 151  
142 152 String apiUrl = String.format("/v1.0/devices/token");
143 153 Long t = System.currentTimeMillis();
... ... @@ -164,11 +174,12 @@ public class TuYaYunController {
164 174 }
165 175 String result = ApiHelper.doPost(TuYaCloudService.TuYaOpenUrl + apiUrl,map,jsonResult);
166 176  
167   - return result;
  177 + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class);
  178 + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult);
168 179 }
169 180  
170 181 @GetMapping("{token}/GetDevicesByToken")
171   - public String getDevicesByToken(@PathVariable("token") String token){
  182 + public ServerResponse getDevicesByToken(@PathVariable("token") String token){
172 183  
173 184 String apiUrl = String.format("/v1.0/devices/tokens/%s",token);
174 185 Long t = System.currentTimeMillis();
... ... @@ -184,6 +195,7 @@ public class TuYaYunController {
184 195  
185 196 String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map);
186 197  
187   - return result;
  198 + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class);
  199 + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult);
188 200 }
189 201 }
... ...
springboot/src/main/java/com/sincre/springboot/controller/YinShiController.java
... ... @@ -3,6 +3,7 @@ package com.sincre.springboot.controller;
3 3  
4 4 import com.alibaba.fastjson.JSON;
5 5 import com.sincre.springboot.ApiModel.YinShiResResult;
  6 +import com.sincre.springboot.ApiPlatform.YinShiServiceConfig;
6 7 import com.sincre.springboot.common.MD5;
7 8 import com.sincre.springboot.common.ResponseCode;
8 9 import com.sincre.springboot.common.ServerResponse;
... ... @@ -10,19 +11,17 @@ import com.sincre.springboot.utils.ApiHelper;
10 11 import com.sincre.springboot.utils.CacheHelper;
11 12 import com.sincre.springboot.utils.ResultUtils;
12 13 import io.swagger.annotations.Api;
  14 +import io.swagger.annotations.ApiImplicitParam;
  15 +import io.swagger.annotations.ApiImplicitParams;
13 16 import io.swagger.annotations.ApiOperation;
14   -import org.json.JSONObject;
15 17 import org.springframework.web.bind.annotation.GetMapping;
16 18 import org.springframework.web.bind.annotation.RequestMapping;
17 19 import org.springframework.web.bind.annotation.RequestParam;
18 20 import org.springframework.web.bind.annotation.RestController;
19 21  
20   -import java.util.Date;
21 22 import java.util.HashMap;
22 23 import java.util.Map;
23 24  
24   -import com.sincre.springboot.ApiPlatform.YinShiServiceConfig;
25   -
26 25 @RestController
27 26 @RequestMapping("/YinShi")
28 27 @Api(value = "YinShiController", tags = "萤石对接接口")
... ... @@ -39,7 +38,7 @@ public class YinShiController {
39 38  
40 39 @ApiOperation(value = "增加子账号")
41 40 @GetMapping("/addChildAccount")
42   - public String addChildAccount(@RequestParam String accountName, @RequestParam String password) {
  41 + public ServerResponse addChildAccount(@RequestParam String accountName, @RequestParam String password) {
43 42  
44 43 String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/create";
45 44 Map<String, Object> map = new HashMap<>();
... ... @@ -54,28 +53,38 @@ public class YinShiController {
54 53 map.put("accountName", accountName);
55 54 map.put("password", password);
56 55 String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
57   - return result;//ResultUtils.getInstance().resturnResultYingshi(result);
  56 +
  57 + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
  58 +
  59 + System.out.println(result);
  60 + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
58 61 }
59 62  
60 63 @ApiOperation(value = "获取单个子账户信息")
  64 + @ApiImplicitParam(name="accountId",value = "子账号标识",required = true,dataType = "String")
61 65 @GetMapping("getChildAccount")
62   - public String getChildAccount(@RequestParam String accountId, @RequestParam String accountName) {
  66 + public ServerResponse getChildAccount(@RequestParam String accountId) {
63 67  
64 68 String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/get";
65 69 Map<String, Object> map = new HashMap<>();
66 70  
67 71 map.put("accessToken", YinShiServiceConfig.AccessToken);
68 72 map.put("accountId", accountId);
69   - map.put("accountName", accountName);
70 73 String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
  74 + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
71 75  
72   - return result;
  76 + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
73 77 }
74 78  
75 79 @ApiOperation(value = "获取子账号信息列表")
  80 + @ApiImplicitParams({
  81 + @ApiImplicitParam(name="pageIndex", value = "分页起始页,从1开始",required = true),
  82 + @ApiImplicitParam(name="pageSize", value = "分页大小,默认为10,最大为50")
  83 + })
76 84 @GetMapping("getChildAccountList")
77   - public ServerResponse getChildAccountList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSize) {
  85 + public ServerResponse getChildAccountList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize) {
78 86  
  87 + pageIndex = pageIndex - 1;
79 88 String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/list";
80 89 Map<String, Object> map = new HashMap<>();
81 90  
... ... @@ -84,15 +93,14 @@ public class YinShiController {
84 93 map.put("pageSize", pageSize);
85 94 String result = ApiHelper.doPost(url, new HashMap<String,String>(), map);
86 95  
87   - System.out.println(result);
88 96 YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
89 97  
90   - return ResultUtils.getInstance().resturnResultYingshi(yinShiResResult);
  98 + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
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 ServerResponse updateChildPassword(@RequestParam("accountId") String accountId, @RequestParam("newPassword") String newPassword, @RequestParam("oldPassword") String oldPassword) {
96 104  
97 105 String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/updatePassword";
98 106 Map<String, Object> map = new HashMap<>();
... ... @@ -110,13 +118,14 @@ public class YinShiController {
110 118 map.put("oldPassword", oldPassword);
111 119 map.put("newPassword", newPassword);
112 120 String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
  121 + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
113 122  
114   - return result;
  123 + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
115 124 }
116 125  
117 126 @ApiOperation(value = "删除指定子账户")
118 127 @GetMapping("deleteChildAccount")
119   - public String deleteChildAccount(@RequestParam String accountId) {
  128 + public ServerResponse deleteChildAccount(@RequestParam String accountId) {
120 129  
121 130 String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/delete";
122 131 Map<String, Object> map = new HashMap<>();
... ... @@ -124,14 +133,15 @@ public class YinShiController {
124 133 map.put("accessToken", YinShiServiceConfig.AccessToken);
125 134 map.put("accountId", accountId);
126 135 String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
  136 + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
127 137  
128   - return result;
  138 + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
129 139 }
130 140  
131 141  
132 142 @ApiOperation(value = "设置子账户的授权策略")
133 143 @GetMapping("policySet")
134   - public String policySet(@RequestParam String accountId, @RequestParam String policy) {
  144 + public ServerResponse policySet(@RequestParam String accountId, @RequestParam String policy) {
135 145  
136 146 String url = YinShiServiceConfig.HostUrl + "lapp/ram/policy/set";
137 147 Map<String, Object> map = new HashMap<>();
... ... @@ -141,12 +151,14 @@ public class YinShiController {
141 151 map.put("policy", policy);
142 152 String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
143 153  
144   - return result;
  154 + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
  155 +
  156 + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
145 157 }
146 158  
147 159 @ApiOperation(value = "增加子账户授权策略中的授权语句")
148 160 @GetMapping("policyAdd")
149   - public String policyAdd(@RequestParam String accountId, @RequestParam String statement) {
  161 + public ServerResponse policyAdd(@RequestParam String accountId, @RequestParam String statement) {
150 162  
151 163 String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/add";
152 164 Map<String, Object> map = new HashMap<>();
... ... @@ -156,12 +168,14 @@ public class YinShiController {
156 168 map.put("statement", statement);
157 169 String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
158 170  
159   - return result;
  171 + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
  172 +
  173 + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
160 174 }
161 175  
162 176 @ApiOperation(value = "删除子账户授权策略中指定设备的所有授权语句")
163 177 @GetMapping("policyDelete")
164   - public String policyDelete(@RequestParam String accountId, @RequestParam String deviceSerial) {
  178 + public ServerResponse policyDelete(@RequestParam String accountId, @RequestParam String deviceSerial) {
165 179  
166 180 String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/delete";
167 181 Map<String, Object> map = new HashMap<>();
... ... @@ -171,12 +185,14 @@ public class YinShiController {
171 185 map.put("deviceSerial", deviceSerial);
172 186 String result = ApiHelper.doPost(url, new HashMap<String, String>(), map);
173 187  
174   - return result;
  188 + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
  189 +
  190 + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
175 191 }
176 192  
177 193 @ApiOperation(value = "获取B模式子账户accessToken")
178 194 @GetMapping("getChildAccountToken")
179   - public String getChildAccountToken(@RequestParam String accountId) {
  195 + public ServerResponse getChildAccountToken(@RequestParam String accountId) {
180 196  
181 197 String url = YinShiServiceConfig.HostUrl + "lapp/ram/token/get";
182 198 Map<String, Object> map1 = new HashMap<>();
... ... @@ -185,6 +201,8 @@ public class YinShiController {
185 201 map1.put("accountId", accountId);
186 202 String result = ApiHelper.doPost(url, new HashMap<String, String>(), map1);
187 203  
188   - return result;
  204 + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class);
  205 +
  206 + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult);
189 207 }
190 208 }
... ...
springboot/src/main/java/com/sincre/springboot/utils/ResultUtils.java
1 1 package com.sincre.springboot.utils;
2 2  
3 3  
  4 +import com.sincre.springboot.ApiModel.TuYaResResult;
4 5 import com.sincre.springboot.ApiModel.YinShiResResult;
5 6 import com.sincre.springboot.common.ResponseCode;
6 7 import com.sincre.springboot.common.ServerResponse;
7   -import com.sincre.springboot.model.ResultModelObj;
8   -import org.json.JSONObject;
9 8  
10 9 /**
11 10 * 结果返回工具类
... ... @@ -34,65 +33,54 @@ public class ResultUtils {
34 33 * @param yinShiResResult 萤石接口返回对象的字符串
35 34 * @return 返回的data可以是对象或者集合,都以字符串形式返回
36 35 */
37   - public ServerResponse resturnResultYingshi(YinShiResResult yinShiResResult) {
38   -// JSONObject jsonObject = new JSONObject(result);
39   -// ResultModelObj resultModelObj = new ResultModelObj();
40   -// long code = jsonObject.optLong("code");
41   -// if (code==10002){//accesstoken过期
42   -// new YinShiController().GetYinShiToken();
43   -// try {
44   -// Thread.sleep(1000);
45   -// } catch (InterruptedException e) {
46   -// e.printStackTrace();
47   -// }
48   -// }
49   -// resultModelObj.setCode(code);
50   -// resultModelObj.setData(jsonObject.optString("data"));
51   -// resultModelObj.setMsg(jsonObject.optString("msg"));
52   -// resultModelObj.setTotal(jsonObject.optInt("page"));
53   -// return resultModelObj.toString();
  36 + public ServerResponse returnResultYingshi(YinShiResResult yinShiResResult) {
54 37  
55   - int code = yinShiResResult.getCode();
56   - System.out.println(yinShiResResult.getPage().getTotal());
57   - if(code == 200){
58   - return ServerResponse.createBySuccess(yinShiResResult.getPage().getTotal().toString(), ResponseCode.SUCCESS.getDesc(),yinShiResResult.getData());
59   - }
60   - else {
61   - if (code==10002){//accessToken过期或异常
62   - CacheHelper.GetYinShiToken();
63   - try {
64   - Thread.sleep(1000);
65   - } catch (InterruptedException e) {
66   - e.printStackTrace();
  38 + try {
  39 + int code = yinShiResResult.getCode();
  40 +
  41 + if (code == 200) {
  42 + String total = null;
  43 + if (yinShiResResult.getPage() != null) {
  44 + total = yinShiResResult.getPage().getTotal().toString();
  45 + }
  46 + return ServerResponse.createBySuccess(total, ResponseCode.SUCCESS.getDesc(), yinShiResResult.getData());
  47 + } else {
  48 + if (code == 10002) {//accessToken过期或异常
  49 + CacheHelper.GetYinShiToken();
  50 + try {
  51 + Thread.sleep(1000);
  52 + } catch (InterruptedException e) {
  53 + e.printStackTrace();
  54 + }
  55 + }
  56 + return ServerResponse.createByErrorCodeMessage(code, yinShiResResult.getMsg());
67 57 }
68 58 }
69   - return ServerResponse.createByErrorMessage(yinShiResResult.getMsg());
  59 + catch (Exception ex){
  60 + return ServerResponse.createByErrorMessage("服务器内部处理出错!");
70 61 }
71 62 }
72   -
73   - private void getYinShiToken(){
74   -
75   - }
76   -
  63 +
77 64 /**
78 65 * 涂鸦云返回结果
79   - * @param result
  66 + * @param
80 67 * @return
81 68 */
82   - public String resturnResultTuya(String result) {
83   - JSONObject jsonObject = new JSONObject(result);
84   - boolean success = jsonObject.optBoolean("success");
85   - ResultModelObj resultModelObj = new ResultModelObj();
86   - if (success){//成功
87   - resultModelObj.setCode(200);
88   - resultModelObj.setData(jsonObject.optString("result"));
89   - resultModelObj.setMsg(jsonObject.optString("msg"));
90   - }else {//失败
91   - resultModelObj.setCode(jsonObject.optLong("code"));
92   - resultModelObj.setData("{}");
93   - resultModelObj.setMsg(jsonObject.optString("msg"));
  69 + public ServerResponse returnResultTuYa(TuYaResResult tuYaResResult) {
  70 + try {
  71 + boolean success = tuYaResResult.getSuccess();
  72 +
  73 + if (success) {
  74 +
  75 + return ServerResponse.createBySuccess(ResponseCode.SUCCESS.getDesc(), tuYaResResult.getResult());
  76 + }
  77 +
  78 + int code = Integer.valueOf(tuYaResResult.getCode());
  79 + return ServerResponse.createByErrorCodeMessage(code, tuYaResResult.getMsg());
  80 + }
  81 + catch (Exception ex){
  82 + return ServerResponse.createByErrorMessage("服务器内部处理出错!");
94 83 }
95   - return resultModelObj.toString();
96 84 }
97 85  
98 86 }
... ...