HttpServer.cs
8.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace DeviceLibrary
{
public class HttpServer
{
public HttpServer()
{
}
private static string Addr_ddjPickUpGoodsNotice = "/rest/api/v2/803/service/store/xl/ddjPickUpGoodsNotice";//堆垛机取货完成, 通知极创
private static string Addr_inStorageFeedback = "/rest/api/v2/803/service/store/xl/inStorageFeedback";//料箱放入库位完成, 通知极创
private static string Addr_outIsReady = "/rest/api/v2/803/service/store/xl/outIsReady";//出库时查询接驳线体是否可以放料箱
private static string Addr_ddjReleaseTheGoodsNotice = "/rest/api/v2/803/service/store/xl/ddjReleaseTheGoodsNotice";//堆垛机放货完成反馈
// ## 入库:
//1 定时通信data里面添加boxCanPutIn字段表示箱子是否可放上入库线体, 值为字符串"TRUE"时表示可放, 其他为不可放
//2 堆垛机取货完成, 通知极创
//http://localhost/rest/api/v2/803/service/store/xl/ddjPickUpGoodsNotice
//请求参数:
//{
//"posName": "库位号"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
//3 料箱放入库位完成, 通知极创
//http://localhost/rest/api/v2/803/service/store/xl/inStorageFeedback
//请求参数:
//{
//"posName": "库位号"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
//4 出库时查询接驳线体是否可以放料箱
// http://localhost/rest/api/v2/803/service/store/xl/outIsReady
//请求参数:
//{
//"cid": "001",
//"boxCode":"CB001"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
//5 堆垛机放货完成反馈
//http://localhost/rest/api/v2/803/service/store/xl/ddjReleaseTheGoodsNotice
//请求参数:
//{
//"boxCode":"CB001"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
private static string GetAddr(string addr, Dictionary<string, string> paramsMap = null)
{
if (paramsMap == null)
{
paramsMap = new Dictionary<string, string>();
}
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
//server = "http://192.168.1.37:8800/";
if (server.EndsWith("/"))
{
server = server.Substring(0, server.Length - 1);
}
string path = server + addr.Trim() + "?";
foreach (string paramName in paramsMap.Keys)
{
string par = System.Web.HttpUtility.UrlEncode(paramsMap[paramName], System.Text.Encoding.UTF8);
path += paramName + "=" + par + "&";
}
path = path.Substring(0, path.Length - 1);
return path;
}
private static string getData(Dictionary<string, Object> data, string key)
{
if (data.ContainsKey(key))
{
return data[key].ToString().Trim();
}
return "";
}
private static int getIntData(Dictionary<string, Object> data, string key, int defValue = -1)
{
try
{
return Int32.Parse(getData(data, key));
}
catch (Exception ex)
{
}
return -1;
}
private static string PostJson(Dictionary<string, string> paramMap, string addr, string logName, bool needLog = true)
{
DateTime startTime = DateTime.Now;
try
{
string url = GetAddr(addr);
string json = HttpHelper.PostJson(url, paramMap, Encoding.UTF8, 2000);
if (needLog)
{
LogUtil.info("http :URL:" + url + " :Response:" + json + " 耗时[" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "]");
}
else
{
LogUtil.debug("http :URL:" + url + " :Response:" + json + " 耗时[" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "]");
}
ResultData data = JsonHelper.DeserializeJsonToObject<ResultData>(json);
if (data == null)
{
return "未收到服务器反馈";
}
else if (data.code == 0)
{
return "";
}
else
{
LogUtil.error(logName + ": 结果:code=" + data.code + ",msg=" + data.msg);
return data.msg;
}
}
catch (Exception ex)
{
LogUtil.error(logName + " error : " + ex.ToString());
return ex.ToString();
}
}
/// <summary>
/// 堆垛机取货完成, 通知极创
/// </summary>
/// <param name="posName"></param>
/// <returns></returns>
public static string ddjPickUpGoodsNotice(string posName)
{
//2 堆垛机取货完成, 通知极创
//http://localhost/rest/api/v2/803/service/store/xl/ddjPickUpGoodsNotice
//请求参数:
//{
//"posName": "库位号"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("posName", posName);
return PostJson(paramMap, Addr_ddjPickUpGoodsNotice, "ddjPickUpGoodsNotice", true);
}
/// <summary>
/// 料箱放入库位完成, 通知极创
/// </summary>
/// <param name="posName"></param>
/// <returns></returns>
public static string inStorageFeedback(string posName)
{
//3 料箱放入库位完成, 通知极创
//http://localhost/rest/api/v2/803/service/store/xl/inStorageFeedback
//请求参数:
//{
//"posName": "库位号"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("posName", posName);
return PostJson(paramMap, Addr_inStorageFeedback, "inStorageFeedback", true);
}
/// <summary>
/// 出库时查询接驳线体是否可以放料箱
/// </summary>
/// <param name="cid"></param>
/// <param name="boxCode"></param>
/// <returns></returns>
public static string outIsReady(string cid, string boxCode)
{
//4 出库时查询接驳线体是否可以放料箱
// http://localhost/rest/api/v2/803/service/store/xl/outIsReady
//请求参数:
//{
//"cid": "001",
//"boxCode":"CB001"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("cid", cid);
paramMap.Add("boxCode", boxCode);
return PostJson(paramMap, Addr_outIsReady, "outIsReady", true);
}
/// <summary>
/// 堆垛机放货完成反馈
/// </summary>
/// <param name="boxCode"></param>
/// <returns></returns>
public static string ddjReleaseTheGoodsNotice(string boxCode)
{
//5 堆垛机放货完成反馈
//http://localhost/rest/api/v2/803/service/store/xl/ddjReleaseTheGoodsNotice
//请求参数:
//{
//"boxCode":"CB001"
//}
//返回结果
//{"code":0,"msg":"ok","data":""}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("boxCode", boxCode);
return PostJson(paramMap, Addr_ddjReleaseTheGoodsNotice, "ddjReleaseTheGoodsNotice", true);
}
}
public class ResultData
{
public int code { get; set; }
public string msg { get; set; }
public object data { get; set; }
}
}