Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
map-parent
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
常超
map-parent
Commits
ab97d384
Commit
ab97d384
authored
Mar 28, 2024
by
yangyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
凯亚接口处理(海南)
parent
f8893b63
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
7 deletions
+126
-7
common/common_utils/src/main/java/com/founder/commonutils/util/KyTokenUtils.java
+121
-0
service/publicapi/src/main/java/com/founder/publicapi/controller/ImageController.java
+3
-2
service/publicapi/src/main/java/com/founder/publicapi/service/serviceimpl/ImageServiceImpl.java
+2
-5
No files found.
common/common_utils/src/main/java/com/founder/commonutils/util/KyTokenUtils.java
0 → 100644
View file @
ab97d384
package
com
.
founder
.
commonutils
.
util
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
jdk.nashorn.internal.runtime.logging.Logger
;
import
lombok.extern.java.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.http.HttpStatus
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
java.util.*
;
/**
* @ClassName: KyTokenUtils
* @Auther: yangyang
* @Description: java类作用描述
* @CreateDate: 2024-03-28
* @Version: 1.0
*/
@Component
@Log
public
class
KyTokenUtils
{
private
static
StringRedisTemplate
redisTemplate
;
@Autowired
public
void
setRestTemplate
(
StringRedisTemplate
redisTemplate
)
{
KyTokenUtils
.
redisTemplate
=
redisTemplate
;
}
/**
* 判断并获取新的token(海南凯亚)
* @return
*/
public
static
String
getHnKyToken
(){
String
result_token
=
null
;
try
{
// 1 先比较已有token是否过期或空
long
nowtime
=
new
Date
().
getTime
();
// 获取redis tokenKy
Map
<
Object
,
Object
>
redisMap
=
redisTemplate
.
opsForHash
().
entries
(
"tokenKy"
);
String
token
=
String
.
valueOf
(
redisMap
.
get
(
"token"
));
String
expiration
=
String
.
valueOf
(
redisMap
.
get
(
"expiration"
));
System
.
out
.
println
(
"得到的token: "
+
token
);
System
.
out
.
println
(
"得到的时间是: "
+
expiration
);
if
(
"null"
==
token
||
"null"
==
expiration
){
// 2 如果为空获取新的token值
result_token
=
readeWriteHnKyToken
(
nowtime
);
}
else
{
// 3 如果过期获取新的token值
if
(
nowtime
>
Long
.
valueOf
(
expiration
)){
result_token
=
readeWriteHnKyToken
(
nowtime
);
}
else
{
result_token
=
token
;
}
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
log
.
info
(
e
.
getMessage
());
}
return
result_token
;
}
// 读和写海南凯亚的token值
public
static
String
readeWriteHnKyToken
(
long
nowtime
){
String
result_token
=
""
;
String
token_url
=
"http://74.10.30.174:18093"
;
String
username
=
"xingjdj"
;
//如果过期先获取新的token值
Map
headerMap
=
new
HashMap
();
headerMap
.
put
(
"login-channel"
,
"API"
);
String
clientUid
=
getClientUid
(
token_url
);
// 随机码
String
password
=
RsaUtil
.
sign
(
clientUid
+
"."
+
username
);
// 随机码+“.”+用户名 RSA私钥进行SHA1WithRSA数字签名
JSONObject
object
=
new
JSONObject
();
object
.
put
(
"username"
,
username
);
object
.
put
(
"password"
,
password
);
object
.
put
(
"clientUid"
,
clientUid
);
try
{
String
resultString
=
com
.
founder
.
commonutils
.
util
.
HttpClient
.
doPostJson
(
token_url
+
"/auth/login"
,
headerMap
,
JSONObject
.
toJSONString
(
object
));
if
(!
StringUtils
.
isEmpty
(
resultString
))
{
JSONObject
result
=
JSONObject
.
parseObject
(
resultString
);
if
(
result
.
getInteger
(
"code"
)==
200
){
JSONObject
resultData
=
result
.
getJSONObject
(
"data"
);
result_token
=
resultData
.
getString
(
"authorization"
);
String
expires_in
=
resultData
.
getString
(
"expireTime"
);
//有效时间段 单位为秒 1800秒
String
result_expiration
=
nowtime
+
Integer
.
parseInt
(
expires_in
)*
1000
+
""
;
// 写入新的token值和本次token的过期时间
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"token"
,
result_token
);
map
.
put
(
"expiration"
,
result_expiration
);
redisTemplate
.
opsForHash
().
putAll
(
"tokenKy"
,
map
);
}
else
{
return
result
.
getString
(
"msg"
);
}
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
log
.
info
(
"获取token错误"
+
e
.
getMessage
());
}
return
result_token
;
}
// 获取海南凯亚的clientUid
public
static
String
getClientUid
(
String
token_url
){
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
HttpUtil
.
doGet
(
token_url
+
"/auth/getClientUid"
));
return
jsonObject
.
getString
(
"clientUid"
);
}
}
service/publicapi/src/main/java/com/founder/publicapi/controller/ImageController.java
View file @
ab97d384
...
...
@@ -4,6 +4,7 @@ import com.founder.commonutils.carEntity.CarKkXxParams;
import
com.founder.commonutils.peopleEntity.CameraFaceTask
;
import
com.founder.commonutils.peopleEntity.FaceSearchParam
;
import
com.founder.commonutils.publicEntity.MapRestResult
;
import
com.founder.commonutils.util.KyTokenUtils
;
import
com.founder.commonutils.util.TokenUtils
;
import
com.founder.publicapi.service.ImageService
;
import
com.founder.servicebase.logs.OperLog
;
...
...
@@ -37,10 +38,10 @@ public class ImageController {
@OperLog
(
message
=
"token获取"
,
operation
=
OperationType
.
QUERY
)
@ApiOperation
(
value
=
"token获取"
)
@
Pos
tMapping
(
"/token"
)
@
Ge
tMapping
(
"/token"
)
public
MapRestResult
getToken
()
{
//获取token
String
accessToken
=
TokenUtils
.
getHnKyToken
();
String
accessToken
=
Ky
TokenUtils
.
getHnKyToken
();
return
MapRestResult
.
build
(
200
,
"成功获取token信息"
,
"1"
,
accessToken
);
}
...
...
service/publicapi/src/main/java/com/founder/publicapi/service/serviceimpl/ImageServiceImpl.java
View file @
ab97d384
...
...
@@ -4,10 +4,7 @@ import com.alibaba.fastjson.JSONArray;
import
com.alibaba.fastjson.JSONObject
;
import
com.founder.commonutils.peopleEntity.*
;
import
com.founder.commonutils.publicEntity.MapRestResult
;
import
com.founder.commonutils.util.DataUtil
;
import
com.founder.commonutils.util.HttpClient
;
import
com.founder.commonutils.util.HttpUtil
;
import
com.founder.commonutils.util.TokenUtils
;
import
com.founder.commonutils.util.*
;
import
com.founder.publicapi.oracleXzxtMapper.CameraInfoMapper
;
import
com.founder.publicapi.service.ImageService
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -358,7 +355,7 @@ public class ImageServiceImpl implements ImageService {
}
// token获取
public
Map
getToken
(){
String
token
=
TokenUtils
.
getHnKyToken
();
String
token
=
Ky
TokenUtils
.
getHnKyToken
();
Map
herders
=
new
HashMap
();
//设置请求的header参数
herders
.
put
(
"Authorization"
,
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