Commit 0160f5c2 by 王欣伟

Revert "Merge branch 'dev' into 'master'"

This reverts merge request !1
1 parent 9d44fe6f
......@@ -40,16 +40,6 @@
<artifactId>rest-admin-redis</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-mybatis</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-swagger2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
......
......@@ -5,8 +5,6 @@ import cn.com.glsx.modules.model.param.UserInfo;
import cn.com.glsx.modules.service.UserService;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
......@@ -24,7 +22,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
*/
@Controller
@RequestMapping("/user")
@Api(value = "用户模块", tags = {"用户模块"})
public class UserController {
@Autowired
......@@ -38,7 +35,6 @@ public class UserController {
*/
@RequestMapping(value = "/registerUser", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "注册用户")
public R registerUser(@RequestBody UserBo userBo) {
String uid = userService.registerUser(userBo);
if(StringUtils.isNotBlank(uid)){
......@@ -56,7 +52,6 @@ public class UserController {
*/
@RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询用户")
public R getUserInfo(@PathVariable String id) {
UserInfo userInfo = userService.getUserInfo(id);
return R.ok(JSONObject.toJSONString(userInfo));
......
package cn.com.glsx.modules.service;
import cn.com.glsx.modules.mapper.TuyaUserMapper;
import cn.com.glsx.common.Constants;
import cn.com.glsx.common.redis.AccessTokenRedis;
import cn.com.glsx.modules.model.param.AccessToken;
import cn.com.glsx.modules.model.param.ResponseBody;
import cn.com.glsx.modules.model.param.UserBo;
import cn.com.glsx.modules.model.param.UserInfo;
import cn.com.glsx.modules.utils.HeaderParamUtils;
import cn.com.glsx.modules.utils.AccessTokenService;
import cn.com.glsx.modules.utils.HttpUtil;
import cn.com.glsx.modules.utils.TuyaUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
......@@ -15,6 +18,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
......@@ -31,6 +35,9 @@ public class UserService {
@Value("${tuya.getUserInfoUrl}")
private String getUserInfoUrl;
@Value("${tuya.sign_method}")
private String sign_method;
@Value("${tuya.client_id}")
private String client_id;
......@@ -66,7 +73,14 @@ public class UserService {
private ResponseBody sendRequestRegisterUser(String accessToken, UserBo userBo) {
ResponseBody responseBody = null;
Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret, accessToken);
long timeMillis = System.currentTimeMillis();
String sign = TuyaUtils.getBussinessSign(timeMillis, client_id, secret, accessToken);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("client_id", client_id);
headerParams.put("t", timeMillis + "");
headerParams.put("sign_method", "HMAC-SHA256");
headerParams.put("sign", sign);
headerParams.put("access_token", accessToken);
try {
JSONObject jsonObject = HttpUtil.sendPost(registerUserUrl, JSONObject.toJSONString(userBo), headerParams);
responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class);
......@@ -101,7 +115,14 @@ public class UserService {
private ResponseBody sendRequestGetUserInfo(String id, String accessToken) {
ResponseBody responseBody = null;
Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret, accessToken);
long timeMillis = System.currentTimeMillis();
String sign = TuyaUtils.getBussinessSign(timeMillis, client_id, secret, accessToken);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("client_id", client_id);
headerParams.put("t", timeMillis + "");
headerParams.put("sign_method", "HMAC-SHA256");
headerParams.put("sign", sign);
headerParams.put("access_token", accessToken);
try {
JSONObject jsonObject = HttpUtil.sendGet(getUserInfoUrl.replace("{uid}", id), null, headerParams);
responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class);
......
package cn.com.glsx.modules.service;
package cn.com.glsx.modules.utils;
import cn.com.glsx.common.Constants;
import cn.com.glsx.common.redis.AccessTokenRedis;
import cn.com.glsx.modules.model.param.AccessToken;
import cn.com.glsx.modules.model.param.ResponseBody;
import cn.com.glsx.modules.utils.HeaderParamUtils;
import cn.com.glsx.modules.utils.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
......@@ -14,6 +12,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
......@@ -56,7 +55,7 @@ public class AccessTokenService {
String access_Token = null;
AccessToken accessToken = accessTokenRedis.readCache(Constants.ACCESSTOKEN_REDISKEY);
if (null != accessToken) {
if ((System.currentTimeMillis()-accessToken.getExpire_time()) >= 1000 * 60 * 60 * 2) {
if ((accessToken.getExpire_time() - System.currentTimeMillis()) >= 1000 * 60 * 60 * 2) {
ResponseBody responseBody = sendRequestFlashToken(accessToken.getRefresh_token());
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
......@@ -92,7 +91,13 @@ public class AccessTokenService {
*/
private ResponseBody sendRequestFlashToken(String flashtoken) {
ResponseBody responseBody = null;
Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret);
long timeMillis = System.currentTimeMillis();
String sign = TuyaUtils.getLoginSign(timeMillis, client_id, secret);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("client_id", client_id);
headerParams.put("t", timeMillis + "");
headerParams.put("sign_method", "HMAC-SHA256");
headerParams.put("sign", sign);
try {
JSONObject jsonObject = HttpUtil.sendGet(tokenFlashUrl + flashtoken, null, headerParams);
responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class);
......@@ -110,7 +115,13 @@ public class AccessTokenService {
*/
private ResponseBody sendRequestGetToken() {
ResponseBody responseBody = null;
Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret);
long timeMillis = System.currentTimeMillis();
String loginSign = TuyaUtils.getLoginSign(timeMillis, client_id, secret);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("client_id", client_id);
headerParams.put("t", timeMillis + "");
headerParams.put("sign_method", "HMAC-SHA256");
headerParams.put("sign", loginSign);
try {
JSONObject jsonObject = HttpUtil.sendGet(getTokenUrl, null, headerParams);
responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class);
......@@ -120,6 +131,4 @@ public class AccessTokenService {
}
return responseBody;
}
}
package cn.com.glsx.modules.utils;
import java.util.HashMap;
import java.util.Map;
/**
* @author zhouhaibao
* @date 2021/3/5 9:24
*/
public class HeaderParamUtils {
public static Map<String,String> buildHeaderParams(String client_id,String secret){
long timeMillis = System.currentTimeMillis();
String loginSign = TuyaUtils.getLoginSign(timeMillis, client_id, secret);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("client_id", client_id);
headerParams.put("t", timeMillis + "");
headerParams.put("sign_method", "HMAC-SHA256");
headerParams.put("sign", loginSign);
return headerParams;
}
public static Map<String,String> buildHeaderParams(String client_id,String secret,String accessToken){
long timeMillis = System.currentTimeMillis();
String sign = TuyaUtils.getBussinessSign(timeMillis, client_id, secret, accessToken);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("client_id", client_id);
headerParams.put("t", timeMillis + "");
headerParams.put("sign_method", "HMAC-SHA256");
headerParams.put("sign", sign);
headerParams.put("access_token", accessToken);
return headerParams;
}
}
......@@ -58,4 +58,6 @@ public class TuyaUtils {
}
return hash;
}
}
#项目名称
spring.application.name=smartDevices-platform-service
spring.application.name=glsx-tuya
#日志路径(logback-spring.xml读取,不要加入配置中心)
logging.path=/data/java_log/jetty/${spring.application.name}/${spring.application.name}.log
......
......@@ -37,9 +37,9 @@
</commentGenerator>
<!-- jdbc连接-->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.3.227:3306/cyb_os?serverTimeZone=Shanghai&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false"
userId="dev_admin"
password="1f7e1ed2">
connectionURL="jdbc:mysql://192.168.0.39:3306/neshield?serverTimeZone=Shanghai&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false"
userId="root"
password="123456">
<!--防止生成其他库同名表-->
<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>
......@@ -50,7 +50,7 @@
</javaTypeResolver>
<!-- 生成实体类地址 -->
<javaModelGenerator targetPackage="cn.com.glsx.modules.entity" targetProject="src/main/java">
<javaModelGenerator targetPackage="com.glsx.neshield.modules.entity" targetProject="src/main/java">
<!-- 是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="true"/>
<!-- 从数据库返回的值去掉前后空格 -->
......@@ -63,11 +63,11 @@
</sqlMapGenerator>
<!-- 生成接口dao type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象 type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象 type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
<javaClientGenerator targetPackage="cn.com.glsx.modules.mapper" targetProject="src/main/java" type="XMLMAPPER">
<javaClientGenerator targetPackage="com.glsx.neshield.modules.mapper" targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>
<!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 -->
<table tableName="tuya_user" domainObjectName="TuyaUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
<table tableName="t_user_path" domainObjectName="UserPath" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!