Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zh-baseversion-project
Project
Project
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
王浩
zh-baseversion-project
Commits
01e11ff7
Commit
01e11ff7
authored
May 06, 2024
by
zhangjianqian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
省接口对接
parent
6e94daed
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
239 additions
and
1 deletion
+239
-1
HttpClient.java
...c/main/java/com/zehong/web/controller/api/HttpClient.java
+74
-0
OutUtil.java
.../src/main/java/com/zehong/web/controller/api/OutUtil.java
+92
-0
TokenController.java
...n/java/com/zehong/web/controller/api/TokenController.java
+63
-0
application-test.yml
zh-baseversion-admin/src/main/resources/application-test.yml
+9
-0
SecurityConfig.java
...main/java/com/zehong/framework/config/SecurityConfig.java
+1
-1
No files found.
zh-baseversion-admin/src/main/java/com/zehong/web/controller/api/HttpClient.java
View file @
01e11ff7
...
...
@@ -269,6 +269,80 @@ public class HttpClient {
return
result
;
}
/**
* 发送POST请求
* @param url
* @return JSON或者字符串
* @throws Exception
*/
public
static
<
JSONObject
>
Object
sendPostJson
(
String
url
,
com
.
alibaba
.
fastjson
.
JSONObject
json
,
String
token
)
throws
Exception
{
JSONObject
jsonObject
=
null
;
CloseableHttpClient
client
=
null
;
CloseableHttpResponse
response
=
null
;
try
{
/**
* 创建一个httpclient对象
*/
client
=
HttpClients
.
createDefault
();
/**
* 创建一个post对象
*/
HttpPost
post
=
new
HttpPost
(
url
);
/**
* 包装成一个Entity对象
*/
StringEntity
entity
=
new
StringEntity
(
json
.
toString
());
entity
.
setContentType
(
"application/json; charset=utf-8"
);
/**
* 设置请求的内容
*/
post
.
setEntity
(
entity
);
/**
* 设置请求的报文头部的编码
*/
post
.
setHeader
(
new
BasicHeader
(
"Content-Type"
,
"application/json; charset=utf-8"
));
/**
* 设置请求的报文头部的编码
*/
post
.
setHeader
(
new
BasicHeader
(
"Accept"
,
"application/json;charset=utf-8"
));
//需要时传token
if
(
token
!=
null
){
post
.
setHeader
(
"authorization"
,
token
);
}
/**
* 执行post请求
*/
response
=
client
.
execute
(
post
);
/**
* 获取响应码
*/
int
statusCode
=
response
.
getStatusLine
().
getStatusCode
();
if
(
SUCCESS_CODE
==
statusCode
){
/**
* 通过EntityUitls获取返回内容
*/
String
result
=
EntityUtils
.
toString
(
response
.
getEntity
(),
"UTF-8"
);
/**
* 转换成json,根据合法性返回json或者字符串
*/
try
{
jsonObject
=
(
JSONObject
)
com
.
alibaba
.
fastjson
.
JSONObject
.
parseObject
(
result
);
return
jsonObject
;
}
catch
(
Exception
e
){
return
result
;
}
}
else
{
LOGGER
.
error
(
"HttpClientService-line: {}, errorMsg:{}"
,
146
,
"POST请求失败!"
);
}
}
catch
(
Exception
e
){
LOGGER
.
error
(
"HttpClientService-line: {}, Exception:{}"
,
149
,
e
);
}
finally
{
response
.
close
();
client
.
close
();
}
return
null
;
}
}
zh-baseversion-admin/src/main/java/com/zehong/web/controller/api/OutUtil.java
0 → 100644
View file @
01e11ff7
package
com
.
zehong
.
web
.
controller
.
api
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zehong.common.core.redis.RedisCache
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
@Component
public
class
OutUtil
{
@Autowired
private
RedisCache
redisCache
;
@Value
(
"${zhengfu.appId}"
)
private
String
appId
;
@Value
(
"${zhengfu.appSecret}"
)
private
String
appSecret
;
@Value
(
"${zhengfu.tokenUrl}"
)
private
String
tokenUrl
;
@Value
(
"${zhengfu.apiUrl}"
)
private
String
apiUrl
;
/**
* 获取token
* @return
* @throws Exception
*/
public
String
getToken
()
throws
Exception
{
String
token
=
(
String
)
redisCache
.
getCacheObject
(
"apiToken"
);
if
(
token
!=
null
){
token
=
getNewToken
();
}
return
token
;
}
/**
* 获取接口参数
* @return
* @throws Exception
*/
public
JSONObject
getInfo
(
String
domain
,
String
methodType
,
Map
<
String
,
Object
>
map
)
throws
Exception
{
String
token
=
(
String
)
redisCache
.
getCacheObject
(
"apiToken"
);
if
(
token
==
null
){
token
=
getNewToken
();
}
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"domain"
,
domain
);
json
.
put
(
"method"
,
methodType
);
json
.
put
(
"condition"
,
map
);
JSONObject
jobct
=
(
JSONObject
)
HttpClient
.
sendPostJson
(
apiUrl
,
json
,
token
);
return
jobct
;
}
/**
* 上传数据
* @param methodType
* @param list
* @return
* @throws Exception
*/
public
JSONObject
setInfo
(
String
domain
,
String
methodType
,
List
<
Map
<
String
,
Object
>>
list
)
throws
Exception
{
String
token
=
(
String
)
redisCache
.
getCacheObject
(
"apiToken"
);
if
(
token
==
null
){
token
=
getNewToken
();
}
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"domain"
,
domain
);
json
.
put
(
"method"
,
methodType
);
json
.
put
(
"data"
,
list
);
JSONObject
jobct
=
(
JSONObject
)
HttpClient
.
sendPostJson
(
apiUrl
,
json
,
token
);
return
jobct
;
}
public
String
getNewToken
()
throws
Exception
{
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"appId"
,
appId
);
json
.
put
(
"appSecret"
,
appSecret
);
JSONObject
jobct
=
(
JSONObject
)
HttpClient
.
sendPostJson
(
tokenUrl
,
json
,
null
);
redisCache
.
setCacheObject
(
"apiToken"
,(
String
)((
Map
<
String
,
Object
>)
jobct
.
get
(
"data"
)).
get
(
"accessToken"
),
7000
,
TimeUnit
.
SECONDS
);
return
(
String
)((
Map
<
String
,
Object
>)
jobct
.
get
(
"data"
)).
get
(
"accessToken"
);
}
}
zh-baseversion-admin/src/main/java/com/zehong/web/controller/api/TokenController.java
0 → 100644
View file @
01e11ff7
package
com
.
zehong
.
web
.
controller
.
api
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zehong.common.core.domain.AjaxResult
;
import
com.zehong.common.core.redis.RedisCache
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
@RestController
@RequestMapping
(
"/token"
)
public
class
TokenController
{
@Autowired
private
OutUtil
outUtil
;
/**
* 获取营业执照
* @return
* @throws Exception
*/
@GetMapping
(
value
=
"/getInfo"
)
public
AjaxResult
getInfo
()
throws
Exception
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"updateTime"
,
"2022-11-28 14:01:00"
);
map
.
put
(
"pageSize"
,
100
);
map
.
put
(
"pageIndex"
,
1
);
map
.
put
(
"cityId"
,
10000010
);
String
domain
=
"region/county/information"
;
JSONObject
json
=
outUtil
.
getInfo
(
domain
,
"READ"
,
map
);
return
AjaxResult
.
success
(
json
);
}
@GetMapping
(
value
=
"/setInfo"
)
public
AjaxResult
setInfo
()
throws
Exception
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"id"
,
"111"
);
map
.
put
(
"idNo"
,
"321323198802116876"
);
map
.
put
(
"expertEval"
,
"的好的"
);
map
.
put
(
"selectionEvent"
,
"没问题的"
);
map
.
put
(
"selectionStartTime"
,
"2024-04-05"
);
map
.
put
(
"scorDesc"
,
"巴适哦"
);
map
.
put
(
"updateTime"
,
"2024-04-05"
);
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
list
.
add
(
map
);
String
domain
=
"professor/application/information"
;
JSONObject
json
=
outUtil
.
setInfo
(
domain
,
"WRITE"
,
list
);
return
AjaxResult
.
success
(
json
);
}
}
zh-baseversion-admin/src/main/resources/application-test.yml
View file @
01e11ff7
...
...
@@ -102,3 +102,12 @@ zehong:
addressEnabled
:
false
# 验证码类型 math 数组计算 char 字符验证
captchaType
:
math
zhengfu
:
#appId
appId
:
6e2c7b5a4g1h0fd9
#appSecret
appSecret
:
b5baee3c8b9bfea4efce1cb0cd3fe5ab
#tokenurl
tokenUrl
:
http://test.zfcxjst.hebei.gov.cn:8082/openApi/authorization/api-entry/v1/getAccessToken
#链接访问地址
apiUrl
:
http://test.zfcxjst.hebei.gov.cn:8082/openApi/index/sync/v1/entrypoint
zh-baseversion-framework/src/main/java/com/zehong/framework/config/SecurityConfig.java
View file @
01e11ff7
...
...
@@ -98,7 +98,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 过滤请求
.
authorizeRequests
()
// 对于登录login 验证码captchaImage 允许匿名访问
.
antMatchers
(
"/login"
,
"/captchaImage"
,
"/websocket/**"
,
"/websocketServer"
,
"/detector/detectorReport/**"
,
"/getout/**"
).
anonymous
()
.
antMatchers
(
"/login"
,
"/captchaImage"
,
"/websocket/**"
,
"/websocketServer"
,
"/detector/detectorReport/**"
,
"/getout/**"
,
"/token/**"
).
anonymous
()
.
antMatchers
(
HttpMethod
.
GET
,
"/*.html"
,
...
...
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