Commit 99a9cdbb by 111-PC\111

[+]aqara代码提交

1 parent c90a7266
...@@ -21,6 +21,44 @@ ...@@ -21,6 +21,44 @@
<dependency> <dependency>
<groupId>com.glsx</groupId> <groupId>com.glsx</groupId>
<artifactId>rest-admin-alliance</artifactId> <artifactId>rest-admin-alliance</artifactId>
<exclusions>
<exclusion>
<artifactId>zipkin-reporter-metrics-micrometer</artifactId>
<groupId>io.zipkin.reporter2</groupId>
</exclusion>
<exclusion>
<artifactId>zipkin-sender-amqp-client</artifactId>
<groupId>io.zipkin.reporter2</groupId>
</exclusion>
<exclusion>
<artifactId>zipkin-sender-kafka</artifactId>
<groupId>io.zipkin.reporter2</groupId>
</exclusion>
<exclusion>
<artifactId>zipkin-sender-activemq-client</artifactId>
<groupId>io.zipkin.reporter2</groupId>
</exclusion>
<exclusion>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
<groupId>org.springframework.cloud</groupId>
</exclusion>
<exclusion>
<artifactId>zipkin-reporter</artifactId>
<groupId>io.zipkin.reporter2</groupId>
</exclusion>
<exclusion>
<artifactId>zipkin-reporter-brave</artifactId>
<groupId>io.zipkin.reporter2</groupId>
</exclusion>
<exclusion>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<groupId>org.springframework.cloud</groupId>
</exclusion>
<exclusion>
<artifactId>rest-admin-sleuth</artifactId>
<groupId>com.glsx</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!-- 运行环境上下文 --> <!-- 运行环境上下文 -->
<dependency> <dependency>
...@@ -50,6 +88,22 @@ ...@@ -50,6 +88,22 @@
<artifactId>rest-admin-swagger2</artifactId> <artifactId>rest-admin-swagger2</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>io.github.yedaxia</groupId>
<artifactId>japidocs</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>com.lumi.opencloud</groupId>
<artifactId>opencloud-sdk</artifactId>
<version>1.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-log4j2</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -7,7 +7,7 @@ package cn.com.glsx.common.BussinessFactory; ...@@ -7,7 +7,7 @@ package cn.com.glsx.common.BussinessFactory;
public enum BussinessType { public enum BussinessType {
tuya_hander("tuya", "deviceService"), tuya_hander("tuya", "deviceService"),
mhome_hander("mhome", "testService"); aqara_hander("aqara", "aqaraDeviceService");
private String busType; private String busType;
private String handerImp; private String handerImp;
......
...@@ -8,4 +8,7 @@ public class Constants { ...@@ -8,4 +8,7 @@ public class Constants {
// 涂鸦立牌rediskey // 涂鸦立牌rediskey
public static final String ACCESSTOKEN_REDISKEY="accessToken_redisKey"; public static final String ACCESSTOKEN_REDISKEY="accessToken_redisKey";
public static final int AQARA_RETURN_SUCCESS_CODE=0;
public static final int AQARA_RETURN_FAIL_CODE=500;
} }
package cn.com.glsx.modules.controller;
import cn.com.glsx.modules.service.AqaraDeviceService;
import cn.com.glsx.modules.service.OauthService;
import com.glsx.plat.core.web.R;
import com.lumi.opencloud.model.v1.request.DeviceBindGetRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author zhouhaibao
* @date 2021/4/20 16:25
*/
@Controller
@RequestMapping("/device")
@Api(value = "aqara设备管理", tags = {"aqara设备管理"})
public class AqaraDeviceController {
@Autowired
private AqaraDeviceService aqaraDeviceService;
@RequestMapping(value = "/bindKeyGet/{token}", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "获取bindKey")
public R bindKeyGet(@RequestBody DeviceBindGetRequest deviceBindGetRequest, @PathVariable String token){
return aqaraDeviceService.bindKeyGet(token,deviceBindGetRequest);
}
}
...@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
/** /**
* 设备管理
*
* @author zhouhaibao * @author zhouhaibao
* @date 2021/3/4 17:05 * @date 2021/3/4 17:05
*/ */
......
package cn.com.glsx.modules.controller;
import cn.com.glsx.modules.service.HomeService;
import com.glsx.plat.core.web.R;
import com.lumi.opencloud.model.v1.request.AuthorizeRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author zhouhaibao
* @date 2021/4/20 20:59
*/
@Controller
@RequestMapping("/home")
@Api(value = "位置信息", tags = {"位置信息"})
public class HomeController {
@Autowired
private HomeService homeService;
@RequestMapping(value = "/getHome", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "获取位置信息")
public R getHome(String token){
return homeService.getHome(token);
}
}
package cn.com.glsx.modules.controller;
import cn.com.glsx.modules.service.OauthService;
import com.glsx.plat.core.web.R;
import com.lumi.opencloud.model.v1.request.AccessTokenRequest;
import com.lumi.opencloud.model.v1.request.AuthorizeRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author zhouhaibao
* @date 2021/4/20 16:33
*/
@Controller
@RequestMapping("/oauth")
@Api(value = "aqara用户授权", tags = {"aqara用户授权"})
public class OauthController {
@Autowired
private OauthService oauthService;
@RequestMapping(value = "/authorize", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "获取鉴权码")
public R authorize(@RequestBody AuthorizeRequest authorizeRequest){
return oauthService.authorize(authorizeRequest);
}
@RequestMapping(value = "/accessToken", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "获取accesstoken")
public R accessToken(@RequestBody AccessTokenRequest accessTokenRequest){
return oauthService.accessToken(accessTokenRequest);
}
}
package cn.com.glsx.modules.service;
import cn.com.glsx.common.Constants;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import com.lumi.opencloud.common.AiotConfig;
import com.lumi.opencloud.common.ResponseMsg;
import com.lumi.opencloud.manager.v1.DeviceManager;
import com.lumi.opencloud.model.v1.request.DeviceBindGetRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* @author zhouhaibao
* @date 2021/4/20 17:56
*/
@Slf4j
@Service
public class AqaraDeviceService {
@Value("${aqara.clientId}")
private String clientId;
@Value("${aqara.doapi}")
private String domain;
/**
* 获取bindKey接口
*
* @param deviceBindGetRequest 入参
* @return
*/
public R bindKeyGet(String token, DeviceBindGetRequest deviceBindGetRequest) {
AiotConfig aiotConfig = new AiotConfig();
aiotConfig.setAppId(clientId);
aiotConfig.setAccessToken(token);
aiotConfig.setDomain(domain);
ResponseMsg responseMsg = DeviceManager.bindKeyGet(aiotConfig, deviceBindGetRequest);
if (responseMsg != null && Constants.AQARA_RETURN_SUCCESS_CODE == responseMsg.getCode()) {
return R.ok(JSONObject.toJSONString(responseMsg));
}
return R.error(responseMsg.getMessage());
}
}
package cn.com.glsx.modules.service;
import cn.com.glsx.common.Constants;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import com.lumi.opencloud.common.AiotConfig;
import com.lumi.opencloud.common.ResponseMsg;
import com.lumi.opencloud.manager.v1.PositionManager;
import com.lumi.opencloud.model.v1.request.PositionQueryRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* @author zhouhaibao
* @date 2021/4/20 20:56
*/
@Slf4j
@Service
public class HomeService {
@Value("${aqara.clientId}")
private String clientId;
@Value("${aqara.doapi}")
private String domain;
public R getHome(String token){
AiotConfig aiotConfig = new AiotConfig();
aiotConfig.setAppId(clientId);
aiotConfig.setAccessToken(token);
aiotConfig.setDomain(domain);
ResponseMsg responseMsg = PositionManager.positionQuery(aiotConfig,new PositionQueryRequest());
if (responseMsg != null && Constants.AQARA_RETURN_SUCCESS_CODE == responseMsg.getCode()) {
return R.ok(JSONObject.toJSONString(responseMsg));
}
return R.error(responseMsg.getMessage());
}
}
package cn.com.glsx.modules.service;
import cn.com.glsx.common.Constants;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import com.lumi.opencloud.common.Contant;
import com.lumi.opencloud.common.ResponseMsg;
import com.lumi.opencloud.manager.v1.OauthManager;
import com.lumi.opencloud.model.v1.request.AccessTokenRequest;
import com.lumi.opencloud.model.v1.request.AuthorizeRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* @author zhouhaibao
* @date 2021/4/20 17:16
*/
@Slf4j
@Service
public class OauthService {
@Value("${aqara.domain}")
private String domain;
@Value("${aqara.clientId}")
private String clientId;
@Value("${aqara.clientSecret}")
private String clientSecret;
@Value("${aqara.redirectUri}")
private String redirectUri;
/**
* 或者鉴权码
*
* @param authorizeRequest 入参
* @return
*/
public R authorize(AuthorizeRequest authorizeRequest) {
authorizeRequest.setClientId(clientId);
authorizeRequest.setRedirectUri(redirectUri);
authorizeRequest.setAccount("13476670746");
authorizeRequest.setPassword("zhb19940903");
ResponseMsg responseMsg = OauthManager.authorize(domain, authorizeRequest);
if(responseMsg!=null&& Constants.AQARA_RETURN_SUCCESS_CODE==responseMsg.getCode()){
return R.ok(JSONObject.toJSONString(responseMsg));
}
return R.error(responseMsg.getMessage());
}
/**
* 获取accessToken
*
* @param authorizeRequest 入参
* @return
*/
public R accessToken(AccessTokenRequest authorizeRequest) {
authorizeRequest.setClientId(clientId);
authorizeRequest.setClientSecret(clientSecret);
authorizeRequest.setRedirectUri(redirectUri);
authorizeRequest.setGrantType("authorization_code");
ResponseMsg authorize = OauthManager.accessToken(domain, authorizeRequest);
if(authorize!=null&& Constants.AQARA_RETURN_SUCCESS_CODE==authorize.getCode()){
return R.ok(JSONObject.toJSONString(authorize));
}
return R.error(authorize.getMessage());
}
}
...@@ -6,6 +6,7 @@ logging.path=/data/java_log/jetty/${spring.application.name}/${spring.applicatio ...@@ -6,6 +6,7 @@ logging.path=/data/java_log/jetty/${spring.application.name}/${spring.applicatio
#nacos配置中心 #nacos配置中心
spring.cloud.nacos.config.server-addr=192.168.0.63:8848 spring.cloud.nacos.config.server-addr=192.168.0.63:8848
spring.freemarker.checkTemplateLocation=false
#nacos配置id,完整dataId=${spring.cloud.nacos.config.prefix}-${spring.profiles.active}.${file-extension(由新增配置时选的文件类型决定)} #nacos配置id,完整dataId=${spring.cloud.nacos.config.prefix}-${spring.profiles.active}.${file-extension(由新增配置时选的文件类型决定)}
#示例:http://192.168.0.63:8848/nacos/v1/cs/configs?dataId=glsx-rest-admin.properties&group=DEV_GROUP #示例:http://192.168.0.63:8848/nacos/v1/cs/configs?dataId=glsx-rest-admin.properties&group=DEV_GROUP
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!