Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jiwei-api
Project
Project
Details
Activity
Releases
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
马天浩
jiwei-api
Commits
7f1123b0
Commit
7f1123b0
authored
Dec 03, 2020
by
matianhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[资产资源接口] <add> 调用js加解密,接入获取项目信息接口
parent
3d120729
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
336 additions
and
0 deletions
+336
-0
ZczyController.java
...java/com/mth/requestsecret/controller/ZczyController.java
+44
-0
RestTemplateService.java
...va/com/mth/requestsecret/service/RestTemplateService.java
+34
-0
AESUtils.java
src/main/java/com/mth/requestsecret/util/AESUtils.java
+37
-0
des.js
src/main/resources/js/des.js
+221
-0
No files found.
src/main/java/com/mth/requestsecret/controller/ZczyController.java
0 → 100644
View file @
7f1123b0
package
com
.
mth
.
requestsecret
.
controller
;
import
com.mth.requestsecret.service.RestTemplateService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 资产资源接口
*
* @author MaTianHao
* @date 2020/11/23
*/
@RestController
@Slf4j
public
class
ZczyController
{
@Autowired
private
RestTemplateService
restTemplateService
;
/**
* 获取项目信息接口
* 根据时间段获取成交项目信息,时间跨度不能超过5天
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return 解密后字符串
*/
@PostMapping
(
"/getProjectBaseInformation"
)
public
String
getProjectBaseInformation
(
String
startTime
,
String
endTime
)
throws
Exception
{
// api方法签名
String
apiMethod
=
"fGetProjectBaseInformation"
;
// api参数
Map
<
String
,
String
>
param
=
new
HashMap
<>(
2
);
param
.
put
(
"StartTime"
,
startTime
);
param
.
put
(
"EndTime"
,
endTime
);
return
restTemplateService
.
zczySendRequest
(
param
,
apiMethod
);
}
}
src/main/java/com/mth/requestsecret/service/RestTemplateService.java
View file @
7f1123b0
...
...
@@ -65,6 +65,12 @@ public class RestTemplateService {
@Value
(
"${buildhouse.address}"
)
private
String
buildHouseAddress
;
/**
* 资产资源接口地址
*/
@Value
((
"${zczy.address}"
))
private
String
zczyAddress
;
/**
* 瑞成平台接口发送请求
*
...
...
@@ -241,4 +247,32 @@ public class RestTemplateService {
return
responseEntity
;
}
/**
* 资产资源接口 发送请求
*/
public
String
zczySendRequest
(
Map
<
String
,
String
>
paramMap
,
String
apiMethod
)
throws
Exception
{
String
url
=
zczyAddress
+
apiMethod
;
log
.
info
(
"资产资源api:{}"
,
apiMethod
);
log
.
info
(
"api url:{}"
,
url
);
log
.
info
(
"api params:{}"
,
paramMap
);
// 1. 参数加密
paramMap
.
replace
(
"StartTime"
,
AESUtils
.
zczyDes
(
paramMap
.
get
(
"StartTime"
),
"encMe"
));
paramMap
.
replace
(
"EndTime"
,
AESUtils
.
zczyDes
(
paramMap
.
get
(
"EndTime"
),
"encMe"
));
// 2. 构建请求头
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
HttpEntity
httpEntity
=
new
HttpEntity
<>(
paramMap
,
headers
);
// 3. 发送请求
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
// 响应解密
String
decryptResponse
=
AESUtils
.
zczyDes
(
responseEntity
.
getBody
(),
"uncMe"
);
String
decryptStr
=
decryptResponse
.
trim
();
log
.
info
(
"api response:{}"
,
decryptStr
);
return
decryptStr
;
}
}
\ No newline at end of file
src/main/java/com/mth/requestsecret/util/AESUtils.java
View file @
7f1123b0
...
...
@@ -9,6 +9,10 @@ import javax.crypto.SecretKeyFactory;
import
javax.crypto.spec.DESedeKeySpec
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
import
javax.script.Invocable
;
import
javax.script.ScriptEngine
;
import
javax.script.ScriptEngineManager
;
import
java.io.FileReader
;
import
java.nio.charset.StandardCharsets
;
import
java.security.Key
;
import
java.security.Security
;
...
...
@@ -42,6 +46,12 @@ public class AESUtils {
*/
private
final
static
byte
[]
SGB_IV
=
{(
byte
)
0x12
,
(
byte
)
0x34
,
(
byte
)
0x56
,
(
byte
)
0x78
,
(
byte
)
0x90
,
(
byte
)
0xAB
,
(
byte
)
0xCD
,
(
byte
)
0xEF
};
// 资产资源加密参数
/**
* key
*/
private
final
static
String
ZCZY_KEY
=
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4"
;
static
{
Security
.
addProvider
(
new
BouncyCastleProvider
());
}
...
...
@@ -132,6 +142,33 @@ public class AESUtils {
}
}
/**
* 资产资源接口:des加密、解密
*
* @param content 待处理字符串
* @param method 加密:encMe;解密:uncMe
* @return
* @throws Exception
*/
public
static
String
zczyDes
(
String
content
,
String
method
)
throws
Exception
{
ScriptEngineManager
manager
=
new
ScriptEngineManager
();
ScriptEngine
engine
=
manager
.
getEngineByName
(
"javascript"
);
// 读取js文件
FileReader
reader
=
new
FileReader
(
"src/main/resources/js/des.js"
);
engine
.
eval
(
reader
);
String
encryptContent
=
""
;
if
(
engine
instanceof
Invocable
)
{
Invocable
invoke
=
(
Invocable
)
engine
;
// 调用js函数
encryptContent
=
(
String
)
invoke
.
invokeFunction
(
method
,
content
,
ZCZY_KEY
);
}
reader
.
close
();
return
encryptContent
;
}
/**
* 16进制字符串转字节数组
*
...
...
src/main/resources/js/des.js
0 → 100644
View file @
7f1123b0
This diff is collapsed.
Click to expand it.
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