Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 2790543e
由
sunke
编写于
2023-01-17 10:22:20 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
兼容SMD box 接口
1 个父辈
53d8efd0
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
93 行增加
和
2 行删除
src/main/java/com/neotel/smfcore/common/utils/HttpHelper.java
src/main/java/com/neotel/smfcore/custom/smdbox/SmdboxApi.java
src/main/java/com/neotel/smfcore/common/utils/HttpHelper.java
查看文件 @
2790543
...
@@ -48,6 +48,97 @@ public class HttpHelper {
...
@@ -48,6 +48,97 @@ public class HttpHelper {
// 读数据超时时间
// 读数据超时时间
private
static
final
int
READ_DATA_TIMEOUT
=
10000
;
private
static
final
int
READ_DATA_TIMEOUT
=
10000
;
/**
* 兼容smdBox接口
* @param url
* @param paramMap
* @param user
* @param pwd
* @return
* @throws ApiException
*/
@Deprecated
public
static
String
postParamWithAuth
(
String
url
,
Map
<
String
,
Object
>
paramMap
,
String
user
,
String
pwd
)
throws
ApiException
{
PrintWriter
out
=
null
;
BufferedReader
in
=
null
;
String
result
=
""
;
try
{
URL
realUrl
=
new
URL
(
url
);
// 打开和URL之间的连接
URLConnection
conn
=
realUrl
.
openConnection
();
// 设置通用的请求属性
conn
.
setRequestProperty
(
"accept"
,
"*/*"
);
conn
.
setRequestProperty
(
"connection"
,
"Keep-Alive"
);
conn
.
setRequestProperty
(
"user-agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"
);
//设置用户名和密码
if
(
Strings
.
isNotBlank
(
user
)){
String
auth
=
user
+
":"
+
pwd
;
//对其进行加密
byte
[]
rel
=
Base64
.
getEncoder
().
encode
(
auth
.
getBytes
());
String
res
=
new
String
(
rel
);
//设置认证属性
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
res
);
}
// conn.setRequestProperty("Charset", "UTF-8");
// 发送POST请求必须设置如下两行
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
// 获取URLConnection对象对应的输出流
out
=
new
PrintWriter
(
conn
.
getOutputStream
());
// 设置请求属性
String
param
=
""
;
if
(
paramMap
!=
null
&&
paramMap
.
size
()
>
0
)
{
Iterator
<
String
>
ite
=
paramMap
.
keySet
().
iterator
();
while
(
ite
.
hasNext
())
{
String
key
=
ite
.
next
();
// key
Object
valueObj
=
paramMap
.
get
(
key
);
String
value
=
""
;
if
(
valueObj
!=
null
){
if
(
valueObj
instanceof
Date
){
DateUtil
.
toDateString
((
Date
)
valueObj
,
"yyyyMMdd"
);
}
else
{
value
=
valueObj
.
toString
();
}
}
param
+=
key
+
"="
+
value
+
"&"
;
}
param
=
param
.
substring
(
0
,
param
.
length
()
-
1
);
}
// 发送请求参数
out
.
print
(
param
);
// flush输出流的缓冲
out
.
flush
();
// 定义BufferedReader输入流来读取URL的响应
in
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
()));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
+=
line
;
}
}
catch
(
Exception
e
)
{
throw
new
ApiException
(
"Request ["
+
url
+
"] failed:"
+
e
.
getMessage
());
}
// 使用finally块来关闭输出流、输入流
finally
{
try
{
if
(
out
!=
null
)
{
out
.
close
();
}
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
IOException
ex
)
{
throw
new
ApiException
(
"Request ["
+
url
+
"] close instream failed:"
+
ex
.
getMessage
());
}
}
return
result
;
}
public
static
String
postJson
(
String
url
,
Map
<
String
,
Object
>
params
)
throws
ApiException
{
public
static
String
postJson
(
String
url
,
Map
<
String
,
Object
>
params
)
throws
ApiException
{
// 设置请求参数
// 设置请求参数
if
(
params
==
null
||
params
.
isEmpty
())
{
if
(
params
==
null
||
params
.
isEmpty
())
{
...
...
src/main/java/com/neotel/smfcore/custom/smdbox/SmdboxApi.java
查看文件 @
2790543
...
@@ -63,7 +63,7 @@ public class SmdboxApi extends BaseSmfApiListener {
...
@@ -63,7 +63,7 @@ public class SmdboxApi extends BaseSmfApiListener {
params
.
put
(
"SP"
,
barcode
.
getProvider
());
params
.
put
(
"SP"
,
barcode
.
getProvider
());
params
.
put
(
"BATCH"
,
barcode
.
getAmount
());
params
.
put
(
"BATCH"
,
barcode
.
getAmount
());
}
}
String
result
=
HttpHelper
.
postParam
(
url
,
params
);
String
result
=
HttpHelper
.
postParam
WithAuth
(
url
,
params
,
null
,
null
);
log
.
info
(
"收到MES ["
+
url
+
"]的关于["
+
reelBarcode
+
"]入库通知的反馈信息:"
+
result
);
log
.
info
(
"收到MES ["
+
url
+
"]的关于["
+
reelBarcode
+
"]入库通知的反馈信息:"
+
result
);
return
true
;
return
true
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -82,7 +82,7 @@ public class SmdboxApi extends BaseSmfApiListener {
...
@@ -82,7 +82,7 @@ public class SmdboxApi extends BaseSmfApiListener {
log
.
info
(
"向 MES 通知【"
+
reelBarcode
+
"】的出库信息"
);
log
.
info
(
"向 MES 通知【"
+
reelBarcode
+
"】的出库信息"
);
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
params
.
put
(
"ReelID"
,
reelBarcode
);
params
.
put
(
"ReelID"
,
reelBarcode
);
String
result
=
HttpHelper
.
postParam
(
url
,
params
);
String
result
=
HttpHelper
.
postParam
WithAuth
(
url
,
params
,
null
,
null
);
log
.
info
(
"收到MES ["
+
url
+
"]的关于["
+
reelBarcode
+
"]出库通知的反馈信息:"
+
result
);
log
.
info
(
"收到MES ["
+
url
+
"]的关于["
+
reelBarcode
+
"]出库通知的反馈信息:"
+
result
);
return
true
;
return
true
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论