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
6dfc6f61
Commit
6dfc6f61
authored
Dec 23, 2020
by
汪昱
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
金安易-临安区村级小微权力智慧监管平台数据接口,增加请求heard
parent
81c5a1ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
24 deletions
+37
-24
JAYSmartController.java
.../com/mth/requestsecret/controller/JAYSmartController.java
+37
-24
No files found.
src/main/java/com/mth/requestsecret/controller/JAYSmartController.java
View file @
6dfc6f61
package
com
.
mth
.
requestsecret
.
controller
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.http.client.methods.HttpHead
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.core.io.Resource
;
...
...
@@ -52,6 +53,7 @@ public class JAYSmartController {
.
append
(
"&apiName=onlyOrganize"
).
toString
();
log
.
info
(
"访问临安区村级小微权力平台数据接口/获取单位列表 -->"
+
url
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"x-real-ip"
,
"101.69.248.16"
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
headers
);
return
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
request
,
String
.
class
);
}
...
...
@@ -72,7 +74,9 @@ public class JAYSmartController {
.
append
(
"&year="
).
append
(
null
==
year
?
""
:
year
)
.
append
(
"&apiName=onlyOrganize"
).
toString
();
log
.
info
(
"访问临安区村级小微权力平台数据接口/获取公开表数据 -->"
+
url
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
new
HttpHeaders
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"x-real-ip"
,
"101.69.248.16"
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
headers
);
return
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
request
,
String
.
class
);
}
...
...
@@ -88,7 +92,9 @@ public class JAYSmartController {
.
append
(
authCode
)
.
append
(
"&unitCode="
).
append
(
unitCode
).
toString
();
log
.
info
(
"访问临安区村级小微权力平台数据接口/获取村级工程 -->"
+
url
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
new
HttpHeaders
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"x-real-ip"
,
"101.69.248.16"
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
headers
);
return
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
request
,
String
.
class
);
}
...
...
@@ -104,7 +110,9 @@ public class JAYSmartController {
.
append
(
authCode
)
.
append
(
"&unitCode="
).
append
(
unitCode
).
toString
();
log
.
info
(
"访问临安区村级小微权力平台数据接口/获取村级工程付款情况表数据 -->"
+
url
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
new
HttpHeaders
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"x-real-ip"
,
"101.69.248.16"
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
headers
);
return
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
request
,
String
.
class
);
}
...
...
@@ -120,7 +128,9 @@ public class JAYSmartController {
.
append
(
authCode
)
.
append
(
"&unitCode="
).
append
(
unitCode
).
toString
();
log
.
info
(
"访问临安区村级小微权力平台数据接口/获取资产资源处置表数据 -->"
+
url
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
new
HttpHeaders
());
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"x-real-ip"
,
"101.69.248.16"
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
headers
);
return
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
request
,
String
.
class
);
}
...
...
@@ -132,7 +142,10 @@ public class JAYSmartController {
RestTemplate
template
=
restTemplateBuilder
.
basicAuthentication
(
username
,
password
,
Charset
.
forName
(
"UTF-8"
)).
build
();
ResponseEntity
<
Resource
>
entity
=
template
.
postForEntity
(
url
,
null
,
Resource
.
class
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"x-real-ip"
,
"101.69.248.16"
);
HttpEntity
<
HashMap
<
String
,
Object
>>
httpEntity
=
new
HttpEntity
<>(
null
,
headers
);
ResponseEntity
<
Resource
>
entity
=
template
.
postForEntity
(
url
,
httpEntity
,
Resource
.
class
);
InputStream
bis
=
null
;
OutputStream
outputStream
=
null
;
...
...
@@ -140,7 +153,6 @@ public class JAYSmartController {
bis
=
entity
.
getBody
().
getInputStream
();
outputStream
=
response
.
getOutputStream
();
// DataInputStream dataInputStream = new DataInputStream(bis);
String
filename
=
contractAddr
.
substring
(
contractAddr
.
lastIndexOf
(
"/"
)
+
1
);
// 解决文件名乱码问题,获取浏览器类型,转换对应文件名编码格式,IE要求文件名必须是utf-8, firefo要求是iso-8859-1编码
...
...
@@ -151,8 +163,6 @@ public class JAYSmartController {
filename
=
URLEncoder
.
encode
(
filename
,
"UTF-8"
);
}
log
.
info
(
"访问临安区村级小微权力平台数据接口/下载合同文书 -->"
+
url
+
";文件 -->"
+
filename
);
// String path = "D:/wangy/test/" + file;
// FileOutputStream fileOutputStream = new FileOutputStream(new File(path));
// 设置下载文件的mineType,告诉浏览器下载文件类型
String
mineType
=
request
.
getServletContext
().
getMimeType
(
filename
);
...
...
@@ -165,26 +175,29 @@ public class JAYSmartController {
outputStream
.
write
(
buffer
,
0
,
length
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
log
.
info
(
"访问临安区村级小微权力平台数据接口,下载合同文书异常"
);
log
.
info
(
"访问临安区村级小微权力平台数据接口,下载合同文书异常"
,
e
);
}
finally
{
if
(
outputStream
!=
null
)
{
try
{
outputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
bis
!=
null
)
{
try
{
bis
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
closeStream
(
bis
,
outputStream
);
}
return
ResponseEntity
.
ok
(
"下载成功!"
);
}
private
void
closeStream
(
InputStream
bis
,
OutputStream
outputStream
)
{
if
(
outputStream
!=
null
)
{
try
{
outputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
bis
!=
null
)
{
try
{
bis
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
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