Commit 2790543e sunke

兼容SMD box 接口

1 个父辈 53d8efd0
...@@ -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()) {
......
...@@ -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.postParamWithAuth(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.postParamWithAuth(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!