Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
O
OZT-Integration
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
许俊
OZT-Integration
Commits
8cd41ec2
提交
8cd41ec2
authored
12月 25, 2023
作者:
李勤
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
excute
上级
c3f8fe24
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
265 行增加
和
0 行删除
+265
-0
KingdeeApiClient.java
...a/org/jeecg/modules/iost/ims/client/KingdeeApiClient.java
+23
-0
HttpUtil.java
.../java/org/jeecg/modules/iost/ims/kingdeeapi/HttpUtil.java
+242
-0
没有找到文件。
jeecg-boot-module-system/src/main/java/org/jeecg/modules/iost/ims/client/KingdeeApiClient.java
浏览文件 @
8cd41ec2
...
...
@@ -10,7 +10,10 @@ import lombok.extern.slf4j.Slf4j;
import
org.apache.http.client.CookieStore
;
import
org.jeecg.common.util.ThreadLocalConfig
;
import
org.jeecg.modules.iost.ims.Util.JsonUtil
;
import
org.jeecg.modules.iost.ims.kingdeeapi.HttpUtil
;
import
org.jeecg.modules.iost.ims.service.impl.ImsNondefectiveFlittingServiceImpl
;
import
org.springframework.http.ResponseEntity
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -48,9 +51,29 @@ public class KingdeeApiClient {
map2
.
put
(
"Costime"
,
Costime
);
ThreadLocalConfig
.
set
(
map2
);
}
execute
(
servicename
,
parameters
);
return
send
;
}
public
void
execute
(
String
serviceName
,
Object
[]
parameters
)
throws
Exception
{
Map
<
String
,
Object
>
header
=
new
HashMap
<>(
1
);
header
.
put
(
"cookie"
,
this
.
_cookieStore
);
Map
<
String
,
Object
>
request
=
new
HashMap
<>(
1
);
request
.
put
(
"parameters"
,
parameters
);
String
url
=
this
.
_serverUrl
+
serviceName
+
".common.kdsvc"
;
long
start
=
System
.
currentTimeMillis
();
String
requestStr
=
JsonUtil
.
toString
(
request
);
ResponseEntity
<
String
>
responseEntity
=
HttpUtil
.
httpPost
(
url
,
header
,
requestStr
);
long
costTime
=
System
.
currentTimeMillis
()
-
start
;
log
.
info
(
"Costime2_"
+
String
.
valueOf
(
costTime
));
}
public
<
T
>
ApiRequest
<
T
>
executeAsync
(
String
servicename
,
Object
[]
parameters
,
Class
<
T
>
returnType
,
IAsyncActionCallBack
<
T
>
callback
)
throws
Exception
{
ApiRequest
<
T
>
request
=
this
.
createRequest
(
servicename
,
parameters
,
returnType
);
ApiHttpClient
<
T
>
httpClient
=
new
ApiHttpClient
(
callback
);
...
...
jeecg-boot-module-system/src/main/java/org/jeecg/modules/iost/ims/kingdeeapi/HttpUtil.java
0 → 100644
浏览文件 @
8cd41ec2
package
org
.
jeecg
.
modules
.
iost
.
ims
.
kingdeeapi
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.client.SimpleClientHttpRequestFactory
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.Map
;
import
java.util.Set
;
public
class
HttpUtil
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
HttpUtil
.
class
);
/**
* 连接超时时间
*/
private
static
final
int
CONN_TIMEOUT
=
12000
;
/**
* 请求超时时间
*/
private
static
final
int
READ_TIMEOUT
=
12000
;
/**
* 请求工具
*/
private
static
RestTemplate
restTemplate
;
static
{
//设置超时时间
SimpleClientHttpRequestFactory
requestFactory
=
new
SimpleClientHttpRequestFactory
();
requestFactory
.
setConnectTimeout
(
CONN_TIMEOUT
);
requestFactory
.
setReadTimeout
(
READ_TIMEOUT
);
restTemplate
=
new
RestTemplate
(
requestFactory
);
}
/**
* 设置header公共参数
*/
private
static
HttpHeaders
initHeader
()
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"Accept"
,
"application/json"
);
headers
.
add
(
"Accpet-Encoding"
,
"gzip"
);
headers
.
add
(
"Content-Encoding"
,
"UTF-8"
);
headers
.
add
(
"Content-Type"
,
"application/json; charset=UTF-8"
);
return
headers
;
}
/**
* * 判断一个对象是否为空
*
* @param object Object
* @return true:为空 false:非空
*/
public
static
boolean
isNull
(
Object
object
)
{
return
object
==
null
;
}
public
static
boolean
isNotNull
(
Object
object
)
{
return
!
isNull
(
object
);
}
/**
* 设置header参数
*/
private
static
void
setHeaderParam
(
HttpHeaders
httpHeaders
,
Map
<
String
,
Object
>
headers
)
{
if
(!
CollectionUtils
.
isEmpty
(
headers
))
{
Set
<
String
>
keys
=
headers
.
keySet
();
for
(
String
key
:
keys
)
{
if
(
isNotNull
(
headers
.
get
(
key
)))
{
httpHeaders
.
add
(
key
,
headers
.
get
(
key
).
toString
());
}
}
}
}
/**
* 发送Get请求
*/
public
static
ResponseEntity
<
String
>
httpGet
(
String
url
)
{
//初始化header公共参数
HttpHeaders
httpHeaders
=
initHeader
();
//发送请求
HttpEntity
<
String
>
httpEntity
=
new
HttpEntity
<>(
null
,
httpHeaders
);
ResponseEntity
<
String
>
result
=
null
;
try
{
result
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
}
catch
(
Exception
ex
)
{
try
{
result
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
}
catch
(
Exception
e
)
{
result
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
}
}
return
result
;
}
/**
* 发送Get请求
*/
public
static
ResponseEntity
<
String
>
httpGet
(
String
url
,
Map
<
String
,
Object
>
param
)
{
//初始化header公共参数
HttpHeaders
httpHeaders
=
initHeader
();
//组装查询参数
url
=
setParam
(
url
,
param
);
//发送请求
HttpEntity
<
String
>
httpEntity
=
new
HttpEntity
<>(
null
,
httpHeaders
);
ResponseEntity
<
String
>
result
=
null
;
try
{
result
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
}
catch
(
Exception
ex
)
{
try
{
result
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
}
catch
(
Exception
e
)
{
result
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
}
}
return
result
;
}
private
static
String
setParam
(
String
url
,
Map
<
String
,
Object
>
param
)
{
Set
<
String
>
keys
=
param
.
keySet
();
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
"?"
);
for
(
String
key
:
keys
)
{
builder
.
append
(
key
).
append
(
"="
).
append
(
param
.
get
(
key
)).
append
(
"&"
);
}
builder
.
deleteCharAt
(
builder
.
lastIndexOf
(
"&"
));
url
=
url
+
builder
.
toString
();
return
url
;
}
/**
* 发送Get请求
*/
public
static
ResponseEntity
<
String
>
httpGet
(
String
url
,
Map
<
String
,
Object
>
headers
,
Map
<
String
,
Object
>
param
)
{
//如果查询参数为空,则调用不带参数的Get请求
if
(
CollectionUtils
.
isEmpty
(
param
))
{
return
httpGet
(
url
,
headers
);
}
//组装查询参数
url
=
setParam
(
url
,
param
);
//发送请求
return
httpGet
(
url
,
headers
);
}
/**
* 发送Post请求
*/
public
static
ResponseEntity
<
String
>
httpPost
(
String
url
,
String
json
)
{
//初始化header公共参数
HttpHeaders
httpHeaders
=
initHeader
();
//发送请求
return
toPost
(
url
,
httpHeaders
,
json
);
}
/**
* 发送Post请求
*/
public
static
ResponseEntity
<
String
>
httpPost
(
String
url
,
Map
<
String
,
Object
>
header
,
String
json
)
{
//初始化header公共参数
HttpHeaders
httpHeaders
=
initHeader
();
setHeaderParam
(
httpHeaders
,
header
);
//发送请求
return
toPost
(
url
,
httpHeaders
,
json
);
}
/**
* 发送请求
*/
private
static
ResponseEntity
<
String
>
toPost
(
String
url
,
HttpHeaders
httpHeaders
,
String
json
)
{
HttpEntity
<
String
>
httpEntity
=
new
HttpEntity
<>(
json
,
httpHeaders
);
ResponseEntity
<
String
>
result
=
null
;
try
{
result
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
}
catch
(
Exception
ex
)
{
try
{
result
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
}
catch
(
Exception
e
)
{
result
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
}
}
return
result
;
}
/**
* 文件二进制
*/
public
static
byte
[]
download
(
String
url
,
String
json
)
{
//初始化header公共参数
HttpHeaders
httpHeaders
=
initHeader
();
HttpEntity
<
String
>
httpEntity
=
new
HttpEntity
<>(
json
,
httpHeaders
);
ResponseEntity
<
byte
[]>
result
=
null
;
try
{
result
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
byte
[].
class
);
}
catch
(
Exception
ex
)
{
try
{
result
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
byte
[].
class
);
}
catch
(
Exception
e
)
{
result
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
byte
[].
class
);
}
}
return
result
.
getBody
();
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论