Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
semiconductor-server
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
inroi
semiconductor-server
Commits
c574d9c0
提交
c574d9c0
authored
10月 27, 2022
作者:
inroi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
微调
上级
992b5782
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
109 行增加
和
25 行删除
+109
-25
KingDeeApiClient.java
...system/src/main/java/com/system/api/KingDeeApiClient.java
+3
-2
FacePlusThrowErrorHandler.java
...in/java/com/system/handler/FacePlusThrowErrorHandler.java
+23
-0
HttpUtil.java
...uctor-system/src/main/java/com/system/utils/HttpUtil.java
+83
-23
没有找到文件。
semiconductor-system/src/main/java/com/system/api/KingDeeApiClient.java
浏览文件 @
c574d9c0
...
...
@@ -4,6 +4,7 @@ import com.core.config.ThreadLocalConfig;
import
com.core.utils.StringUtil
;
import
com.system.constans.KingDeeConstants
;
import
com.system.serializer.SerializerProxy
;
import
com.system.utils.HttpUtil
;
import
com.system.utils.JsonUtil
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -51,7 +52,7 @@ public class KingDeeApiClient {
System
.
out
.
println
(
"------------>"
+
url
);
long
start
=
System
.
currentTimeMillis
();
ResponseEntity
<
String
>
responseEntity
=
KingDeeHttpApi
.
httpPost
(
url
,
header
,
JsonUtil
.
toString
(
request
));
ResponseEntity
<
String
>
responseEntity
=
HttpUtil
.
httpPost
(
url
,
header
,
JsonUtil
.
toString
(
request
));
long
costTime
=
System
.
currentTimeMillis
()
-
start
;
Map
<
String
,
Object
>
map
=
ThreadLocalConfig
.
get
();
...
...
@@ -67,7 +68,7 @@ public class KingDeeApiClient {
request
.
put
(
"parameters"
,
new
Object
[]{
dbId
,
userName
,
password
,
lcid
});
String
url
=
serverUrl
+
"Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser"
+
HTTP_SUFFIX
;
ResponseEntity
<
String
>
responseEntity
=
KingDeeHttpApi
.
httpPost
(
url
,
JsonUtil
.
toString
(
request
));
ResponseEntity
<
String
>
responseEntity
=
HttpUtil
.
httpPost
(
url
,
JsonUtil
.
toString
(
request
));
System
.
out
.
println
(
responseEntity
.
getBody
());
if
(
responseEntity
.
getStatusCode
()
==
HttpStatus
.
OK
)
{
...
...
semiconductor-system/src/main/java/com/system/handler/FacePlusThrowErrorHandler.java
0 → 100644
浏览文件 @
c574d9c0
package
com
.
system
.
handler
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.web.client.ResponseErrorHandler
;
import
javax.annotation.Nonnull
;
/**
* @author Inori
*/
public
class
FacePlusThrowErrorHandler
implements
ResponseErrorHandler
{
@Override
public
boolean
hasError
(
@Nonnull
ClientHttpResponse
response
)
{
return
false
;
}
@Override
public
void
handleError
(
@Nonnull
ClientHttpResponse
response
)
{
}
}
semiconductor-system/src/main/java/com/system/
api/KingDeeHttpApi
.java
→
semiconductor-system/src/main/java/com/system/
utils/HttpUtil
.java
浏览文件 @
c574d9c0
package
com
.
system
.
api
;
package
com
.
system
.
utils
;
import
com.system.handler.FacePlusThrowErrorHandler
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
...
...
@@ -14,7 +17,9 @@ import java.util.Set;
/**
* @author Inori
*/
public
class
KingDeeHttpApi
{
public
class
HttpUtil
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
HttpUtil
.
class
);
/**
* 连接超时时间
...
...
@@ -38,27 +43,7 @@ public class KingDeeHttpApi {
requestFactory
.
setConnectTimeout
(
CONN_TIMEOUT
);
requestFactory
.
setReadTimeout
(
READ_TIMEOUT
);
restTemplate
=
new
RestTemplate
(
requestFactory
);
}
/**
* 发送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
);
restTemplate
.
setErrorHandler
(
new
FacePlusThrowErrorHandler
());
}
/**
...
...
@@ -86,6 +71,81 @@ public class KingDeeHttpApi {
}
/**
* 发送Get请求
*/
public
static
ResponseEntity
<
String
>
httpGet
(
String
url
)
{
//初始化header公共参数
HttpHeaders
httpHeaders
=
initHeader
();
//发送请求
HttpEntity
<
String
>
httpEntity
=
new
HttpEntity
<>(
null
,
httpHeaders
);
return
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
httpEntity
,
String
.
class
);
}
/**
* 发送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
);
log
.
info
(
"【Get请求】Url: {}"
,
url
);
return
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
httpEntity
,
String
.
class
);
}
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
);
//发送请求
log
.
info
(
"【Get请求】Url: {}"
,
url
);
return
httpGet
(
url
,
headers
);
}
/**
* 发送Post请求
*/
public
static
ResponseEntity
<
String
>
httpPost
(
String
url
,
String
json
)
{
//初始化header公共参数
HttpHeaders
httpHeaders
=
initHeader
();
//发送请求
log
.
info
(
"【Post请求】Url: {}"
,
url
);
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
);
//发送请求
log
.
info
(
"【Post请求】Url: {}"
,
url
);
return
toPost
(
url
,
httpHeaders
,
json
);
}
/**
* 发送请求
*/
private
static
ResponseEntity
<
String
>
toPost
(
String
url
,
HttpHeaders
httpHeaders
,
String
json
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论