Commit c6d457b82666dc5bac722ac648d237bb6b2ad22b
1 parent
6cf6747a
DataOutputStream改为OutputStreamWriter
Showing
3 changed files
with
23 additions
and
9 deletions
src/main/java/com/huaheng/api/mes/domain/LoginMES.java
@@ -11,6 +11,6 @@ import org.springframework.stereotype.Component; | @@ -11,6 +11,6 @@ import org.springframework.stereotype.Component; | ||
11 | @Component | 11 | @Component |
12 | //登录参数 | 12 | //登录参数 |
13 | public class LoginMES { | 13 | public class LoginMES { |
14 | - private String appkey; | 14 | + private String appKey; |
15 | private String appSecret; | 15 | private String appSecret; |
16 | } | 16 | } |
src/main/java/com/huaheng/api/mes/service/MESHelper.java
@@ -2,15 +2,15 @@ package com.huaheng.api.mes.service; | @@ -2,15 +2,15 @@ package com.huaheng.api.mes.service; | ||
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | import com.huaheng.api.mes.domain.MESUri; | 4 | import com.huaheng.api.mes.domain.MESUri; |
5 | +import com.huaheng.common.utils.http.HttpUtils; | ||
5 | import com.huaheng.framework.aspectj.ApiLogAspect; | 6 | import com.huaheng.framework.aspectj.ApiLogAspect; |
7 | +import com.huaheng.framework.web.domain.AjaxResult; | ||
6 | import com.huaheng.pc.monitor.apilog.domain.ApiLog; | 8 | import com.huaheng.pc.monitor.apilog.domain.ApiLog; |
7 | import com.huaheng.pc.system.config.service.IConfigService; | 9 | import com.huaheng.pc.system.config.service.IConfigService; |
8 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
9 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
10 | 12 | ||
11 | -import java.io.BufferedReader; | ||
12 | -import java.io.DataOutputStream; | ||
13 | -import java.io.InputStreamReader; | 13 | +import java.io.*; |
14 | import java.net.HttpURLConnection; | 14 | import java.net.HttpURLConnection; |
15 | import java.net.URL; | 15 | import java.net.URL; |
16 | 16 | ||
@@ -27,7 +27,6 @@ public class MESHelper { | @@ -27,7 +27,6 @@ public class MESHelper { | ||
27 | HttpURLConnection connection = (HttpURLConnection) postUrl | 27 | HttpURLConnection connection = (HttpURLConnection) postUrl |
28 | .openConnection(); | 28 | .openConnection(); |
29 | String MESCookie = configService.selectConfigByKey("MESCookie"); | 29 | String MESCookie = configService.selectConfigByKey("MESCookie"); |
30 | - connection.setRequestProperty("Authorization", MESCookie); | ||
31 | connection.setDoOutput(true); | 30 | connection.setDoOutput(true); |
32 | connection.setDoInput(true); | 31 | connection.setDoInput(true); |
33 | connection.setUseCaches(false); | 32 | connection.setUseCaches(false); |
@@ -35,9 +34,13 @@ public class MESHelper { | @@ -35,9 +34,13 @@ public class MESHelper { | ||
35 | connection.setRequestMethod("POST");// 设置请求方式 | 34 | connection.setRequestMethod("POST");// 设置请求方式 |
36 | connection.setRequestProperty("Accept","application/json");// 设置接收数据的格式 | 35 | connection.setRequestProperty("Accept","application/json");// 设置接收数据的格式 |
37 | connection.setRequestProperty("Content-Type","application/json");// 设置发送数据的格式 | 36 | connection.setRequestProperty("Content-Type","application/json");// 设置发送数据的格式 |
37 | + connection.setRequestProperty("Authorization", MESCookie); | ||
38 | apiLog = ApiLogAspect.initApiLog(connection, paras, "MES"); | 38 | apiLog = ApiLogAspect.initApiLog(connection, paras, "MES"); |
39 | - DataOutputStream out = new DataOutputStream(connection.getOutputStream()); | ||
40 | - out.writeBytes(paras); | 39 | +// DataOutputStream out = new DataOutputStream(connection.getOutputStream()); |
40 | + // out.writeBytes(paras); | ||
41 | + OutputStreamWriter out = null; | ||
42 | + out = new OutputStreamWriter(connection.getOutputStream(),"UTF-8");// utf-8编码 | ||
43 | + out.append(paras); | ||
41 | out.flush(); | 44 | out.flush(); |
42 | out.close(); | 45 | out.close(); |
43 | return connection; | 46 | return connection; |
@@ -45,7 +48,17 @@ public class MESHelper { | @@ -45,7 +48,17 @@ public class MESHelper { | ||
45 | 48 | ||
46 | public void insertAgvPort(String param) throws Exception { | 49 | public void insertAgvPort(String param) throws Exception { |
47 | HttpURLConnection connection = initUrlConn(MESUri.INSERT_AGV_PORT.getApiUri(), param); | 50 | HttpURLConnection connection = initUrlConn(MESUri.INSERT_AGV_PORT.getApiUri(), param); |
51 | + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
52 | + String line; | ||
53 | + String sResult=null; | ||
54 | + while ((line = reader.readLine()) != null) { | ||
55 | + sResult = new String(line.getBytes(), "UTF-8"); | ||
56 | + System.out.println(sResult); | ||
57 | + } | ||
58 | + reader.close(); | ||
48 | connection.disconnect(); | 59 | connection.disconnect(); |
60 | + ApiLogAspect.finishApiLog(apiLog,connection, AjaxResult.success(sResult).toString()); | ||
61 | +// HttpUtils.bodypost(MESUri.INSERT_AGV_PORT.getApiUri(),param,"CS0001"); | ||
49 | } | 62 | } |
50 | 63 | ||
51 | public JSONObject returnOrderCode(String param) throws Exception { | 64 | public JSONObject returnOrderCode(String param) throws Exception { |
src/main/java/com/huaheng/pc/monitor/job/task/RyTask.java
@@ -405,11 +405,12 @@ public class RyTask extends BaseController { | @@ -405,11 +405,12 @@ public class RyTask extends BaseController { | ||
405 | 405 | ||
406 | public void loginMES(String params) | 406 | public void loginMES(String params) |
407 | throws Exception { | 407 | throws Exception { |
408 | - System.out.println("params:" + params); | ||
409 | LoginMES loginMES = JSON.parseObject(params, LoginMES.class); | 408 | LoginMES loginMES = JSON.parseObject(params, LoginMES.class); |
409 | + HashMap map=new HashMap(); | ||
410 | + map.put("body",loginMES); | ||
410 | String sUrl = MESUri.LOGIN.getApiUri(); | 411 | String sUrl = MESUri.LOGIN.getApiUri(); |
411 | Gson gson = new Gson(); | 412 | Gson gson = new Gson(); |
412 | - String s = gson.toJson(loginMES); | 413 | + String s = gson.toJson(map); |
413 | HttpURLConnection connection = mesHelper.initUrlConn(sUrl, s); | 414 | HttpURLConnection connection = mesHelper.initUrlConn(sUrl, s); |
414 | // 获取Cookie | 415 | // 获取Cookie |
415 | BufferedReader reader = new BufferedReader(new InputStreamReader( | 416 | BufferedReader reader = new BufferedReader(new InputStreamReader( |