diff --git a/springboot/bash.exe.stackdump b/springboot/bash.exe.stackdump new file mode 100644 index 0000000..3dab5e2 --- /dev/null +++ b/springboot/bash.exe.stackdump @@ -0,0 +1,9 @@ +Stack trace: +Frame Function Args +000FFFFA1A8 0018007164E (0018026F12D, 00180224DC6, 000FFFFA1A8, 000FFFF90A0) +000FFFFA1A8 00180046669 (00000000000, 00000000000, 00000000000, 000FFFFFFFF) +000FFFFA1A8 001800466A2 (0018026F1E9, 000FFFFA058, 000FFFFA1A8, 00000000000) +000FFFFA1A8 001800BDFEF (00000000000, 00000000000, 00000000000, 00000000000) +000FFFFA1A8 001800BE20F (000FFFFA1D0, 00000000000, 00000000000, 00000000000) +000FFFFA250 001800BF4AD (000FFFFA1D0, 00000000000, 00000000000, 00000000000) +End of stack trace diff --git a/springboot/pom.xml b/springboot/pom.xml index 69383fc..124d510 100644 --- a/springboot/pom.xml +++ b/springboot/pom.xml @@ -77,6 +77,12 @@ 2.0.0 + + + org.apache.commons + commons-lang3 + 3.9 + org.apache.httpcomponents diff --git a/springboot/src/main/java/com/sincre/springboot/ApiModel/YinShiResResult.java b/springboot/src/main/java/com/sincre/springboot/ApiModel/YinShiResResult.java new file mode 100644 index 0000000..faf86ec --- /dev/null +++ b/springboot/src/main/java/com/sincre/springboot/ApiModel/YinShiResResult.java @@ -0,0 +1,61 @@ +package com.sincre.springboot.ApiModel; + +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class YinShiResResult { + + private YinShiToken data; + + public YinShiToken getData() { + return data; + } + + public void setData(YinShiToken data) { + this.data = data; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + private String code; + private String msg; +} + +class YinShiToken{ + + private String accessToken; + + private Long expireTime; + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public Long getExpireTime() { + return expireTime; + } + + public void setExpireTime(Long expireTime) { + this.expireTime = expireTime; + } + + +} diff --git a/springboot/src/main/java/com/sincre/springboot/ApiPlatform/YinShiServiceConfig.java b/springboot/src/main/java/com/sincre/springboot/ApiPlatform/YinShiServiceConfig.java new file mode 100644 index 0000000..1dbca06 --- /dev/null +++ b/springboot/src/main/java/com/sincre/springboot/ApiPlatform/YinShiServiceConfig.java @@ -0,0 +1,9 @@ +package com.sincre.springboot.ApiPlatform; + +public class YinShiServiceConfig { + + public final static String HostUrl = "https://open.ys7.com/api/"; + + public static String appKey = "3780bdecb44c4b608367ba469d6d52ea"; + public static String appSecret = "b6399d42a10215242c3d72944abdc8a2"; +} diff --git a/springboot/src/main/java/com/sincre/springboot/common/MD5.java b/springboot/src/main/java/com/sincre/springboot/common/MD5.java new file mode 100644 index 0000000..50689f6 --- /dev/null +++ b/springboot/src/main/java/com/sincre/springboot/common/MD5.java @@ -0,0 +1,42 @@ +package com.sincre.springboot.common; + +import org.apache.commons.codec.digest.DigestUtils; + +public class MD5 { + + /** + * MD5方法 + * + * @param text 明文 + * @param key 密钥 + * @return 密文 + * @throws Exception + */ + public static String md5(String text, String key) throws Exception { + //加密后的字符串 + String encodeStr= DigestUtils.md5Hex(text + key); + System.out.println("MD5加密后的字符串为:encodeStr="+encodeStr); + return encodeStr; + } + + /** + * MD5验证方法 + * + * @param text 明文 + * @param key 密钥 + * @param md5 密文 + * @return true/false + * @throws Exception + */ + public static boolean verify(String text, String key, String md5) throws Exception { + //根据传入的密钥进行验证 + String md5Text = md5(text, key); + if(md5Text.equalsIgnoreCase(md5)) + { + System.out.println("MD5验证通过"); + return true; + } + + return false; + } +} diff --git a/springboot/src/main/java/com/sincre/springboot/controller/TuYaYunController.java b/springboot/src/main/java/com/sincre/springboot/controller/TuYaYunController.java index 45240f3..8e38b35 100644 --- a/springboot/src/main/java/com/sincre/springboot/controller/TuYaYunController.java +++ b/springboot/src/main/java/com/sincre/springboot/controller/TuYaYunController.java @@ -17,7 +17,7 @@ import java.util.Map; @RestController @RequestMapping(value = "/TuYa/*") -@Api(value = "涂鸦云服务API调用") +@Api(tags = "涂鸦云服务API调用") public class TuYaYunController { @GetMapping("GetDevicesInfo") diff --git a/springboot/src/main/java/com/sincre/springboot/controller/YinShiController.java b/springboot/src/main/java/com/sincre/springboot/controller/YinShiController.java new file mode 100644 index 0000000..e3fbe0b --- /dev/null +++ b/springboot/src/main/java/com/sincre/springboot/controller/YinShiController.java @@ -0,0 +1,191 @@ +package com.sincre.springboot.controller; + + +import com.sincre.springboot.common.MD5; +import com.sincre.springboot.utils.ApiHelper; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +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.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 map = new HashMap<>(); + + map.put("appKey",appKey); + map.put("appSecret",appSecret); + String result = ApiHelper.doPost(url,new HashMap(),map); + + return result; + } + + @ApiOperation(value = "增加子账号") + @GetMapping("/addChildAccount") + public String addChildAccount(@RequestParam String accountName, @RequestParam String password){ + + String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/create"; + Map map = new HashMap<>(); + //子账户密码,LowerCase(MD5(AppKey#密码明文)) + password = YinShiServiceConfig.appKey+"#"+password; + try { + password = MD5.md5(password, "").toLowerCase(); + }catch (Exception ex){ + ex.getStackTrace(); + } + map.put("accessToken",AccessToken); + map.put("accountName",accountName); + map.put("password",password); + String result = ApiHelper.doPost(url,new HashMap(),map); + + return result; + } + + @ApiOperation(value = "获取单个子账户信息") + @GetMapping("getChildAccount") + public String getChildAccount(@RequestParam String accountId,@RequestParam String accountName){ + + String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/get"; + Map map = new HashMap<>(); + //子账户密码,LowerCase(MD5(AppKey#密码明文)) + + map.put("accessToken",AccessToken); + map.put("accountId",accountId); + map.put("accountName",accountName); + String result = ApiHelper.doPost(url,new HashMap(),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 map = new HashMap<>(); + //子账户密码,LowerCase(MD5(AppKey#密码明文)) + + map.put("accessToken",AccessToken); + map.put("pageStart",pageIndex); + map.put("pageSize",pageSize); + String result = ApiHelper.doPost(url,new HashMap(),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 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",AccessToken); + map.put("accountId",accountId); + map.put("oldPassword",oldPassword); + map.put("newPassword",newPassword); + String result = ApiHelper.doPost(url,new HashMap(),map); + + return result; + } + + @ApiOperation(value = "删除指定子账户") + @GetMapping("deleteChildAccount") + public String deleteChildAccount(@RequestParam String accountId){ + + String url =YinShiServiceConfig.HostUrl + "lapp/ram/account/delete"; + Map map = new HashMap<>(); + + map.put("accessToken",AccessToken); + map.put("accountId",accountId); + String result = ApiHelper.doPost(url,new HashMap(),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 map = new HashMap<>(); + + map.put("accessToken",AccessToken); + map.put("accountId",accountId); + map.put("policy",policy); + String result = ApiHelper.doPost(url,new HashMap(),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 map = new HashMap<>(); + + map.put("accessToken",AccessToken); + map.put("accountId",accountId); + map.put("statement",statement); + String result = ApiHelper.doPost(url,new HashMap(),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 map = new HashMap<>(); + + map.put("accessToken",AccessToken); + map.put("accountId",accountId); + map.put("deviceSerial",deviceSerial); + String result = ApiHelper.doPost(url,new HashMap(),map); + + return result; + } + + @ApiOperation(value = "获取B模式子账户accessToken") + @GetMapping("getChildAccountToken") + public String getChildAccountToken(@RequestParam String accountId){ + + String url =YinShiServiceConfig.HostUrl + "lapp/ram/token/get"; + Map map = new HashMap<>(); + + map.put("accessToken",AccessToken); + map.put("accountId",accountId); + String result = ApiHelper.doPost(url,new HashMap(),map); + + return result; + } +} diff --git a/springboot/src/main/java/com/sincre/springboot/utils/ApiHelper.java b/springboot/src/main/java/com/sincre/springboot/utils/ApiHelper.java index 3df762c..68ab223 100644 --- a/springboot/src/main/java/com/sincre/springboot/utils/ApiHelper.java +++ b/springboot/src/main/java/com/sincre/springboot/utils/ApiHelper.java @@ -74,22 +74,23 @@ public class ApiHelper { /** * 表单格式的post请求 - * @param url 接口地址 + * + * @param url 接口地址 * @param headerParamMap 设置请求头 - * @param paramMap 设置请求值 + * @param paramMap 设置请求值,表单格式的请求值 * @return */ - public static String doPost(String url,Map headerParamMap, Map paramMap) { - CloseableHttpClient httpClient ; + public static String doPost(String url, Map headerParamMap, Map paramMap) { + CloseableHttpClient httpClient; String result; // 创建httpClient实例 httpClient = HttpClients.createDefault(); // 创建httpPost远程连接实例 HttpPost httpPost = new HttpPost(url); // 设置请求头 - httpPost.addHeader("Content-Type", "application/json"); + httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded"); for (Map.Entry entry : headerParamMap.entrySet()) { - httpPost.setHeader(entry.getKey(),entry.getValue()); + httpPost.setHeader(entry.getKey(), entry.getValue()); } // 配置请求参数实例 RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 设置连接主机服务超时时间 @@ -114,16 +115,14 @@ public class ApiHelper { // 为httpPost设置封装好的请求参数 try { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nvps, "UTF-8"); - entity.setContentType("application/json"); httpPost.setEntity(entity); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } - result = closeHttpAndResult(httpClient,httpPost); + result = closeHttpAndResult(httpClient, httpPost); return result; } - /** * post请求,内容体比较灵活,任意字符串格式的内容 * @param url diff --git a/springboot/src/main/java/com/sincre/springboot/utils/CacheHelper.java b/springboot/src/main/java/com/sincre/springboot/utils/CacheHelper.java index 41d9c80..5e93b06 100644 --- a/springboot/src/main/java/com/sincre/springboot/utils/CacheHelper.java +++ b/springboot/src/main/java/com/sincre/springboot/utils/CacheHelper.java @@ -28,7 +28,7 @@ public class CacheHelper { map.put("sign_method",TuYaCloudService.Sign_method); map.put("t",t.toString()); String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); - + System.out.println(result); TuYaResResult resResult ; try{ ObjectMapper objectMapper = new ObjectMapper(); -- libgit2 0.21.0