Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-fb
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王衍超
cloud-fb
Commits
0e8cec42
Commit
0e8cec42
authored
Apr 25, 2022
by
yanHeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[初始化] wuLink对接
parent
f1a6e64a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
168 additions
and
6 deletions
+168
-6
common.gradle
backend/common.gradle
+9
-1
GpsWuLingUtil.java
.../main/java/com/beecode/inz/common/util/GpsWuLingUtil.java
+6
-5
build.gradle
backend/xyst.dinas.camera/build.gradle
+1
-0
IotPlatformUtils.java
...java/com/xyst/dinas/camera/constant/IotPlatformUtils.java
+101
-0
IotPlatformController.java
...java/com/xyst/dinas/camera/web/IotPlatformController.java
+51
-0
No files found.
backend/common.gradle
View file @
0e8cec42
...
...
@@ -67,6 +67,8 @@ ext {
micrometerRegistryVersion
=
"1.0.4"
poiTlVersion
=
"1.5.0"
cxfVersion
=
"3.1.6"
websocketVersion
=
"1.5.2"
lib
=
[
/* jiuqi next platform */
np_authz:
"com.jiuqi:np.authz:${npAuthzVersion}"
,
...
...
@@ -251,7 +253,9 @@ ext {
hibernate_common_annotations:
"org.hibernate.common:hibernate-commons-annotations:5.0.4.Final"
,
net_byte_buddy:
"net.bytebuddy:byte-buddy:1.8.15"
,
thumbnailator:
"net.coobird:thumbnailator:0.4.8"
thumbnailator:
"net.coobird:thumbnailator:0.4.8"
,
websocket:
"org.java-websocket:Java-WebSocket:${websocketVersion}"
]
}
...
...
@@ -413,6 +417,10 @@ configurations.all {
force
lib
.
net_byte_buddy
force
lib
.
thumbnailator
/* websocket */
force
lib
.
websocket
exclude
group:
"c3p0"
,
module:
"c3p0"
exclude
group:
"dom4j"
,
module:
"dom4j"
exclude
group:
"com.vaadin.external.google"
,
module:
"android-json"
...
...
backend/inz.common/src/main/java/com/beecode/inz/common/util/GpsWuLingUtil.java
View file @
0e8cec42
...
...
@@ -3,6 +3,7 @@ package com.beecode.inz.common.util;
import
org.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.apache.commons.lang.StringUtils
;
import
java.nio.charset.StandardCharsets
;
...
...
@@ -56,10 +57,10 @@ public class GpsWuLingUtil {
* @throws Exception
*/
public
static
String
getTokenByAccount
()
throws
Exception
{
//
String token = RedisUtils.getInstance().get(getGpsWuLingTokenRedisKey(CLIET_ID, CLIENT_SECRET));
//
if(StringUtils.isNotEmpty(token)){
//
return token;
//
}else {
String
token
=
RedisUtils
.
getInstance
().
get
(
getGpsWuLingTokenRedisKey
(
CLIET_ID
,
CLIENT_SECRET
));
if
(
StringUtils
.
isNotEmpty
(
token
)){
return
token
;
}
else
{
String
sendParam
=
"grant_type="
+
GRANT_TYPE
+
"&client_id="
+
CLIET_ID
+
"&client_secret="
+
CLIENT_SECRET
;
String
sendPost
=
HttpSendUtil
.
sendPost
(
TOKEN_URL
,
sendParam
,
StandardCharsets
.
UTF_8
.
name
());
...
...
@@ -71,7 +72,7 @@ public class GpsWuLingUtil {
}
else
{
logger
.
error
(
"请求GPSWuLink获取token出错,错误信息"
+
postStr
.
get
(
"msg"
));
}
//
}
}
return
null
;
}
...
...
backend/xyst.dinas.camera/build.gradle
View file @
0e8cec42
...
...
@@ -8,6 +8,7 @@ dependencies {
compile
lib
.
jackson_datatype_jdk8
compile
lib
.
jackson_datatype_jsr310
compile
lib
.
json
compile
lib
.
websocket
compile
"com.beecode:bap2.participant:${aminoVersion}"
compile
"com.beecode:bcp.org:${aminoVersion}"
compile
"com.beecode:bap2.department:${aminoVersion}"
...
...
backend/xyst.dinas.camera/src/main/java/com/xyst/dinas/camera/constant/IotPlatformUtils.java
0 → 100644
View file @
0e8cec42
package
com
.
xyst
.
dinas
.
camera
.
constant
;
import
com.beecode.inz.common.util.HttpSendUtil
;
import
com.beecode.inz.common.util.RedisUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.json.JSONObject
;
import
org.springframework.stereotype.Component
;
import
java.nio.charset.StandardCharsets
;
import
java.util.HashMap
;
/**
* Description:IOT平台对接工具类
*
* @author 孟庆鑫
* @version 1.0
* @date: 2021/7/13 15:06
*/
@Component
public
class
IotPlatformUtils
{
public
static
String
getGpsWuLingTokenRedisKey
(
String
clietId
,
String
clientSecret
)
{
return
"gps_wu_link_token_key"
+
clietId
+
"_"
+
clientSecret
;
}
//获取token必填参数 如下三个
private
static
final
String
GRANT_TYPE
=
"client_credentials"
;
private
static
final
String
CLIET_ID
=
"jt808"
;
private
static
final
String
CLIENT_SECRET
=
"f04dd1e4"
;
private
static
final
String
GPS_WU_LING_DOMAIN
=
"http://dev.kunlun.cloud/iot/"
;
/**
* 获取tokenUrl
*/
private
static
final
String
TOKEN_URL
=
GPS_WU_LING_DOMAIN
+
"oauth/token"
;
/**
* 根据设备序列号获取id
*/
private
static
final
String
FIND_GATEWAY_ID_URL
=
GPS_WU_LING_DOMAIN
+
"gateway/api/findGatewayId"
;
/**
* 根据设备id查询⽹关指标信息
*/
private
static
final
String
GATEWAYINDICATORS_URL
=
GPS_WU_LING_DOMAIN
+
"gateway/api/gatewayIndicators"
;
/**
* 历史轨迹URL
*/
private
static
final
String
HISTORY_URL
=
GPS_WU_LING_DOMAIN
+
"devices/history"
;
/**
* Description:获取平台accesstoken
*
* @author 孟庆鑫
* @date 2021/7/13 16:45
* @return: 0:请求正常 -1:clientId或clientSecret为空 -2:请求accessToken服务器异常
*/
public
HashMap
<
String
,
Object
>
getAuthToken
(
String
clientId
,
String
clientSecret
)
throws
Exception
{
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
if
(
StringUtils
.
isBlank
(
clientId
)
||
StringUtils
.
isBlank
(
clientSecret
))
{
//clientId和clientSecret不能为空
map
.
put
(
"status"
,
-
1
);
map
.
put
(
"message"
,
"当前项目未注册IOT平台"
);
return
map
;
}
String
accessTokenData
=
null
;
try
{
accessTokenData
=
RedisUtils
.
getInstance
().
get
(
getGpsWuLingTokenRedisKey
(
CLIET_ID
,
CLIENT_SECRET
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
//优先从redis缓存拿
if
(
StringUtils
.
isNotBlank
(
accessTokenData
))
{
map
.
put
(
"status"
,
0
);
map
.
put
(
"data"
,
accessTokenData
);
return
map
;
}
String
sendParam
=
"grant_type="
+
GRANT_TYPE
+
"&client_id="
+
CLIET_ID
+
"&client_secret="
+
CLIENT_SECRET
;
String
sendPost
=
HttpSendUtil
.
sendPost
(
TOKEN_URL
,
sendParam
,
StandardCharsets
.
UTF_8
.
name
());
JSONObject
postStr
=
new
JSONObject
(
sendPost
);
String
accessToken
=
postStr
.
getString
(
"access_token"
);
if
(
accessToken
!=
null
)
{
RedisUtils
.
getInstance
().
set
(
getGpsWuLingTokenRedisKey
(
CLIET_ID
,
CLIENT_SECRET
),
accessToken
,
postStr
.
getInt
(
"expires_in"
)-
3
);
map
.
put
(
"status"
,
0
);
map
.
put
(
"data"
,
accessToken
);
return
map
;
}
else
{
//获取accesstoken异常
map
.
put
(
"status"
,
-
2
);
map
.
put
(
"message"
,
"IOT平台返回错误"
);
return
map
;
}
}
}
backend/xyst.dinas.camera/src/main/java/com/xyst/dinas/camera/web/IotPlatformController.java
0 → 100644
View file @
0e8cec42
package
com
.
xyst
.
dinas
.
camera
.
web
;
import
com.beecode.inz.basis.team.pojo.ResponseObj
;
import
com.xyst.dinas.camera.constant.IotPlatformUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.HashMap
;
/**
* Description:对接IOT平台controller
* @param
* @author yanHeng
* @version 1.0
* @date: 2021/7/15 9:37
*/
@RestController
@RequestMapping
(
"/iotplatform"
)
public
class
IotPlatformController
{
//获取token必填参数 如下三个
private
static
final
String
GRANT_TYPE
=
"client_credentials"
;
private
static
final
String
CLIET_ID
=
"jt808"
;
private
static
final
String
CLIENT_SECRET
=
"f04dd1e4"
;
@Autowired
private
IotPlatformUtils
iotPlatformUtils
;
/**Description:从IOT平台获取access_token
* @Author yanHeng
* @Date 2022/4/24 18:25
* @Param []
* @return com.beecode.inz.basis.team.pojo.ResponseObj
**/
@GetMapping
(
"/getAccessToken"
)
public
ResponseObj
getAccessToken
()
throws
Exception
{
HashMap
<
String
,
Object
>
tokenMap
=
iotPlatformUtils
.
getAuthToken
(
CLIET_ID
,
CLIENT_SECRET
);
if
((
int
)
tokenMap
.
get
(
"status"
)
==
-
1
||
(
int
)
tokenMap
.
get
(
"status"
)
==
-
2
)
{
return
ResponseObj
.
success
(
"获取失败"
,
tokenMap
.
get
(
"message"
).
toString
());
}
else
{
String
token
=
tokenMap
.
get
(
"data"
).
toString
();
return
ResponseObj
.
success
(
"获取成功"
,
token
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment