Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
smartDevices-platform-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 9d44fe6f
authored
Mar 05, 2021
by
周海宝
1
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'dev' into 'master'
Dev See merge request
!1
2 parents
cc68d0ce
ae4ea9d3
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
68 additions
and
51 deletions
pom.xml
src/main/java/cn/com/glsx/modules/controller/UserController.java
src/main/java/cn/com/glsx/modules/utils/AccessTokenService.java → src/main/java/cn/com/glsx/modules/service/AccessTokenService.java
src/main/java/cn/com/glsx/modules/service/UserService.java
src/main/java/cn/com/glsx/modules/utils/HeaderParamUtils.java
src/main/java/cn/com/glsx/modules/utils/TuyaUtils.java
src/main/resources/bootstrap.properties
src/main/resources/config/generatorConfig.xml
pom.xml
View file @
9d44fe6
...
...
@@ -40,6 +40,16 @@
<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>
...
...
src/main/java/cn/com/glsx/modules/controller/UserController.java
View file @
9d44fe6
...
...
@@ -5,6 +5,8 @@ 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
;
...
...
@@ -22,6 +24,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
*/
@Controller
@RequestMapping
(
"/user"
)
@Api
(
value
=
"用户模块"
,
tags
=
{
"用户模块"
})
public
class
UserController
{
@Autowired
...
...
@@ -35,6 +38,7 @@ 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
)){
...
...
@@ -52,6 +56,7 @@ 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
));
...
...
src/main/java/cn/com/glsx/modules/
utils
/AccessTokenService.java
→
src/main/java/cn/com/glsx/modules/
service
/AccessTokenService.java
View file @
9d44fe6
package
cn
.
com
.
glsx
.
modules
.
utils
;
package
cn
.
com
.
glsx
.
modules
.
service
;
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
;
...
...
@@ -12,7 +14,6 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.stereotype.Service
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
...
...
@@ -55,7 +56,7 @@ public class AccessTokenService {
String
access_Token
=
null
;
AccessToken
accessToken
=
accessTokenRedis
.
readCache
(
Constants
.
ACCESSTOKEN_REDISKEY
);
if
(
null
!=
accessToken
)
{
if
((
accessToken
.
getExpire_time
()
-
System
.
currentTimeMillis
())
>=
1000
*
60
*
60
*
2
)
{
if
((
System
.
currentTimeMillis
()-
accessToken
.
getExpire_time
())
>=
1000
*
60
*
60
*
2
)
{
ResponseBody
responseBody
=
sendRequestFlashToken
(
accessToken
.
getRefresh_token
());
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
...
...
@@ -91,13 +92,7 @@ public class AccessTokenService {
*/
private
ResponseBody
sendRequestFlashToken
(
String
flashtoken
)
{
ResponseBody
responseBody
=
null
;
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
);
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
);
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendGet
(
tokenFlashUrl
+
flashtoken
,
null
,
headerParams
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
...
...
@@ -115,13 +110,7 @@ public class AccessTokenService {
*/
private
ResponseBody
sendRequestGetToken
()
{
ResponseBody
responseBody
=
null
;
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
);
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
);
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendGet
(
getTokenUrl
,
null
,
headerParams
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
...
...
@@ -131,4 +120,6 @@ public class AccessTokenService {
}
return
responseBody
;
}
}
src/main/java/cn/com/glsx/modules/service/UserService.java
View file @
9d44fe6
package
cn
.
com
.
glsx
.
modules
.
service
;
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.mapper.TuyaUserMapper
;
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.
AccessTokenService
;
import
cn.com.glsx.modules.utils.
HeaderParamUtils
;
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
;
...
...
@@ -18,7 +15,6 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.stereotype.Service
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
...
...
@@ -35,9 +31,6 @@ 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
;
...
...
@@ -73,14 +66,7 @@ public class UserService {
private
ResponseBody
sendRequestRegisterUser
(
String
accessToken
,
UserBo
userBo
)
{
ResponseBody
responseBody
=
null
;
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
);
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
,
accessToken
);
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendPost
(
registerUserUrl
,
JSONObject
.
toJSONString
(
userBo
),
headerParams
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
...
...
@@ -115,14 +101,7 @@ public class UserService {
private
ResponseBody
sendRequestGetUserInfo
(
String
id
,
String
accessToken
)
{
ResponseBody
responseBody
=
null
;
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
);
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
,
accessToken
);
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendGet
(
getUserInfoUrl
.
replace
(
"{uid}"
,
id
),
null
,
headerParams
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
...
...
src/main/java/cn/com/glsx/modules/utils/HeaderParamUtils.java
0 → 100644
View file @
9d44fe6
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
;
}
}
src/main/java/cn/com/glsx/modules/utils/TuyaUtils.java
View file @
9d44fe6
...
...
@@ -58,6 +58,4 @@ public class TuyaUtils {
}
return
hash
;
}
}
src/main/resources/bootstrap.properties
View file @
9d44fe6
#项目名称
spring.application.name
=
glsx-tuya
spring.application.name
=
smartDevices-platform-service
#日志路径(logback-spring.xml读取,不要加入配置中心)
logging.path
=
/data/java_log/jetty/${spring.application.name}/${spring.application.name}.log
...
...
src/main/resources/config/generatorConfig.xml
View file @
9d44fe6
...
...
@@ -37,9 +37,9 @@
</commentGenerator>
<!-- jdbc连接-->
<jdbcConnection
driverClass=
"com.mysql.cj.jdbc.Driver"
connectionURL=
"jdbc:mysql://192.168.
0.39:3306/neshield
?serverTimeZone=Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false"
userId=
"
root
"
password=
"1
23456
"
>
connectionURL=
"jdbc:mysql://192.168.
3.227:3306/cyb_os
?serverTimeZone=Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false"
userId=
"
dev_admin
"
password=
"1
f7e1ed2
"
>
<!--防止生成其他库同名表-->
<property
name=
"nullCatalogMeansCurrent"
value=
"true"
/>
</jdbcConnection>
...
...
@@ -50,7 +50,7 @@
</javaTypeResolver>
<!-- 生成实体类地址 -->
<javaModelGenerator
targetPackage=
"c
om.glsx.neshield
.modules.entity"
targetProject=
"src/main/java"
>
<javaModelGenerator
targetPackage=
"c
n.com.glsx
.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=
"c
om.glsx.neshield
.modules.mapper"
targetProject=
"src/main/java"
type=
"XMLMAPPER"
>
<javaClientGenerator
targetPackage=
"c
n.com.glsx
.modules.mapper"
targetProject=
"src/main/java"
type=
"XMLMAPPER"
>
<property
name=
"enableSubPackages"
value=
"false"
/>
</javaClientGenerator>
<!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 -->
<table
tableName=
"t
_user_path"
domainObjectName=
"UserPath
"
enableCountByExample=
"false"
enableUpdateByExample=
"false"
enableDeleteByExample=
"false"
enableSelectByExample=
"false"
selectByExampleQueryId=
"false"
/>
<table
tableName=
"t
uya_user"
domainObjectName=
"TuyaUser
"
enableCountByExample=
"false"
enableUpdateByExample=
"false"
enableDeleteByExample=
"false"
enableSelectByExample=
"false"
selectByExampleQueryId=
"false"
/>
</context>
</generatorConfiguration>
\ No newline at end of file
@zhouhb
周海宝
@zhouhb
commented
Mar 05, 2021
Master
可以
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment