Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InternalLogic
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
CrossProvincialPlatform
InternalLogic
Commits
ff36fb7b
Commit
ff36fb7b
authored
Sep 28, 2023
by
张俊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化
parent
9191b2e8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
187 deletions
+36
-187
src/main/java/net/cdkj/gjj/adapter/controller/ProvidentFundServicesController.java
...j/adapter/controller/ProvidentFundServicesController.java
+28
-176
src/main/java/net/cdkj/gjj/adapter/utils/HttpUtil.java
src/main/java/net/cdkj/gjj/adapter/utils/HttpUtil.java
+8
-11
No files found.
src/main/java/net/cdkj/gjj/adapter/controller/ProvidentFundServicesController.java
View file @
ff36fb7b
...
...
@@ -3,13 +3,12 @@ package net.cdkj.gjj.adapter.controller;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.alibaba.fastjson.JSONObject
;
import
net.cdkj.gjj.adapter.config.JasyptConfig
;
import
net.cdkj.gjj.adapter.domain.BusinessProcessing
;
import
net.cdkj.gjj.adapter.domain.Json
;
import
net.cdkj.gjj.adapter.domain.PropertyqUtil
;
import
net.cdkj.gjj.adapter.domain.UnitAccountOpeningInformation
;
import
net.cdkj.gjj.adapter.utils.HttpUtil
;
import
net.cdkj.gjj.adapter.utils.InternalUtils
;
import
oracle.jdbc.OracleTypes
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -17,14 +16,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.sql.CallableStatement
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
...
...
@@ -72,69 +66,9 @@ public class ProvidentFundServicesController {
jsonObject
.
put
(
"app_id"
,
"eb453ca78b354f2c9163a703530f5186"
);
jsonObject
.
put
(
"app_secret"
,
"9a31b84878654a72a999e38ef55aa186"
);
String
str
=
jsonObject
.
toString
();
StringBuffer
sb
=
new
StringBuffer
();
HttpURLConnection
conn
=
null
;
OutputStream
out
=
null
;
try
{
// 创建url 资源
URL
url
=
new
URL
(
frontEndProcessorServer
+
"/FrontEndProcessor/FrontEndProcessor/ProvidentFundServices"
);
//(测试环境地址)调用前置机将业务机封装的业务json数据发给前置机,让前置机去请求第三方的公积金系统服务接口
// URL url = new URL("http://192.168.101.34:8080/FrontEndProcessor/FrontEndProcessor/ProvidentFundServices");//(本地测试地址)调用前置机将业务机封装的业务json数据发给前置机,让前置机去请求第三方的公积金系统服务接口
// 创建http 连接
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
// 设置允许输出
conn
.
setDoOutput
(
true
);
// 设置允许输入
conn
.
setDoInput
(
true
);
// 设置不使用缓存
conn
.
setUseCaches
(
false
);
// 设置传递方式
conn
.
setRequestMethod
(
"POST"
);
// 设置维持长连接
conn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
// 设置文件类型:
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
// 设置文件字符集:
conn
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
// 转换为字节数组
byte
[]
data
=
(
str
).
getBytes
(
"UTF-8"
);
// 设置文件长度
conn
.
setRequestProperty
(
"Content-Length"
,
String
.
valueOf
(
data
.
length
));
// 开始连接请求
conn
.
connect
();
// 创建写入流,写入请求的字符串
out
=
new
DataOutputStream
(
conn
.
getOutputStream
());
out
.
write
(
data
);
// 请求返回的状态
if
(
HttpURLConnection
.
HTTP_OK
==
conn
.
getResponseCode
())
{
// 请求返回的数据
InputStream
is
=
conn
.
getInputStream
();
String
readLine
=
new
String
();
BufferedReader
responseReader
=
new
BufferedReader
(
new
InputStreamReader
(
is
,
"UTF-8"
));
while
((
readLine
=
responseReader
.
readLine
())
!=
null
)
{
sb
.
append
(
readLine
);
}
responseReader
.
close
();
// System.out.println("前置机返回第三方解压之后的公积金服务数据:"+sb.toString());
return
sb
.
toString
();
}
else
{
System
.
out
.
println
(
"请求失败!!!"
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
out
!=
null
)
{
try
{
out
.
flush
();
out
.
close
();
}
catch
(
IOException
e
)
{
}
}
if
(
conn
!=
null
)
{
conn
.
disconnect
();
}
}
return
null
;
String
spec
=
frontEndProcessorServer
+
"/FrontEndProcessor/FrontEndProcessor/ProvidentFundServices"
;
// 发起 post 请求
return
HttpUtil
.
sendPost
(
spec
,
str
);
}
/**
...
...
@@ -145,29 +79,7 @@ public class ProvidentFundServicesController {
@ResponseBody
@PostMapping
(
"currentime"
)
public
static
String
currenttime
(
int
type
)
{
String
time
=
null
;
if
(
type
==
0
)
{
// 获取当天零点零分零秒的时间戳
Calendar
curentDay
=
Calendar
.
getInstance
();
curentDay
.
setTime
(
new
Date
());
curentDay
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
curentDay
.
set
(
Calendar
.
MINUTE
,
0
);
curentDay
.
set
(
Calendar
.
SECOND
,
0
);
SimpleDateFormat
df2
=
new
SimpleDateFormat
(
"yyyyMMdd HH:mm:ss"
);
time
=
df2
.
format
(
curentDay
.
getTime
().
getTime
());
System
.
out
.
println
(
time
);
}
else
if
(
type
==
24
)
{
// 获取当天24点零分零秒的时间戳,即第二天零点时间
Calendar
curentDay
=
Calendar
.
getInstance
();
curentDay
.
setTime
(
new
Date
());
curentDay
.
set
(
Calendar
.
HOUR_OF_DAY
,
24
);
curentDay
.
set
(
Calendar
.
MINUTE
,
0
);
curentDay
.
set
(
Calendar
.
SECOND
,
0
);
SimpleDateFormat
df2
=
new
SimpleDateFormat
(
"yyyyMMdd HH:mm:ss"
);
time
=
df2
.
format
(
curentDay
.
getTime
().
getTime
());
System
.
out
.
println
(
time
);
}
return
time
;
return
InternalUtils
.
currentTime
(
type
);
}
/**
...
...
@@ -404,57 +316,16 @@ public class ProvidentFundServicesController {
jsonObject
.
put
(
"departCode"
,
"10"
);
jsonObject
.
put
(
"nodeList"
,
list
);
String
str
=
jsonObject
.
toString
();
StringBuffer
sb
=
new
StringBuffer
();
HttpURLConnection
conn
=
null
;
OutputStream
out
=
null
;
try
{
// 创建url 资源
URL
url
=
new
URL
(
frontEndProcessorServer
+
"/FrontEndProcessor/FrontEndProcessor/BusinessProcessing"
);
//(测试环境)调用前置机将业务机封装的业务json数据发给前置机,让前置机去请求第三方的公积金系统服务接口
// URL url = new URL("http://192.168.101.34:8080/FrontEndProcessor/FrontEndProcessor/BusinessProcessing");//(本地环境)调用前置机将业务机封装的业务json数据发给前置机,让前置机去请求第三方的公积金系统服务接口
// 创建http 连接
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
// 设置允许输出
conn
.
setDoOutput
(
true
);
// 设置允许输入
conn
.
setDoInput
(
true
);
// 设置不使用缓存
conn
.
setUseCaches
(
false
);
// 设置传递方式
conn
.
setRequestMethod
(
"POST"
);
// 设置维持长连接
conn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
// 设置文件类型:
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
// 设置文件字符集:
conn
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
// 转换为字节数组
byte
[]
data
=
(
str
).
getBytes
(
"UTF-8"
);
// 设置文件长度
conn
.
setRequestProperty
(
"Content-Length"
,
String
.
valueOf
(
data
.
length
));
// 开始连接请求
conn
.
connect
();
// 创建写入流,写入请求的字符串
out
=
new
DataOutputStream
(
conn
.
getOutputStream
());
out
.
write
(
data
);
// 请求返回的状态
if
(
HttpURLConnection
.
HTTP_OK
==
conn
.
getResponseCode
())
{
// 请求返回的数据
InputStream
is
=
conn
.
getInputStream
();
String
readLine
=
new
String
();
BufferedReader
responseReader
=
new
BufferedReader
(
new
InputStreamReader
(
is
,
"UTF-8"
));
while
((
readLine
=
responseReader
.
readLine
())
!=
null
)
{
sb
.
append
(
readLine
);
}
responseReader
.
close
();
System
.
out
.
println
(
"前置机返回第三方解压之后的进度推送结果"
+
sb
.
toString
());
String
spec
=
frontEndProcessorServer
+
"/FrontEndProcessor/FrontEndProcessor/BusinessProcessing"
;
// 发起 post 请求
String
result
=
HttpUtil
.
sendPost
(
spec
,
str
);
if
(
result
!=
null
)
{
String
uscc
=
""
;
if
(!
list
.
isEmpty
())
{
uscc
=
list
.
get
(
0
).
getUscc
();
}
else
{
}
System
.
out
.
println
(
uscc
);
JSONObject
jsonObj
=
JSONObject
.
parseObject
(
sb
.
toString
()
);
JSONObject
jsonObj
=
JSONObject
.
parseObject
(
result
);
String
success
=
jsonObj
.
getString
(
"success"
);
Integer
value
=
0
;
if
(
"true"
.
equals
(
success
))
{
...
...
@@ -468,27 +339,8 @@ public class ProvidentFundServicesController {
e
.
printStackTrace
();
}
System
.
out
.
println
(
value
);
return
sb
.
toString
();
}
else
{
System
.
out
.
println
(
"请求失败!!!"
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
out
!=
null
)
{
try
{
out
.
flush
();
out
.
close
();
}
catch
(
IOException
e
)
{
}
}
if
(
conn
!=
null
)
{
conn
.
disconnect
();
}
}
return
null
;
return
result
;
}
/**
...
...
@@ -572,7 +424,7 @@ public class ProvidentFundServicesController {
// 给参数赋值
pstm
.
setString
(
1
,
uscc
);
pstm
.
setInt
(
2
,
value
);
//
pstm.registerOutParameter(1, OracleTypes.CURSOR);
//
pstm.registerOutParameter(1, OracleTypes.CURSOR);
// 执行数据库查询操作
pstm
.
execute
();
// 输出结果[第二个参数]
...
...
src/main/java/net/cdkj/gjj/adapter/utils/HttpUtil.java
View file @
ff36fb7b
...
...
@@ -31,7 +31,7 @@ public class HttpUtil {
/**
* 发起 post 请求
,并对出参进行解压缩
* 发起 post 请求
*/
public
static
String
sendPost
(
String
httpUrl
,
String
content
)
{
StringBuffer
sb
=
new
StringBuffer
();
...
...
@@ -54,8 +54,6 @@ public class HttpUtil {
conn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
// 设置文件类型:
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
conn
.
setRequestProperty
(
"accept"
,
"*/*"
);
conn
.
setRequestProperty
(
"Accept-Encoding"
,
"gzip, deflate, br"
);
// 设置文件字符集:
conn
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
// 转换为字节数组
...
...
@@ -69,16 +67,15 @@ public class HttpUtil {
out
.
write
(
data
);
// 请求返回的状态
if
(
HttpURLConnection
.
HTTP_OK
==
conn
.
getResponseCode
())
{
// 请求返回的数据
,解压缩
// 请求返回的数据
InputStream
is
=
conn
.
getInputStream
();
GZIPInputStream
gzis
=
new
GZIPInputStream
(
is
);
InputStreamReader
reader
=
new
InputStreamReader
(
gzis
,
"UTF-8"
);
BufferedReader
br
=
new
BufferedReader
(
reader
);
String
temp
;
while
((
temp
=
br
.
readLine
())
!=
null
)
{
sb
.
append
(
temp
);
String
readLine
=
new
String
();
BufferedReader
responseReader
=
new
BufferedReader
(
new
InputStreamReader
(
is
,
"UTF-8"
));
while
((
readLine
=
responseReader
.
readLine
())
!=
null
)
{
sb
.
append
(
readLine
);
}
System
.
out
.
println
(
"第三方返回的zip解压缩之后的报文:"
+
sb
);
responseReader
.
close
();
System
.
out
.
println
(
"前置机返回第三方解压之后数据:"
+
sb
);
return
sb
.
toString
();
}
else
{
System
.
out
.
println
(
"请求失败!!!"
);
...
...
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